Flow.js 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.Work = MWF.xApplication.process.Work || {};
  3. MWF.xDesktop.requireApp("process.Work", "lp." + MWF.language, null, false);
  4. MWF.ProcessFlow_ORG_HEIGHT = 275;
  5. MWF.xApplication.process.Work.Flow = MWF.ProcessFlow = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. style: "default",
  10. processEnable: true,
  11. addTaskEnable: true,
  12. resetEnable: true,
  13. goBackEnable: true,
  14. processOptions: {},
  15. mainColorEnable: true,
  16. zIndex: 20001 //比正文编辑器痕迹窗口多1
  17. },
  18. initialize: function (container, task, options, form) {
  19. this.setOptions(options);
  20. this.path = "../x_component_process_Work/$Flow/";
  21. // this.cssPath = "../x_component_process_Work/$Flow/" + this.options.style + "/css.wcss";
  22. // this._loadCss();
  23. this.lp = MWF.xApplication.process.Work.LP;
  24. this.task = task;
  25. this.container = $(container);
  26. this.form = form;
  27. this.businessData = this.form.businessData;
  28. this.load();
  29. },
  30. load: function () {
  31. this.container.loadCss( this.path + this.options.style + "/style.css", null, function () {
  32. this.cssLoaded = true;
  33. this.checkLoadEvent();
  34. }.bind(this));
  35. this.processEnable = this.options.processEnable && this.businessData.control["allowProcessing"];
  36. this.addTaskEnable = this.options.addTaskEnable && this.businessData.control["allowAddTask"];
  37. this.resetEnable = this.options.resetEnable && this.businessData.control["allowReset"];
  38. this.goBackEnable = this.options.goBackEnable && this.businessData.control["allowGoBack"];
  39. this.navi = [];
  40. if( this.processEnable )this.navi.push({ key: "process", label: this.lp.flowActions.process });
  41. if( this.addTaskEnable )this.navi.push({ key: "addTask", label: this.lp.flowActions.addTask });
  42. if( this.resetEnable )this.navi.push({ key: "reset", label: this.lp.flowActions.reset });
  43. if( this.goBackEnable )this.navi.push({ key: "goBack", label: this.lp.flowActions.goBack });
  44. var url = this.path+this.options.style+"/main.html";
  45. this.container.loadHtml(url, {"bind": {"lp": this.lp, "navi": this.navi}, "module": this}, function(){
  46. this.changeAction( this.navi[0].key );
  47. if( this.processEnable || this.resetEnable || this.addTaskEnable ){
  48. this.loadQuickSelect();
  49. }else{
  50. this.quickSelectNode.hide();
  51. }
  52. }.bind(this));
  53. },
  54. getSize: function(){
  55. return {
  56. y: this.contentWraper.getSize().y + this.getMarginY(this.contentWraper) + this.getOffsetY(this.node) + 1,
  57. x: this.node.getSize().x + this.getMarginY(this.node)
  58. };
  59. },
  60. checkLoadEvent: function(){
  61. if( this.cssLoaded && this.firstActionLoaded){
  62. if( this.currentAction === "process" ){
  63. if( this.processor.getMaxOrgLength() > 1 ){
  64. this.node.addClass("o2flow-node-wide").removeClass("o2flow-node");
  65. }
  66. }
  67. this.fireEvent("load");
  68. }
  69. },
  70. changeAction: function( action, quickData ){
  71. debugger;
  72. if( this.currentAction ){
  73. this[ this.currentAction+"ContentNode" ].hide();
  74. this[ this.currentAction+"TitleNode" ].removeClass("o2flow-navi-item-active");
  75. if( this.options.mainColorEnable )this[ this.currentAction+"TitleNode" ].removeClass("mainColor_bg");
  76. }
  77. this[ action+"ContentNode" ].show();
  78. this[ action+"TitleNode" ].addClass("o2flow-navi-item-active");
  79. if( this.options.mainColorEnable )this[ action+"TitleNode" ].addClass("mainColor_bg");
  80. this.currentAction = action;
  81. switch (action) {
  82. case "process":
  83. this.loadProcessor( quickData );
  84. break;
  85. case "addTask":
  86. this.loadAddTask( quickData );
  87. break;
  88. case "reset":
  89. this.loadReset( quickData );
  90. break;
  91. case "goBack":
  92. this.loadGoBack();
  93. break;
  94. }
  95. },
  96. loadProcessor: function ( quickData ) {
  97. if( this.processor ){
  98. if( quickData )this.processor.setQuickData( quickData );
  99. this.resize();
  100. return;
  101. }
  102. this.processor = new MWF.ProcessFlow.Processor(
  103. this.processContentNode,
  104. this,
  105. Object.merge( this.options.processOptions, {
  106. onLoad: function () {
  107. if( this.firstActionLoaded ){
  108. this.resize();
  109. }else{
  110. this.firstActionLoaded = true;
  111. this.checkLoadEvent();
  112. }
  113. }.bind(this)
  114. })
  115. );
  116. this.processor.load( quickData );
  117. },
  118. loadReset: function( quickData ){
  119. if( this.reset ){
  120. if( quickData )this.reset.setQuickData( quickData );
  121. this.resize();
  122. return;
  123. }
  124. this.reset = new MWF.ProcessFlow.Reset(
  125. this.resetContentNode,
  126. this,
  127. Object.merge( this.options.resetOptions, {
  128. onLoad: function () {
  129. if( this.firstActionLoaded ){
  130. this.resize();
  131. }else{
  132. this.firstActionLoaded = true;
  133. this.checkLoadEvent();
  134. }
  135. }.bind(this)
  136. })
  137. );
  138. this.reset.load( quickData );
  139. },
  140. loadAddTask: function( quickData ){
  141. if( this.addTask ){
  142. if( quickData )this.addTask.setQuickData( quickData );
  143. this.resize();
  144. return;
  145. }
  146. this.addTask = new MWF.ProcessFlow.AddTask(
  147. this.addTaskContentNode,
  148. this,
  149. Object.merge( this.options.addTaskOptions, {
  150. onLoad: function () {
  151. if( this.firstActionLoaded ){
  152. this.resize();
  153. }else{
  154. this.firstActionLoaded = true;
  155. this.checkLoadEvent();
  156. }
  157. }.bind(this)
  158. })
  159. );
  160. this.addTask.load( quickData );
  161. },
  162. loadGoBack: function(){
  163. if( this.goBack ){
  164. //if( quickData )this.goBack.setQuickData( quickData );
  165. this.resize();
  166. return;
  167. }
  168. this.goBack = new MWF.ProcessFlow.GoBack(
  169. this.goBackContentNode,
  170. this,
  171. Object.merge( this.options.goBackOptions, {
  172. onLoad: function () {
  173. if( this.firstActionLoaded ){
  174. this.resize();
  175. }else{
  176. this.firstActionLoaded = true;
  177. this.checkLoadEvent();
  178. }
  179. }.bind(this)
  180. })
  181. );
  182. this.goBack.load();
  183. },
  184. loadQuickSelect: function(){
  185. if( !this.addTaskEnable && !this.resetEnable && !this.processEnable ){
  186. if(this.quickSelector)this.quickSelector.hide();
  187. return;
  188. }
  189. this.quickSelector = new MWF.ProcessFlow.widget.QuickSelect(
  190. this.form.app ? this.form.app.content : $(document.body),
  191. this.quickSelectNode,
  192. this.form.app,
  193. {},
  194. {
  195. nodeStyles: {
  196. "z-index" : this.options.zIndex + 1
  197. }
  198. }
  199. );
  200. this.quickSelector.flow = this;
  201. this.contentScrollNode.addEvent("scroll", function () {
  202. if(this.quickSelector.status === "display")this.quickSelector.hide();
  203. }.bind(this))
  204. },
  205. submit: function(){
  206. switch ( this.currentAction ) {
  207. case "process":
  208. this.processor.submit();
  209. break;
  210. case "addTask":
  211. this.addTask.submit();
  212. break;
  213. case "reset":
  214. this.reset.submit();
  215. break;
  216. case "goBack":
  217. this.goBack.submit();
  218. break;
  219. }
  220. },
  221. destroy: function () {
  222. if( this.processor )this.processor.destroy();
  223. if( this.reset )this.reset.destroy();
  224. if( this.addTask )this.addTask.destroy();
  225. if( this.goBack )this.goBack.destroy();
  226. if(this.quickSelector)this.quickSelector.destroy();
  227. this.fireEvent("cancel");
  228. },
  229. getMarginY : function(node){
  230. return (node.getStyle("margin-top").toInt() || 0 ) +
  231. (node.getStyle("margin-bottom").toInt() || 0 );
  232. },
  233. getMarginX : function(node){
  234. return (node.getStyle("margin-left").toInt() || 0 ) +
  235. (node.getStyle("margin-right").toInt() || 0 );
  236. },
  237. getOffsetY : function(node){
  238. return (node.getStyle("margin-top").toInt() || 0 ) +
  239. (node.getStyle("margin-bottom").toInt() || 0 ) +
  240. (node.getStyle("padding-top").toInt() || 0 ) +
  241. (node.getStyle("padding-bottom").toInt() || 0 )+
  242. (node.getStyle("border-top-width").toInt() || 0 ) +
  243. (node.getStyle("border-bottom-width").toInt() || 0 );
  244. },
  245. getOffsetX : function(node){
  246. return (node.getStyle("margin-left").toInt() || 0 ) +
  247. (node.getStyle("margin-right").toInt() || 0 ) +
  248. (node.getStyle("padding-left").toInt() || 0 ) +
  249. (node.getStyle("padding-right").toInt() || 0 )+
  250. (node.getStyle("border-left-width").toInt() || 0 ) +
  251. (node.getStyle("border-right-width").toInt() || 0 );
  252. },
  253. getEl: function( ev, className ){
  254. var node = ev.target;
  255. while (node && !node.hasClass(className)){ node = node.getParent();}
  256. return node;
  257. },
  258. noticeError: function( text, node, offset, position ){
  259. MWF.xDesktop.notice(
  260. "error",
  261. position || {"x": "center", "y": "center"},
  262. text,
  263. node || this.node,
  264. offset === null ? null : ( offset || {"x": 0, "y": 30} ),
  265. {"closeOnBoxClick": true, "closeOnBodyClick": true, "fixed": true, "delayClose": 6000}
  266. );
  267. },
  268. resize: function () {
  269. this.fireEvent("resize");
  270. },
  271. getRouteGroupConfig: function () {
  272. if (this.routeGroupObject) return this.routeGroupObject;
  273. this.routeGroupObject = {};
  274. this.routeGroupNameList = [];
  275. this.hasRouteGroup = false;
  276. var routeList = this.getRouteConfigList();
  277. routeList.each(function (route, i) {
  278. if (route.hiddenScriptText && this.form && this.form.Macro) { //如果隐藏路由,返回
  279. if (this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true") return;
  280. }
  281. if (route.displayNameScriptText && this.form && this.form.Macro) { //如果有显示名称公式
  282. route.displayName = this.form.Macro.exec(route.displayNameScriptText, this);
  283. } else {
  284. route.displayName = route.name;
  285. }
  286. if (route.decisionOpinion) {
  287. this.hasRouteGroup = true;
  288. route.decisionOpinion.split("#").each(function (rg) {
  289. this.routeGroupNameList.combine([rg]);
  290. var d = this.splitByStartNumber(rg);
  291. if (!this.routeGroupObject[d.name]) this.routeGroupObject[d.name] = [];
  292. this.routeGroupObject[d.name].push(route);
  293. }.bind(this))
  294. } else {
  295. var defaultName = MWF.xApplication.process.Work.LP.defaultDecisionOpinionName;
  296. this.routeGroupNameList.combine([defaultName]);
  297. if (!this.routeGroupObject[defaultName]) this.routeGroupObject[defaultName] = [];
  298. this.routeGroupObject[defaultName].push(route);
  299. }
  300. }.bind(this));
  301. return this.routeGroupObject;
  302. },
  303. getRouteConfigList: function () {
  304. if(this.routeConfigList)return this.routeConfigList;
  305. if (this.task.routeNameDisable){
  306. this.routeConfigList = [{
  307. "id": o2.uuid(),
  308. "asyncSupported": false,
  309. "soleDirect": false,
  310. "name": "继续流转",
  311. "alias": "",
  312. "selectConfigList": []
  313. }];
  314. return this.routeConfigList;
  315. }
  316. if( this.form && this.form.businessData && this.form.businessData.routeList ){
  317. this.form.businessData.routeList.sort( function(a, b){
  318. var aIdx = parseInt(a.orderNumber || "9999999");
  319. var bIdx = parseInt(b.orderNumber || "9999999");
  320. return aIdx - bIdx;
  321. }.bind(this));
  322. this.form.businessData.routeList.each( function(d){
  323. d.selectConfigList = JSON.parse(d.selectConfig || "[]");
  324. }.bind(this));
  325. this.routeConfigList = this.form.businessData.routeList;
  326. }
  327. if (!this.routeConfigList) {
  328. o2.Actions.get("x_processplatform_assemble_surface").listRoute({"valueList": this.task.routeList}, function (json) {
  329. json.data.sort(function(a, b){
  330. var aIdx = parseInt(a.orderNumber || "9999999");
  331. var bIdx = parseInt(b.orderNumber || "9999999");
  332. return aIdx - bIdx;
  333. }.bind(this));
  334. json.data.each(function (d) {
  335. d.selectConfigList = JSON.parse(d.selectConfig || "[]");
  336. }.bind(this));
  337. this.routeConfigList = json.data;
  338. }.bind(this), null, false);
  339. }
  340. return this.routeConfigList;
  341. },
  342. getRouteConfig: function (routeId) {
  343. var routeList = this.getRouteConfigList();
  344. for (var i = 0; i < routeList.length; i++) {
  345. if (routeList[i].id === routeId || routeList[i].name === routeId) {
  346. return routeList[i];
  347. }
  348. }
  349. },
  350. getOrgConfig: function (routeId) {
  351. var routeList = this.getRouteConfigList();
  352. for (var i = 0; i < routeList.length; i++) {
  353. if (routeList[i].id === routeId) {
  354. return routeList[i].selectConfigList;
  355. }
  356. }
  357. },
  358. getVisableOrgConfig: function (routeId) {
  359. var selectConfigList = this.getOrgConfig(routeId);
  360. var list = [];
  361. (selectConfigList || []).each(function (config) {
  362. if (!this.isOrgHidden(config)) {
  363. list.push(config);
  364. }
  365. }.bind(this));
  366. return list;
  367. },
  368. getSingleOrgConfig: function( routeId, orgName ){
  369. var orgList = this.getOrgConfig( routeId );
  370. for (var i = 0; i < orgList.length; i++) {
  371. if (orgList[i].name === orgName) {
  372. return orgList[i];
  373. }
  374. }
  375. },
  376. isOrgHidden: function (d) {
  377. if (d.hiddenScript && d.hiddenScript.code) { //如果隐藏路由,返回
  378. var hidden = this.form.Macro.exec(d.hiddenScript.code, this);
  379. if (hidden && hidden.toString() === "true") return true;
  380. }
  381. return false;
  382. },
  383. getMaxOrgLength: function () {
  384. var routeList = this.getRouteConfigList();
  385. var length = 0;
  386. routeList.each(function (route) {
  387. if (route.hiddenScriptText) { //如果隐藏路由,返回
  388. if (this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true") return;
  389. }
  390. length = Math.max(length, this.getVisableOrgConfig( route.id ).length);
  391. }.bind(this));
  392. return length;
  393. },
  394. splitByStartNumber: function (str) {
  395. var obj = {
  396. name: "",
  397. order: ""
  398. };
  399. for (var i = 0; i < str.length; i++) {
  400. if (parseInt(str.substr(i, 1)).toString() !== "NaN") {
  401. obj.order = obj.order + str.substr(i, 1);
  402. } else {
  403. obj.name = str.substr(i, str.length);
  404. break;
  405. }
  406. }
  407. return obj;
  408. },
  409. });
  410. MWF.ProcessFlow.Reset = new Class({
  411. Extends: MWF.widget.Common,
  412. Implements: [Options, Events],
  413. options:{
  414. data: null,
  415. style: "default"
  416. },
  417. initialize: function (container, flow, options) {
  418. this.setOptions(options);
  419. this.container = $(container);
  420. this.flow = flow;
  421. this.task = flow.task;
  422. this.form = flow.form;
  423. this.lp = flow.lp;
  424. this.businessData = this.form.businessData;
  425. },
  426. load: function( quickData ){
  427. this.quickData = quickData || {};
  428. this.container.loadHtml(this.getUrl(), {"bind": {"lp": this.lp}, "module": this}, function(){
  429. this.loadOpinion();
  430. this.loadOrg();
  431. this.afterLoad();
  432. this.fireEvent("load");
  433. }.bind(this));
  434. },
  435. setQuickData: function( data ){
  436. //if(this.keepOption)this.keepOption.setValue( data.keepTask ? "true" : null );
  437. if(this.opinion)this.opinion.setValue( data.opinion || "" );
  438. if(this.selector && this.selector.selector)this.selector.selector.setValues( data.organizations ? (data.organizations.default || []) : [] );
  439. },
  440. getUrl: function(){
  441. return this.flow.path+this.flow.options.style+"/reset.html";
  442. },
  443. show: function(){
  444. },
  445. afterLoad: function () {
  446. // this.keepOption = new MWF.ProcessFlow.widget.Radio(this.keepOptionArea, this.flow, {
  447. // optionList: [{
  448. // text: this.lp.keepTask,
  449. // value: "true"
  450. // }],
  451. // value: (this.quickData.keepTask) ? "true" : null
  452. // });
  453. // this.keepOption.load();
  454. },
  455. loadOpinion: function(){
  456. var opt = Object.clone(this.flow.options.opinionOptions);
  457. opt.isHandwriting = this.options.isHandwriting;
  458. if( this.quickData.opinion ){
  459. opt.opinion = this.quickData.opinion;
  460. delete this.quickData.opinion;
  461. }
  462. this.opinion = new MWF.ProcessFlow.widget.Opinion( this.opinionContent, this.flow, opt );
  463. this.opinion.load();
  464. },
  465. loadOrg: function(){
  466. this.getSelOptions( function (options) {
  467. options.values = this.quickData.organizations ? (this.quickData.organizations.default || []) : [];
  468. if(this.quickData.organizations)delete this.quickData.organizations.default;
  469. this.selector = new MWF.O2Selector(this.orgsArea, options);
  470. }.bind(this) );
  471. },
  472. getSelOptions: function( callback ){
  473. // o2.Actions.get("x_processplatform_assemble_surface").listTaskByWork(this.businessData.work.id, function(json){
  474. // var identityList = [];
  475. // json.data.each(function(task){
  476. // identityList.push(task.identity);
  477. // });
  478. // this._getSelOptions(identityList, callback);
  479. // }.bind(this))
  480. this._getSelOptions([], callback);
  481. },
  482. _getSelOptions: function (exclude, callback) {
  483. var options = this.getSelDefaultOptions();
  484. var range = this.businessData.activity.resetRange || "department";
  485. switch (range) {
  486. case "unit":
  487. options.units = this.businessData.task.unitDn ? [this.businessData.task.unitDn] : [];
  488. options.exclude = exclude;
  489. callback( options );
  490. break;
  491. case "topUnit":
  492. MWF.require("MWF.xScript.Actions.UnitActions", function () {
  493. orgActions = new MWF.xScript.Actions.UnitActions();
  494. var data = { "unitList": [this.businessData.task.unitDn] };
  495. orgActions.listUnitSupNested(data, function (json) {
  496. options.units = json.data[0] ? [json.data[0]]: [];
  497. options.exclude = exclude;
  498. callback( options );
  499. }.bind(this));
  500. }.bind(this));
  501. break;
  502. case "script":
  503. o2.Actions.load("x_processplatform_assemble_surface").ProcessAction.getActivity(this.businessData.work.activity, "manual", function (activityJson) {
  504. var scriptText = activityJson.data.activity.resetRangeScriptText;
  505. if (!scriptText) return;
  506. var resetRange = this.Macro.exec(activityJson.data.activity.resetRangeScriptText, this);
  507. options.noUnit = true;
  508. options.include = typeOf(resetRange) === "array" ? resetRange : [resetRange];
  509. options.exclude = exclude;
  510. callback( options );
  511. }.bind(this));
  512. break;
  513. default:
  514. callback( options );
  515. }
  516. },
  517. getSelDefaultOptions: function(){
  518. var defaultOpt = {
  519. "type": "identity",
  520. "mainColorEnable": this.flow.options.mainColorEnable,
  521. "style": "flow",
  522. "width": "auto",
  523. "height": MWF.ProcessFlow_ORG_HEIGHT,
  524. "count": this.businessData.activity.resetCount || 0,
  525. "embedded": true,
  526. "hasLetter": false, //字母
  527. "hasTop": true //可选、已选的标题
  528. };
  529. if (this.form.json.selectorStyle) {
  530. defaultOpt = Object.merge(Object.clone(this.form.json.selectorStyle), defaultOpt);
  531. if (this.form.json.selectorStyle.style) defaultOpt.style = this.form.json.selectorStyle.style;
  532. }
  533. return defaultOpt;
  534. },
  535. getSelOrgData: function () {
  536. var data;
  537. if (this.selector && this.selector.selector) {
  538. data = this.selector.selector.selectedItems.map(function (item) {
  539. return item.data.distinguishedName;
  540. // return MWF.org.parseOrgData(item.data, true, simple);
  541. })
  542. }
  543. return data || [];
  544. },
  545. submit: function () {
  546. var names = this.getSelOrgData();
  547. if (!names.length) {
  548. this.flow.noticeError(MWF.xApplication.process.Xform.LP.inputResetPeople, this.orgsArea);
  549. return false;
  550. }
  551. var opinion = this.opinion.getValue();
  552. // var keep = this.keepOption.getValue() === "true";
  553. var leftText = MWF.xApplication.process.Xform.LP.resetTo;
  554. var nameText = [];
  555. names.each(function (n) { nameText.push(MWF.name.cn(n)); });
  556. if (!opinion) {
  557. opinion = leftText + ": " + nameText.join(", ");
  558. }
  559. var n = nameText.length > 3 ? (nameText[0]+"、"+nameText[1]+"、"+nameText[2]+"...") : nameText.join(", ");
  560. var routeName = leftText+":"+n;
  561. this.flow.quickSelector.saveData();
  562. this.fireEvent("submit", [names, opinion, routeName, this.opinion.getValue()]);
  563. },
  564. getQuickData: function(){
  565. return {
  566. routeId: "reset",
  567. opinion: this.opinion.getValue(),
  568. //keepTask: this.keepOption.getValue() === "true",
  569. organizations: {
  570. default: this.getSelOrgData()
  571. }
  572. }
  573. },
  574. destroy: function () {
  575. if (this.orgItem && this.orgItem.clearTooltip){
  576. this.orgItem.clearTooltip();
  577. }
  578. if (this.node) this.node.empty();
  579. },
  580. });
  581. MWF.ProcessFlow.AddTask = new Class({
  582. Extends: MWF.ProcessFlow.Reset,
  583. getUrl: function(){
  584. return this.flow.path+this.flow.options.style+"/addTask.html";
  585. },
  586. afterLoad: function () {
  587. this.mode = new MWF.ProcessFlow.widget.Radio(this.modeArea, this.flow, {
  588. optionList: [{
  589. text: this.lp.single,
  590. value: "single"
  591. },{
  592. text: this.lp.queue,
  593. value: "queue"
  594. },{
  595. text: this.lp.parallel,
  596. value: "parallel"
  597. }],
  598. value: this.quickData.mode || "single" //默认为单人
  599. });
  600. this.mode.load();
  601. var position = "";
  602. if( this.quickData.routeId ){
  603. position = (this.quickData.routeId === "before") ? "true" : "false";
  604. }else{
  605. position = "false"; //默认为后加签
  606. }
  607. this.position = new MWF.ProcessFlow.widget.Radio(this.positionArea, this.flow, {
  608. optionList: [{
  609. text: this.lp.addTaskBefore,
  610. value: "true"
  611. },
  612. {
  613. text: this.lp.addTaskAfter,
  614. value: "false"
  615. }],
  616. value: position
  617. });
  618. this.position.load();
  619. },
  620. submit: function () {
  621. var opinion = this.opinion.getValue();
  622. var before = this.position.getValue() === "true";
  623. if (!this.position.getValue()) {
  624. this.flow.noticeError(MWF.xApplication.process.Work.LP.inputAddTaskType, this.positionArea);
  625. return false;
  626. }
  627. var mode = this.mode.getValue();
  628. if (!mode) {
  629. this.flow.noticeError(MWF.xApplication.process.Work.LP.inputModeType, this.modeArea);
  630. return false;
  631. }
  632. var names = this.getSelOrgData();
  633. if (!names.length) {
  634. this.flow.noticeError(MWF.xApplication.process.Work.LP.inputAddTaskPeople, this.orgsArea);
  635. return false;
  636. }
  637. var leftText = (before ? this.lp.addTaskBefore : this.lp.addTaskAfter) + this.lp[mode];
  638. var nameText = names.map(function (n) { return MWF.name.cn(n); });
  639. if (!opinion) {
  640. opinion = leftText + ": " + nameText.join(", ");
  641. }
  642. var n = nameText.length > 3 ? (nameText[0]+"、"+nameText[1]+"、"+nameText[2]+"...") : nameText.join(", ");
  643. var routeName = leftText+":"+n;
  644. this.flow.quickSelector.saveData();
  645. this.fireEvent("submit", [names, opinion, mode, before, routeName, this.opinion.getValue()]);
  646. },
  647. setQuickData: function( data ){
  648. if(this.position)this.position.setValue( data.routeId === "before" ? "true" : null ); //前后加签存在 routeId
  649. if(this.mode)this.mode.setValue( data.routeGroup || null ); //单人、并行、串行存在 routeGroup
  650. if(this.opinion)this.opinion.setValue( data.opinion || "" );
  651. if(this.selector && this.selector.selector)this.selector.selector.setValues( data.organizations ? (data.organizations.default || []) : [] );
  652. },
  653. getQuickData: function(){
  654. var names = this.getSelOrgData();
  655. // var nameText = names.map(function (n) { return MWF.name.cn(n); });
  656. // var routeName = o2.xApplication.process.Xform.LP.form.addTask+":"+nameText.join(", ");
  657. return {
  658. routeId: this.position.getValue() === "true" ? "before" : "after",
  659. routeGroup: this.mode.getValue(),
  660. opinion: this.opinion.getValue(),
  661. //before: this.position.getValue() === "true",
  662. routeName: this.position.getValue() === "true" ? "before" : "after",
  663. organizations: {
  664. default: names
  665. }
  666. }
  667. },
  668. });
  669. MWF.ProcessFlow.GoBack = new Class({
  670. Extends: MWF.widget.Common,
  671. Implements: [Options, Events],
  672. options:{
  673. data: null,
  674. style: "default"
  675. },
  676. initialize: function (container, flow, options) {
  677. this.setOptions(options);
  678. this.container = $(container);
  679. this.flow = flow;
  680. this.task = flow.task;
  681. this.form = flow.form;
  682. this.lp = flow.lp;
  683. this.businessData = this.form.businessData;
  684. this.checkedItems = [];
  685. },
  686. load: function(){
  687. this.container.loadHtml(this.getUrl(), {"bind": {"lp": this.lp}, "module": this}, function(){
  688. this.loadOpinion();
  689. this.loadActivitys();
  690. }.bind(this));
  691. },
  692. getUrl: function(){
  693. return this.flow.path+this.flow.options.style+"/goBack.html";
  694. },
  695. loadActivitys: function(){
  696. o2.Actions.load('x_processplatform_assemble_surface').WorkAction.V2ListActivityGoBack(this.task.work, function(json) {
  697. this.activitys = json.data.map(function (d) {
  698. var ids = o2.name.cns(d.lastIdentityList);
  699. d.identityNameString = (ids.length>8) ? ids.slice(0,8).join(', ')+' ...' : ids.join(', ');
  700. d.identityNameTitle = ids.join(',');
  701. return d;
  702. })
  703. // var act2 = Array.clone(this.activitys);
  704. // act2[0].way = "custom";
  705. // var act3 = Array.clone(this.activitys);
  706. // act3[0].way = "custom";
  707. // var act4 = Array.clone(this.activitys);
  708. // this.activitys = this.activitys.concat(act2, act3, act4);
  709. this.activitysArea.loadHtml(this.flow.path+this.flow.options.style+"/widget/gobackActivity.html",
  710. {"bind": {"lp": this.lp, "activityList":this.activitys}, "module": this},
  711. function(){
  712. if( this.activitys.length === 1 ){
  713. var el = this.activitysArea.getElement(".o2flow-radio2");
  714. this.check( el );
  715. }
  716. this.afterLoad();
  717. this.fireEvent("load");
  718. }.bind(this));
  719. }.bind(this));
  720. },
  721. loadWayRadio: function(ev, activityData){
  722. var wayRadio = new MWF.ProcessFlow.widget.Radio(ev.target, this.flow, {
  723. optionList: [{
  724. text: this.lp.goBackActivityWayStep,
  725. value: "step"
  726. },{
  727. text: this.lp.goBackActivityWayJump,
  728. value: "jump"
  729. }],
  730. value: "step", //默认为单人
  731. onLoad: function () {
  732. this.container.getElement(".o2flow-radio-area").setStyle("display","flex");
  733. this.container.getElements(".o2flow-radio").setStyles({
  734. "padding-top":"0px",
  735. "padding-bottom":"0px"
  736. })
  737. }
  738. });
  739. wayRadio.load();
  740. var parentNode = ev.target.getParent(".o2flow-radio2");
  741. parentNode.store("wayRadio", wayRadio);
  742. ev.target.hide();
  743. },
  744. toggle: function( ev ){
  745. var el = this.flow.getEl(ev, "o2flow-radio2");
  746. if( this.checkedItems.contains( el ) ){
  747. //if( this.options.cancelEnable )this.uncheck( el, true )
  748. }else{
  749. this.check( el );
  750. }
  751. },
  752. showWayRadio: function(el){
  753. var parentNode = this.flow.getEl({target: el}, "o2flow-radio2");
  754. var wayRadio = parentNode.retrieve("wayRadio");
  755. if(wayRadio)wayRadio.container.show();
  756. },
  757. hideWayRadio: function(el){
  758. var parentNode = this.flow.getEl({target: el}, "o2flow-radio2");
  759. var wayRadio = parentNode.retrieve("wayRadio");
  760. if(wayRadio)wayRadio.container.hide();
  761. },
  762. check: function(el){
  763. while( this.checkedItems.length ){
  764. this.uncheck( this.checkedItems[0] );
  765. }
  766. el.addClass("o2flow-radio2-active");
  767. if( this.flow.options.mainColorEnable )el.addClass("mainColor_color");
  768. el.getElement("i").removeClass("o2icon-icon_circle").addClass("o2icon-radio-checked").addClass("o2flow-radio2-icon");
  769. if( this.flow.options.mainColorEnable )el.getElement("i").addClass("mainColor_color");
  770. el.dataset["o2Checked"] = true;
  771. this.activitysArea.removeClass("o2flow-invalid-bg");
  772. this.checkedItems.push(el);
  773. this.showWayRadio(el);
  774. this.fireEvent("check", [el, el.dataset["o2Value"]])
  775. },
  776. uncheck: function(el, isFire){
  777. el.removeClass("o2flow-radio2-active");
  778. if( this.flow.options.mainColorEnable )el.removeClass("mainColor_color");
  779. el.getElement("i").removeClass("o2icon-radio-checked").addClass("o2icon-icon_circle").removeClass("o2flow-radio2-icon");
  780. if( this.flow.options.mainColorEnable )el.getElement("i").removeClass("mainColor_color");
  781. el.dataset["o2Checked"] = false;
  782. this.checkedItems.erase(el);
  783. this.hideWayRadio(el);
  784. if(isFire)this.fireEvent("uncheck", [el, el.dataset["o2Value"]])
  785. },
  786. show: function(){
  787. },
  788. afterLoad: function () {
  789. },
  790. loadOpinion: function(){
  791. var opt = Object.clone(this.flow.options.opinionOptions);
  792. opt.isHandwriting = this.options.isHandwriting;
  793. this.opinion = new MWF.ProcessFlow.widget.Opinion( this.opinionContent, this.flow, opt );
  794. this.opinion.load();
  795. },
  796. submit: function () {
  797. if (!this.checkedItems.length) {
  798. this.activitysArea.addClass("o2flow-invalid-bg");
  799. this.flow.noticeError(
  800. MWF.xApplication.process.Work.LP.selectGoBackActivity,
  801. this.activitysArea,
  802. null,
  803. {"x": "center", "y": "top"}
  804. );
  805. return false;
  806. }
  807. var itemNode = this.checkedItems[0];
  808. var activity = itemNode.dataset["o2Value"];
  809. var activityName = itemNode.dataset["o2Text"];
  810. var way;
  811. var wayRadio = itemNode.retrieve("wayRadio");
  812. if( wayRadio ){
  813. way = wayRadio.getValue();
  814. }else{
  815. way = itemNode.dataset["o2Way"];
  816. }
  817. var opinion = this.opinion.getValue();
  818. if(!opinion)opinion = this.lp.goBackTo+activityName;
  819. var routeName = this.lp.goBackTo+activityName;
  820. debugger;
  821. this.fireEvent("submit", [opinion, routeName, activity, way, this.opinion.getValue()]);
  822. },
  823. // getQuickData: function(){
  824. // return {
  825. // routeId: "goBack",
  826. // opinion: this.opinion.getValue(),
  827. // //keepTask: this.keepOption.getValue() === "true",
  828. // organizations: {
  829. // default: this.getSelOrgData()
  830. // }
  831. // }
  832. // },
  833. destroy: function () {
  834. if (this.node) this.node.empty();
  835. },
  836. });
  837. MWF.ProcessFlow.Processor = new Class({
  838. Extends: MWF.widget.Common,
  839. Implements: [Options, Events],
  840. options: {
  841. "style": "default",
  842. "defaultRouteGroup": "",
  843. "defaultRoute": ""
  844. },
  845. initialize: function (container, flow, options) {
  846. this.setOptions(options);
  847. this.container = $(container);
  848. this.node = this.container;
  849. this.flow = flow;
  850. this.task = flow.task;
  851. this.form = flow.form;
  852. this.lp = flow.lp;
  853. this.businessData = this.form.businessData;
  854. this.routeOrgMap = {};
  855. },
  856. load: function( quickData ){
  857. this.quickData = quickData;
  858. if( quickData )quickData.rId = quickData.routeId;
  859. if( quickData && (quickData.routeId || quickData.routeName) ){
  860. this.options.defaultRoute = quickData.routeId || quickData.routeName;
  861. delete quickData.routeId;
  862. delete quickData.routeName;
  863. this.options.defaultRouteGroup = quickData.routeGroup;
  864. delete quickData.routeGroup;
  865. }
  866. this.container.loadHtml(this.flow.path+this.flow.options.style+"/process.html", {"bind": {"lp": this.lp}, "module": this}, function(){
  867. this.loadOpinion();
  868. this.loadRouteOrGroupList();
  869. //this.loadOrg();
  870. //this.afterLoad();
  871. }.bind(this));
  872. },
  873. checkLoadEvent: function(){
  874. if( !this.loadEventFired ){
  875. this.fireEvent("load");
  876. this.loadEventFired = true;
  877. }
  878. },
  879. setQuickData: function( quickData ){
  880. this.quickData = quickData;
  881. if(quickData)quickData.rId = quickData.routeId;
  882. if( this.routeGroupRadio && quickData.routeGroup ){
  883. if( quickData.routeId || quickData.routeName ){
  884. this.options.defaultRoute = quickData.routeId || quickData.routeName;
  885. delete quickData.routeId;
  886. delete quickData.routeName;
  887. }
  888. this.routeGroupRadio.setValue( quickData.routeGroup );
  889. delete quickData.routeGroup;
  890. }else{
  891. this.routeRadio.setValue( quickData.routeId );
  892. delete quickData.routeId;
  893. }
  894. if(this.opinion){
  895. this.opinion.setValue( quickData.opinion || "" );
  896. delete quickData.opinion;
  897. }
  898. //if(this.selector && this.selector.selector)this.selector.selector.setValues( data.organizations ? (data.organizations.default || []) : [] );
  899. },
  900. loadOpinion: function(){
  901. var opt = Object.clone(this.flow.options.opinionOptions);
  902. opt.isHandwriting = this.options.isHandwriting;
  903. if( this.quickData && this.quickData.opinion ){
  904. opt.opinion = this.quickData.opinion;
  905. delete this.quickData.opinion;
  906. }
  907. this.opinion = new MWF.ProcessFlow.widget.Opinion( this.opinionContent, this.flow, opt );
  908. this.opinion.load();
  909. },
  910. loadRouteOrGroupList: function () {
  911. this.getRouteGroupConfig();
  912. if (this.hasRouteGroup) {
  913. this.loadRouteGroupList();
  914. } else {
  915. this.routeGroupWraper.destroy();
  916. this.routeWraper.removeClass("o2flow-route-wraper").addClass("o2flow-route-fullsize-wraper");
  917. this.routeArea.removeClass("o2flow-route-area").addClass("o2flow-route-fullsize-area");
  918. this.loadRouteList();
  919. }
  920. },
  921. loadRouteGroupList: function(){
  922. var keys = this.routeGroupNameList;
  923. keys.sort(function (a, b) {
  924. var aIdx = parseInt(this.flow.splitByStartNumber(a).order || "9999999");
  925. var bIdx = parseInt(this.flow.splitByStartNumber(b).order || "9999999");
  926. return aIdx - bIdx;
  927. }.bind(this));
  928. var routeGroupNames = keys.map(function (k) { return this.flow.splitByStartNumber(k).name; }.bind(this));
  929. var defaultValue;
  930. if( keys.length === 1 ) {
  931. defaultValue = routeGroupNames[0];
  932. }else if( this.opinion.defaultRouteGroup ){
  933. defaultValue = this.opinion.defaultRouteGroup;
  934. this.opinion.defaultRouteGroup = "";
  935. }else if( this.options.defaultRoute ){
  936. routeGroupNames.each(function (routeGroupName) {
  937. if( defaultValue )return;
  938. var routeList = this.routeGroupObject[routeGroupName];
  939. var matchRoutes = routeList.filter(function(r){ return r.id === this.options.defaultRoute || r.name === this.options.defaultRoute; }.bind(this));
  940. if( matchRoutes.length )defaultValue = routeGroupName;
  941. }.bind(this));
  942. }
  943. var optionList = routeGroupNames.map(function (routeGroupName) {
  944. return {
  945. text: routeGroupName,
  946. value: routeGroupName,
  947. data: this.routeGroupObject[routeGroupName]
  948. };
  949. }.bind(this));
  950. var _self = this;
  951. this.routeGroupRadio = new MWF.ProcessFlow.widget.Radio2(this.routeGroupArea, this.flow, {
  952. optionList: optionList,
  953. cancelEnable: false,
  954. onCheck: function(el, value){
  955. var routeConfigList = this.getData().data;
  956. _self.loadRouteList( routeConfigList );
  957. },
  958. onLoad: function(){
  959. if( defaultValue ){
  960. this.setValue( defaultValue );
  961. }else{
  962. _self.loadOrgs();
  963. }
  964. }
  965. });
  966. this.routeGroupRadio.load();
  967. },
  968. loadRouteList: function (routeConfigList) {
  969. var _self = this;
  970. this.routeArea.empty();
  971. if (!routeConfigList) routeConfigList = this.getRouteConfigList();
  972. var optionList = [], isSelectedDefault = false, defaultRoute;
  973. routeConfigList.each(function (route, i) {
  974. if ( route.hiddenScriptText ) {
  975. if (this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true") return;
  976. }
  977. var routeName = route.name;
  978. if (route.displayNameScriptText && this.form && this.form.Macro) {
  979. routeName = this.form.Macro.exec(route.displayNameScriptText, this);
  980. }
  981. optionList.push({
  982. value: route.id,
  983. text: routeName,
  984. data: route
  985. });
  986. if( route.id === this.options.defaultRoute || route.name === this.options.defaultRoute) {
  987. defaultRoute = route.id;
  988. this.options.defaultRoute = "";
  989. isSelectedDefault = true;
  990. }else if ( !isSelectedDefault && (routeConfigList.length == 1 || route.sole )) { //sole表示优先路由
  991. defaultRoute = route.id;
  992. }
  993. }.bind(this));
  994. this.routeRadio = new MWF.ProcessFlow.widget.Radio(this.routeArea, this.flow, {
  995. optionList: optionList,
  996. onCheck: function(el, value){
  997. var routeConfig = this.getData().data;
  998. var checkOpinion = function(){
  999. var op = _self.opinion.getValue();
  1000. if( op === (_self.lastDefaultOpinion || "") || op === "" ){
  1001. _self.lastDefaultOpinion = routeConfig.opinion || "";
  1002. _self.opinion.setValue( _self.lastDefaultOpinion );
  1003. }
  1004. };
  1005. if( _self.opinion.loaded ){
  1006. checkOpinion()
  1007. }else{
  1008. _self.opinion.addEvent("load", checkOpinion);
  1009. }
  1010. _self.loadOrgs( routeConfig );
  1011. },
  1012. onUncheck: function(el, value){
  1013. var routeConfig = this.getData( value ).data;
  1014. var op = _self.opinion.getValue();
  1015. if (op === (routeConfig.opinion || "") || op === "" ) {
  1016. _self.lastDefaultOpinion = "";
  1017. _self.opinion.setValue("");
  1018. }
  1019. _self.loadOrgs();
  1020. },
  1021. onLoad: function(){
  1022. if( defaultRoute ){
  1023. this.setValue( defaultRoute );
  1024. }else{
  1025. _self.loadOrgs();
  1026. }
  1027. }
  1028. });
  1029. this.routeRadio.load();
  1030. },
  1031. loadOrgs: function( routeConfig ){
  1032. for( var r in this.routeOrgMap ){
  1033. this.routeOrgMap[r].hide();
  1034. }
  1035. var notFireResize = !this.loadEventFired;
  1036. if( routeConfig ){
  1037. var routeId = routeConfig.id;
  1038. var orgList = this.routeOrgMap[routeId];
  1039. if( orgList ){
  1040. orgList.load( notFireResize );
  1041. }else{
  1042. orgList = new MWF.ProcessFlow.Processor.OrgList(this, {
  1043. routeId: routeId
  1044. });
  1045. this.routeOrgMap[routeId] = orgList;
  1046. orgList.load( notFireResize );
  1047. }
  1048. this.currentOrgList = orgList;
  1049. }else{
  1050. this.orgsWraper.hide();
  1051. //this.setSize(0);
  1052. if( !notFireResize )this.flow.resize();
  1053. this.currentOrgList = null;
  1054. }
  1055. this.checkLoadEvent();
  1056. },
  1057. cancel: function(){
  1058. this.destroy();
  1059. this.fireEvent("cancel");
  1060. },
  1061. submit: function (ev) {
  1062. if (this.hasRouteGroup && !this.routeGroupRadio.getValue() ) {
  1063. this.routeGroupRadio.setRequireStyle();
  1064. this.flow.noticeError(
  1065. MWF.xApplication.process.Work.LP.mustSelectRouteGroup,
  1066. this.routeGroupArea,
  1067. null,
  1068. {"x": "center", "y": "top"}
  1069. );
  1070. return false;
  1071. }
  1072. if (!this.routeRadio.getValue()) {
  1073. this.routeRadio.setRequireStyle();
  1074. this.flow.noticeError(
  1075. MWF.xApplication.process.Work.LP.mustSelectRoute,
  1076. this.routeArea,
  1077. null, //{"x": 0, "y": 30}
  1078. {"x": "center", "y": "top"}
  1079. );
  1080. return false;
  1081. }
  1082. var routeName = this.routeRadio.getData().data.name;
  1083. var opinion = this.opinion.getValue();
  1084. var medias = [];
  1085. if (this.opinion.handwritingFile) medias.push(this.opinion.handwritingFile);
  1086. var currentRouteId = this.routeRadio.getValue();
  1087. var routeConfig = this.getRouteConfig(currentRouteId);
  1088. if (!opinion && medias.length === 0) {
  1089. if (routeConfig.opinionRequired === true) {
  1090. this.opinion.setRequireStyle();
  1091. this.flow.noticeError(
  1092. MWF.xApplication.process.Work.LP.opinionRequired,
  1093. this.opinion.opinionTextarea,
  1094. null,
  1095. {"x": "center", "y": "top"}
  1096. );
  1097. return false;
  1098. }
  1099. }
  1100. var orgItems = this.currentOrgList ? this.currentOrgList.orgVisableItems : [];
  1101. var appendTaskOrgItem = "";
  1102. if (routeConfig.type === "appendTask" && routeConfig.appendTaskIdentityType === "select") {
  1103. if (!orgItems || orgItems.length === 0) {
  1104. this.flow.noticeError(
  1105. MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig,
  1106. this.node,
  1107. null
  1108. );
  1109. return false;
  1110. } else {
  1111. appendTaskOrgItem = orgItems[0];
  1112. }
  1113. }
  1114. this.currentOrgList.saveOrgsWithCheckEmpower(function () {
  1115. var appandTaskIdentityList;
  1116. if (appendTaskOrgItem) {
  1117. appandTaskIdentityList = appendTaskOrgItem.getData();
  1118. if (!appandTaskIdentityList || appandTaskIdentityList.length === 0) {
  1119. this.flow.noticeError(
  1120. MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice,
  1121. this.node
  1122. );
  1123. return;
  1124. }
  1125. }
  1126. if (routeConfig.validationScriptText) {
  1127. var validation = this.form.Macro.exec(routeConfig.validationScriptText, this);
  1128. if (!validation || validation.toString() !== "true") {
  1129. if (typeOf(validation) === "string") {
  1130. this.flow.noticeError( validation, this.node );
  1131. return false;
  1132. } else {
  1133. //"路由校验失败"
  1134. this.flow.noticeError(
  1135. MWF.xApplication.process.Work.LP.routeValidFailure,
  1136. this.node
  1137. );
  1138. return false;
  1139. }
  1140. }
  1141. }
  1142. this.node.mask({
  1143. "inject": {"where": "bottom", "target": this.node},
  1144. "destroyOnHide": true,
  1145. "style": {
  1146. "background-color": "#999",
  1147. "opacity": 0.3,
  1148. "z-index": this.flow.options.zIndex+1
  1149. }
  1150. });
  1151. var array = [routeName, opinion, medias, appandTaskIdentityList, orgItems, function () {
  1152. if (appendTaskOrgItem) appendTaskOrgItem.setData([]);
  1153. }];
  1154. this.flow.quickSelector.saveData();
  1155. this.fireEvent("submit", array);
  1156. }.bind(this));
  1157. },
  1158. getQuickData: function(){
  1159. var organizations = {};
  1160. var orgItems = this.currentOrgList ? this.currentOrgList.orgVisableItems : [];
  1161. orgItems.each(function (org) {
  1162. var vs = org.getValue();
  1163. organizations[org.json.name] = vs.map(function (o) {
  1164. return typeOf(o) === "string" ? o : o.distinguishedName;
  1165. })
  1166. });
  1167. var route = this.routeRadio.getData().data;
  1168. return {
  1169. routeGroup: this.routeGroupRadio ? this.routeGroupRadio.getValue() : "",
  1170. routeId: route.id,
  1171. routeName: route.name,
  1172. opinion: this.opinion.getValue(),
  1173. organizations: organizations
  1174. }
  1175. },
  1176. destroy: function () {
  1177. Object.values( this.routeOrgMap ).each(function (orgList) {
  1178. Object.values( orgList.orgMap ).each(function( org ){
  1179. if(org.clearTooltip)org.clearTooltip();
  1180. });
  1181. });
  1182. },
  1183. getRouteGroupConfig: function () {
  1184. var config = this.flow.getRouteGroupConfig();
  1185. this.routeGroupObject = this.flow.routeGroupObject;
  1186. this.routeGroupNameList = this.flow.routeGroupNameList;
  1187. this.hasRouteGroup = this.flow.hasRouteGroup;
  1188. return config;
  1189. },
  1190. getRouteConfigList: function () {
  1191. return this.flow.getRouteConfigList();
  1192. },
  1193. getRouteConfig: function (routeId) {
  1194. return this.flow.getRouteConfig( routeId );
  1195. },
  1196. getOrgConfig: function (routeId) {
  1197. return this.flow.getOrgConfig( routeId );
  1198. },
  1199. getVisableOrgConfig: function (routeId) {
  1200. return this.flow.getVisableOrgConfig(routeId);
  1201. },
  1202. isOrgHidden: function (d) {
  1203. return this.flow.isOrgHidden(d);
  1204. },
  1205. getMaxOrgLength: function () {
  1206. return this.flow.getMaxOrgLength();
  1207. },
  1208. getOffsetY: function (node) {
  1209. return (node.getStyle("margin-top").toInt() || 0) +
  1210. (node.getStyle("margin-bottom").toInt() || 0) +
  1211. (node.getStyle("padding-top").toInt() || 0) +
  1212. (node.getStyle("padding-bottom").toInt() || 0) +
  1213. (node.getStyle("border-top-width").toInt() || 0) +
  1214. (node.getStyle("border-bottom-width").toInt() || 0);
  1215. },
  1216. // setSize: function (currentOrgLength, flag) {
  1217. // this.flow.resize()
  1218. // return;
  1219. // }
  1220. });
  1221. MWF.xDesktop.requireApp("process.Xform", "Org", null, false);
  1222. MWF.ProcessFlow.Processor.OrgList = new Class({
  1223. Implements: [Options, Events],
  1224. options: {
  1225. routeId: ""
  1226. },
  1227. initialize: function (processor, options) {
  1228. this.processor = processor;
  1229. this.form = processor.form;
  1230. this.flow = processor.flow;
  1231. this.businessData = this.form.businessData;
  1232. this.wraper = processor.orgsWraper;
  1233. this.container = processor.orgsArea;
  1234. this.node = new Element("div").inject( processor.orgsArea );
  1235. this.setOptions(options);
  1236. this.orgs = [];
  1237. this.orgMap = {};
  1238. this.domMap = {};
  1239. },
  1240. load: function ( notFireResize ) {
  1241. this.orgVisableItems = [];
  1242. var configVisable = this.getVisableOrgConfig();
  1243. if (configVisable.length) {
  1244. this.wraper.show();
  1245. this.node.show();
  1246. this.loadOrgs();
  1247. //this.processor.setSize(configVisable.length);
  1248. if(!notFireResize)this.flow.resize();
  1249. } else {
  1250. this.orgMap = {};
  1251. this.domMap = {};
  1252. this.node.hide();
  1253. this.wraper.hide();
  1254. //this.processor.setSize(0);
  1255. if(!notFireResize)this.flow.resize();
  1256. }
  1257. },
  1258. hide: function(){
  1259. this.node.hide();
  1260. },
  1261. getVisableOrgConfig: function(){
  1262. return this.processor.getVisableOrgConfig( this.options.routeId );
  1263. },
  1264. getQuickOrgData: function( orgConfig ){
  1265. if( !this.processor.quickData )return;
  1266. if( this.processor.quickData.rId !== this.options.routeId )return;
  1267. if( !this.processor.quickData.organizations )return;
  1268. var d = this.processor.quickData.organizations[orgConfig.name];
  1269. delete this.processor.quickData.organizations[orgConfig.name];
  1270. return d;
  1271. },
  1272. loadOrgs: function () {
  1273. var lastDom, configVisable = this.getVisableOrgConfig(), len = configVisable.length, lineNode;
  1274. configVisable.each(function (config, i) {
  1275. var dom, cfgId = config.id, quickOrgData = this.getQuickOrgData( config );
  1276. if( i % 2 === 0 )lineNode = new Element("div.o2flow-org-line").inject( this.node );
  1277. if( this.domMap[cfgId] ){
  1278. dom = this.domMap[cfgId].show().inject( lineNode );
  1279. if( quickOrgData && this.orgMap[cfgId]){
  1280. var org = this.orgMap[cfgId];
  1281. org.setData( quickOrgData );
  1282. org.resetSelectorData();
  1283. }
  1284. this.orgVisableItems.push( this.orgMap[cfgId] );
  1285. }else{
  1286. //dom = new Element("div" ).inject( lastDom || this.node, lastDom ? "after" : "bottom" );
  1287. dom = new Element("div" ).inject( lineNode );
  1288. this.domMap[cfgId] = dom;
  1289. this.loadOrg(dom, config, false, quickOrgData );
  1290. }
  1291. if( (i + 1 === len) && (len % 2 === 1) ){ //fullsize
  1292. dom.addClass("o2flow-org-fullsize-node").removeClass("o2flow-org-left-node").removeClass("o2flow-org-right-node");
  1293. }else{
  1294. if( i % 2 === 0 ){ //left
  1295. dom.removeClass("o2flow-org-fullsize-node").addClass("o2flow-org-left-node").removeClass("o2flow-org-right-node");
  1296. }else{
  1297. dom.removeClass("o2flow-org-fullsize-node").removeClass("o2flow-org-left-node").addClass("o2flow-org-right-node");
  1298. }
  1299. }
  1300. //lastDom = dom;
  1301. }.bind(this));
  1302. },
  1303. loadOrg: function (container, json, ignoreOldData, quickOrgData) {
  1304. var titleNode = new Element("div.o2flow-selector-title").inject(container);
  1305. new Element("div.o2flow-selector-titletext", { "text": json.title }).inject(titleNode);
  1306. var errorNode = new Element("div.o2flow-selector-errornode").inject(titleNode);
  1307. var contentNode = new Element("div.o2flow-selector-content").inject(container);
  1308. contentNode.setStyle( "height", MWF.ProcessFlow_ORG_HEIGHT + "px" );
  1309. var org = new MWF.ProcessFlow.Processor.Org(contentNode, this.form, json, this);
  1310. org.ignoreOldData = ignoreOldData;
  1311. org.errContainer = errorNode;
  1312. org.load( quickOrgData );
  1313. this.orgVisableItems.push(org);
  1314. this.orgMap[json.id] = org;
  1315. },
  1316. clearAllOrgs: function () {
  1317. //清空组织所选人
  1318. Object.values(this.orgMap).each(function (org) {
  1319. org.setDataToOriginal();
  1320. })
  1321. this.orgMap = {};
  1322. this.domMap = {};
  1323. this.orgVisableItems = [];
  1324. this.node.empty();
  1325. },
  1326. getSelectedData: function (filedName) {
  1327. var data = [];
  1328. for (var i = 0; i < this.orgVisableItems.length; i++) {
  1329. var org = this.orgVisableItems[i];
  1330. if (org.json.name === filedName) {
  1331. var selector = org.selector.selector;
  1332. selector.selectedItems.each(function (item) {
  1333. data.push(item.data)
  1334. })
  1335. }
  1336. }
  1337. return data;
  1338. },
  1339. isErrorHeightOverflow: function () {
  1340. var hasOverflow = false;
  1341. (this.orgVisableItems || []).each(function (item) {
  1342. if (item.errorHeightOverflow) {
  1343. hasOverflow = true;
  1344. }
  1345. }.bind(this));
  1346. return hasOverflow;
  1347. },
  1348. checkErrorHeightOverflow: function (force) {
  1349. if (force || this.isErrorHeightOverflow()) {
  1350. //this.processor.setSize(this.orgVisableItems.length, true);
  1351. this.flow.resize();
  1352. }
  1353. },
  1354. errorHeightChange: function () {
  1355. this.checkErrorHeightOverflow(true)
  1356. },
  1357. validationOrgs: function () {
  1358. if (!this.orgVisableItems || !this.orgVisableItems.length) return true;
  1359. var flag = true;
  1360. this.orgVisableItems.each(function (item) {
  1361. if (!item.validation()) flag = false;
  1362. }.bind(this));
  1363. this.checkErrorHeightOverflow();
  1364. return flag;
  1365. },
  1366. isOrgsHasEmpower: function () {
  1367. if (!this.orgVisableItems || !this.orgVisableItems.length) return true;
  1368. this.needCheckEmpowerOrg = [];
  1369. var ps = this.orgVisableItems.map(function (item) {
  1370. return Promise.resolve( item.hasEmpowerIdentity() ).then(function ( flag ) {
  1371. if( flag )return item;
  1372. }.bind(this));
  1373. }.bind(this));
  1374. return Promise.all( ps ).then(function ( array ) {
  1375. this.needCheckEmpowerOrg = array.clean();
  1376. return this.needCheckEmpowerOrg.length > 0;
  1377. }.bind(this));
  1378. },
  1379. saveOrgs: function (keepSilent) {
  1380. if (!this.orgVisableItems || !this.orgVisableItems.length) return true;
  1381. var flag = true;
  1382. this.orgVisableItems.each(function (item) {
  1383. if (!item.save(!keepSilent)) flag = false;
  1384. }.bind(this));
  1385. return flag;
  1386. },
  1387. saveOrgsWithCheckEmpower: function (callback) {
  1388. var visableOrg = this.getVisableOrgConfig();
  1389. var needOrgLength = visableOrg.length;
  1390. var loadedOrgLength = 0;
  1391. if ( this.orgVisableItems && this.orgVisableItems.length)loadedOrgLength = this.orgVisableItems.length;
  1392. if( needOrgLength !== loadedOrgLength ){
  1393. this.flow.noticeError(
  1394. MWF.xApplication.process.Work.LP.loadedOrgCountUnexpected,
  1395. this.node
  1396. );
  1397. return false;
  1398. }
  1399. if (!this.orgVisableItems || !this.orgVisableItems.length) {
  1400. if (callback) callback();
  1401. return true;
  1402. }
  1403. if (!this.validationOrgs()) return false;
  1404. Promise.resolve( this.isOrgsHasEmpower() ).then(function (flag) {
  1405. if( flag ){
  1406. this.showEmpowerDlg(callback);
  1407. }else{
  1408. if (callback) callback();
  1409. return true;
  1410. }
  1411. }.bind(this));
  1412. },
  1413. showEmpowerDlg: function (callback) {
  1414. var empowerNode = new Element("div.o2flow-empower-node");
  1415. empowerNode.loadCss( this.flow.path + this.flow.options.style + "/style.css" );
  1416. var empowerTitleNode = new Element("div.o2flow-empower-titleNode", {
  1417. text: MWF.xApplication.process.Xform.LP.empowerDlgText
  1418. }).inject(empowerNode);
  1419. var orgs = this.needCheckEmpowerOrg;
  1420. var len = orgs.length;
  1421. var lines = ((len + 1) / 2).toInt();
  1422. var empowerTable = new Element("table.o2flow-empower-table", {
  1423. "cellspacing": 0, "cellpadding": 0, "border": 0, "width": "100%"
  1424. }).inject(empowerNode);
  1425. for (var n = 0; n < lines; n++) {
  1426. var tr = new Element("tr").inject(empowerTable);
  1427. new Element("td.o2flow-empower-oddTd").inject(tr);
  1428. new Element("td.o2flow-empower-evenTd").inject(tr);
  1429. }
  1430. var trs = empowerTable.getElements("tr");
  1431. orgs.each(function (org, i) {
  1432. var sNode;
  1433. var width;
  1434. if (i + 1 == len && (len % 2 === 1)) {
  1435. sNode = trs[trs.length - 1].getFirst("td");
  1436. sNode.set("colspan", 2);
  1437. trs[trs.length - 1].getLast("td").destroy();
  1438. width = "50%";
  1439. } else {
  1440. var row = ((i + 2) / 2).toInt();
  1441. var tr = trs[row - 1];
  1442. sNode = (i % 2 === 0) ? tr.getFirst("td") : tr.getLast("td");
  1443. }
  1444. org.loadCheckEmpower(sNode);
  1445. }.bind(this));
  1446. var width = 840;
  1447. empowerNode.setStyle("height", lines * MWF.ProcessFlow_ORG_HEIGHT + 20);
  1448. empowerNode.setStyle("width", width + "px");
  1449. empowerNode.setStyle("opacity", 0);
  1450. this.node.getParent().mask({
  1451. "opacity": 0.7,
  1452. "background-color": "#eee",
  1453. "z-index": this.flow.options.zIndex + 2
  1454. });
  1455. this.empowerDlg = o2.DL.open({
  1456. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1457. "style": this.form.json.dialogStyle || "user",
  1458. "isResize": false,
  1459. "content": empowerNode,
  1460. //"container" : this.node,
  1461. "width": width + 40, //600,
  1462. "height": "auto", //dlgHeight,
  1463. "mark": true,
  1464. "zindex": this.flow.options.zIndex + 3,
  1465. "onPostShow": function () {
  1466. if (this.nodeWidth)this.node.setStyle("width", this.nodeWidth + "px");
  1467. if (this.nodeHeight)this.node.setStyle("height", this.nodeHeight + "px");
  1468. empowerNode.setStyle("opacity", 1);
  1469. },
  1470. "buttonList": [
  1471. {
  1472. "type": "ok",
  1473. "text": MWF.LP.process.button.ok,
  1474. "action": function (d, e) {
  1475. orgs.each(function (org, i) {
  1476. org.saveCheckedEmpowerData(function () {
  1477. if (i === orgs.length - 1) {
  1478. if (callback) callback();
  1479. this.node.getParent().unmask();
  1480. this.empowerDlg.close();
  1481. }
  1482. }.bind(this))
  1483. }.bind(this))
  1484. }.bind(this)
  1485. },
  1486. {
  1487. "type": "cancel",
  1488. "text": MWF.LP.process.button.cancel,
  1489. "action": function () {
  1490. this.node.getParent().unmask();
  1491. this.empowerDlg.close();
  1492. }.bind(this)
  1493. }
  1494. ]
  1495. });
  1496. },
  1497. });
  1498. MWF.ProcessFlow.Processor.Org = new Class({
  1499. Implements: [Options, Events],
  1500. options: {
  1501. moduleEvents: ["queryLoadSelector", "postLoadSelector", "postLoadContent", "queryLoadCategory", "postLoadCategory",
  1502. "selectCategory", "unselectCategory", "queryLoadItem", "postLoadItem", "selectItem", "unselectItem", "change"]
  1503. },
  1504. initialize: function (container, form, json, processor, options) {
  1505. this.form = form;
  1506. this.json = json;
  1507. this.processor = processor;
  1508. this.container = $(container);
  1509. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1510. this.setOptions(options);
  1511. },
  1512. load: function ( quickData ) {
  1513. var options = this.getOptions();
  1514. if (options) {
  1515. if( quickData )options.values = quickData;
  1516. this.selector = new MWF.O2Selector(this.container, options);
  1517. }
  1518. },
  1519. clearTooltip: function(){
  1520. if( this.selector && this.selector.selector && this.selector.selector.clearTooltip ){
  1521. this.selector.selector.clearTooltip();
  1522. }
  1523. },
  1524. _getOrgOptions: function () {
  1525. this.selectTypeList = typeOf(this.json.selectType) == "array" ? this.json.selectType : [this.json.selectType];
  1526. if (this.selectTypeList.contains("identity")) {
  1527. this.identityOptions = new MWF.ProcessFlow.Processor.IdentityOptions(this.form, this.json);
  1528. }
  1529. if (this.selectTypeList.contains("unit")) {
  1530. this.unitOptions = new MWF.ProcessFlow.Processor.UnitOptions(this.form, this.json);
  1531. }
  1532. if( this.selectTypeList.contains( "group" ) ){
  1533. this.groupOptions = new MWF.ProcessFlow.Processor.GroupOptions( this.form, this.json );
  1534. }
  1535. },
  1536. getDefaultOptions: function(){
  1537. return {
  1538. "style": "flow",
  1539. "mainColorEnable": this.processor.flow.options.mainColorEnable,
  1540. "width": "auto",
  1541. "height": MWF.ProcessFlow_ORG_HEIGHT,
  1542. "embedded": true,
  1543. "hasLetter": false, //字母
  1544. "hasTop": true //可选、已选的标题
  1545. };
  1546. },
  1547. getOptionEvents: function(){
  1548. return {};
  1549. },
  1550. getOptions: function () {
  1551. var _self = this;
  1552. this._getOrgOptions();
  1553. if (this.selectTypeList.length === 0) return false;
  1554. var exclude = [];
  1555. if (this.json.exclude) {
  1556. var v = this.form.Macro.exec(this.json.exclude.code, this);
  1557. exclude = typeOf(v) === "array" ? v : [v];
  1558. }
  1559. var identityOpt;
  1560. if (this.identityOptions) {
  1561. identityOpt = this.identityOptions.getOptions();
  1562. if (this.json.identityRange !== "all") {
  1563. if (!identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length)) {
  1564. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  1565. identityOpt.disabled = true;
  1566. // return false;
  1567. }
  1568. }
  1569. if (!identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange !== "all") {
  1570. if (!identityOpt.dutys || !identityOpt.dutys.length) {
  1571. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  1572. identityOpt.disabled = true;
  1573. // return false;
  1574. }
  1575. }
  1576. if (this.ignoreOldData) {
  1577. identityOpt.values = this._computeValue() || [];
  1578. } else {
  1579. identityOpt.values = this.getValue() || [];
  1580. }
  1581. identityOpt.exclude = exclude;
  1582. }
  1583. var unitOpt;
  1584. if (this.unitOptions) {
  1585. unitOpt = this.unitOptions.getOptions();
  1586. if (this.json.unitRange !== "all") {
  1587. if (!unitOpt.units || !unitOpt.units.length) {
  1588. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  1589. unitOpt.disabled = true;
  1590. // return false;
  1591. }
  1592. }
  1593. if (this.ignoreOldData) {
  1594. unitOpt.values = this._computeValue() || [];
  1595. } else {
  1596. unitOpt.values = this.getValue() || [];
  1597. }
  1598. unitOpt.exclude = exclude;
  1599. }
  1600. var groupOpt;
  1601. if( this.groupOptions ){
  1602. groupOpt = this.groupOptions.getOptions();
  1603. if (this.ignoreOldData) {
  1604. groupOpt.values = this._computeValue() || [];
  1605. } else {
  1606. groupOpt.values = this.getValue() || [];
  1607. }
  1608. groupOpt.exclude = exclude;
  1609. }
  1610. var defaultOpt = this.getDefaultOptions();
  1611. if (this.json.events && typeOf(this.json.events) === "object") {
  1612. Object.each(this.json.events, function (e, key) {
  1613. if (e.code) {
  1614. if (this.options.moduleEvents.indexOf(key) !== -1) {
  1615. if (key === "postLoadSelector") {
  1616. this.addEvent("loadSelector", function (selector) {
  1617. return this.form.Macro.fire(e.code, selector);
  1618. }.bind(this))
  1619. } else if (key === "queryLoadSelector") {
  1620. defaultOpt["onQueryLoad"] = function (target) {
  1621. return this.form.Macro.fire(e.code, target);
  1622. }.bind(this)
  1623. } else {
  1624. defaultOpt["on" + key.capitalize()] = function (target) {
  1625. return this.form.Macro.fire(e.code, target);
  1626. }.bind(this)
  1627. }
  1628. }
  1629. }
  1630. }.bind(this));
  1631. }
  1632. if (this.needValid()) {
  1633. defaultOpt["onValid"] = function (selector) {
  1634. this.validOnSelect();
  1635. }.bind(this);
  1636. }
  1637. if (this.form.json.selectorStyle) {
  1638. defaultOpt = Object.merge(Object.clone(this.form.json.selectorStyle), defaultOpt);
  1639. if (this.form.json.selectorStyle.style) defaultOpt.style = this.form.json.selectorStyle.style;
  1640. }
  1641. var events = this.getOptionEvents();
  1642. if (this.selectTypeList.length === 1) {
  1643. var opts = Object.merge(
  1644. defaultOpt,
  1645. {
  1646. "type": this.selectTypeList[0],
  1647. "onLoad": function () {
  1648. //this 为 selector
  1649. _self.selectOnLoad(this, this.selector)
  1650. }
  1651. },
  1652. events,
  1653. identityOpt || unitOpt || groupOpt
  1654. )
  1655. return this.filterOptionValues( opts, this.selectTypeList[0] );
  1656. } else if (this.selectTypeList.length > 1) {
  1657. var options = {
  1658. "type": "",
  1659. "types": this.selectTypeList,
  1660. "onLoad": function () {
  1661. //this 为 selector
  1662. _self.selectOnLoad(this)
  1663. }
  1664. };
  1665. if (identityOpt) {
  1666. options.identityOptions = Object.merge(
  1667. defaultOpt, events, identityOpt
  1668. );
  1669. }
  1670. if (unitOpt) {
  1671. options.unitOptions = Object.merge(
  1672. defaultOpt, events, unitOpt
  1673. );
  1674. }
  1675. if (groupOpt) {
  1676. options.groupOptions = Object.merge(
  1677. defaultOpt, events, groupOpt
  1678. );
  1679. }
  1680. return options;
  1681. }
  1682. },
  1683. filterOptionValues: function( options, type ){
  1684. var suffix;
  1685. switch (type) {
  1686. case "identity": suffix = "I"; break;
  1687. case "unit": suffix = "U"; break;
  1688. case "group": suffix = "G"; break;
  1689. }
  1690. options.values = (options.values || []).filter(function (v) {
  1691. if( typeOf(v) === "string" ){
  1692. if( v.contains("@") ){
  1693. return v.split("@").getLast().toUpperCase() === suffix;
  1694. }else{
  1695. return true;
  1696. }
  1697. }else if( typeOf(v) === "object" ){
  1698. if( v.distinguishedName ){
  1699. return v.distinguishedName.split("@").getLast().toUpperCase() === suffix;
  1700. }else{
  1701. return false;
  1702. }
  1703. }
  1704. return false;
  1705. }.bind(this));
  1706. return options;
  1707. },
  1708. selectOnLoad: function (selector) {
  1709. //if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  1710. this.fireEvent("loadSelector", [selector])
  1711. },
  1712. loadOrgWidget: function (value, node) {
  1713. var height = node.getStyle("height").toInt();
  1714. if (node.getStyle("overflow") === "visible" && !height) node.setStyle("overflow", "hidden");
  1715. if (value && value.length) {
  1716. value.each(function (data) {
  1717. if( typeOf(data) === "string" ){
  1718. data = { distinguishedName : data, name : o2.name.cn(data) };
  1719. }
  1720. var flag = data.distinguishedName.substr(data.distinguishedName.length - 1, 1);
  1721. var copyData = Object.clone(data);
  1722. if (this.json.displayTextScript && this.json.displayTextScript.code) {
  1723. this.currentData = copyData;
  1724. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  1725. if (displayName) {
  1726. copyData.displayName = displayName;
  1727. }
  1728. this.currentData = null;
  1729. }
  1730. var widget;
  1731. switch (flag.toLowerCase()) {
  1732. case "i":
  1733. widget = new MWF.widget.O2Identity(copyData, node, this.getOrgWidgetOption());
  1734. break;
  1735. case "p":
  1736. widget = new MWF.widget.O2Person(copyData, node, this.getOrgWidgetOption());
  1737. break;
  1738. case "u":
  1739. widget = new MWF.widget.O2Unit(copyData, node, this.getOrgWidgetOption());
  1740. break;
  1741. case "g":
  1742. widget = new MWF.widget.O2Group(copyData, node, this.getOrgWidgetOption());
  1743. break;
  1744. default:
  1745. widget = new MWF.widget.O2Other(copyData, node, this.getOrgWidgetOption());
  1746. }
  1747. widget.field = this;
  1748. widget.load();
  1749. }.bind(this));
  1750. }
  1751. },
  1752. getOrgWidgetOption: function(){
  1753. return {"style": "xform", "lazy": true, "delay":true}
  1754. },
  1755. hasEmpowerIdentity: function () {
  1756. var data = this.getData();
  1757. if (!this.empowerChecker){
  1758. this.empowerChecker = new MWF.ProcessFlow.Processor.EmpowerChecker(this);
  1759. }
  1760. return this.empowerChecker.hasEmpowerIdentity(data);
  1761. },
  1762. checkEmpower: function (data, callback, container) {
  1763. if (typeOf(data) === "array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity") {
  1764. if (!this.empowerChecker){
  1765. this.empowerChecker = new MWF.ProcessFlow.Processor.EmpowerChecker(this);
  1766. }
  1767. this.empowerChecker.load(data, callback, container);
  1768. } else {
  1769. if (callback) callback(data);
  1770. }
  1771. },
  1772. loadCheckEmpower: function (container, callback) {
  1773. this.checkEmpower(this.getData(), callback, container);
  1774. },
  1775. saveCheckedEmpowerData: function (callback) {
  1776. var data = this.getData();
  1777. var simple = this.json.storeRange === "simple";
  1778. //this.empowerChecker.replaceEmpowerIdentity(data, function( newData ){
  1779. this.empowerChecker.setIgnoreEmpowerFlag(data, function (newData) {
  1780. var values = [];
  1781. newData.each(function (d) {
  1782. values.push(MWF.org.parseOrgData(d, true, simple));
  1783. }.bind(this));
  1784. this.setData(values);
  1785. if (callback) callback(values);
  1786. }.bind(this))
  1787. },
  1788. save: function (isValid) {
  1789. if (isValid) {
  1790. if (this.validation()) {
  1791. return true;
  1792. } else {
  1793. this.processor.checkErrorHeightOverflow();
  1794. return false;
  1795. }
  1796. } else {
  1797. this.setData(this.getData());
  1798. return true;
  1799. }
  1800. },
  1801. resetSelectorData: function () {
  1802. if (this.selector && this.selector.selector) {
  1803. this.selector.selector.emptySelectedItems();
  1804. this.selector.selector.options.values = this.getValue() || [];
  1805. this.selector.selector.setSelectedItem();
  1806. }
  1807. },
  1808. setDataToOriginal: function () {
  1809. var v = this._computeValue();
  1810. this.setData(v || "");
  1811. },
  1812. resetData: function () {
  1813. var v = this.getValue() || [];
  1814. //this.setData((v) ? v.join(", ") : "");
  1815. this.setData(v);
  1816. },
  1817. getData: function () {
  1818. if (this.selector) {
  1819. return this.getSelectedData();
  1820. } else {
  1821. return this.getValue();
  1822. }
  1823. },
  1824. getSelectedData: function () {
  1825. var simple = this.json.storeRange === "simple";
  1826. var data = [];
  1827. if (this.selector && this.selector.selector) {
  1828. this.selector.selector.selectedItems.each(function (item) {
  1829. data.push(MWF.org.parseOrgData(item.data, true, simple));
  1830. })
  1831. }
  1832. return data;
  1833. },
  1834. getValue: function () {
  1835. var value = this._getBusinessData();
  1836. if (!value) value = this._computeValue();
  1837. return value || "";
  1838. },
  1839. _computeValue: function () {
  1840. var values = [];
  1841. if (this.json.identityValue) {
  1842. this.json.identityValue.each(function (v) {
  1843. if (v) values.push(v)
  1844. });
  1845. }
  1846. if (this.json.unitValue) {
  1847. this.json.unitValue.each(function (v) {
  1848. if (v) values.push(v)
  1849. });
  1850. }
  1851. // if (this.json.groupValue) {
  1852. // this.json.groupValue.each(function (v) {
  1853. // if (v) values.push(v)
  1854. // });
  1855. // }
  1856. if (this.json.dutyValue) {
  1857. var dutys = JSON.decode(this.json.dutyValue);
  1858. var par;
  1859. if (dutys.length) {
  1860. dutys.each(function (duty) {
  1861. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  1862. var code = "return this.org.getDuty(\"" + duty.name + "\", \"" + par + "\")";
  1863. var d = this.form.Macro.exec(code, this);
  1864. if (typeOf(d) !== "array") d = (d) ? [d.toString()] : [];
  1865. d.each(function (dd) {
  1866. if (dd) values.push(dd);
  1867. });
  1868. }.bind(this));
  1869. }
  1870. }
  1871. if (this.json.defaultValue && this.json.defaultValue.code) {
  1872. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  1873. if (typeOf(fd) !== "array") fd = (fd) ? [fd] : [];
  1874. fd.each(function (fdd) {
  1875. if (fdd) {
  1876. if (typeOf(fdd) === "string") {
  1877. var data;
  1878. this.getOrgAction()[this.getValueMethod(fdd)](function (json) {
  1879. data = json.data
  1880. }.bind(this), null, fdd, false);
  1881. values.push(data);
  1882. } else {
  1883. values.push(fdd);
  1884. }
  1885. }
  1886. }.bind(this));
  1887. }
  1888. if (this.json.count > 0) {
  1889. return values.slice(0, this.json.count);
  1890. }
  1891. return values;
  1892. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  1893. },
  1894. getOrgAction: function () {
  1895. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1896. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  1897. return this.orgAction;
  1898. },
  1899. setData: function (value) {
  1900. if (!value) return false;
  1901. var oldValues = this.getValue();
  1902. var values = [];
  1903. var simple = this.json.storeRange === "simple";
  1904. var type = typeOf(value);
  1905. if (type === "array") {
  1906. value.each(function (v) {
  1907. var vtype = typeOf(v);
  1908. var data = null;
  1909. if (vtype === "string") {
  1910. this.getOrgAction()[this.getValueMethod(v)](function (json) {
  1911. data = MWF.org.parseOrgData(json.data, true, simple);
  1912. }.bind(this), null, v, false);
  1913. }
  1914. if (vtype === "object") {
  1915. data = MWF.org.parseOrgData(v, true, simple);
  1916. if (data.woPerson) delete data.woPerson;
  1917. }
  1918. if (data) values.push(data);
  1919. }.bind(this));
  1920. }
  1921. if (type === "string") {
  1922. var vData;
  1923. this.getOrgAction()[this.getValueMethod(value)](function (json) {
  1924. vData = MWF.org.parseOrgData(json.data, true, simple);
  1925. }.bind(this), null, value, false);
  1926. if (vData) values.push(vData);
  1927. }
  1928. if (type === "object") {
  1929. var vData = MWF.org.parseOrgData(value, true, simple);
  1930. if (vData.woPerson) delete vData.woPerson;
  1931. values.push(vData);
  1932. }
  1933. var change = false;
  1934. if (oldValues.length && values.length) {
  1935. if (oldValues.length === values.length) {
  1936. for (var i = 0; i < oldValues.length; i++) {
  1937. if ((oldValues[i].distinguishedName !== values[i].distinguishedName) || (oldValues[i].name !== values[i].name) || (oldValues[i].unique !== values[i].unique)) {
  1938. change = true;
  1939. break;
  1940. }
  1941. }
  1942. } else {
  1943. change = true;
  1944. }
  1945. } else if (values.length || oldValues.length) {
  1946. change = true;
  1947. }
  1948. this._setBusinessData(values);
  1949. if (change) this.fireEvent("change");
  1950. },
  1951. getValueMethod: function (value) {
  1952. if (value) {
  1953. var flag = value.substr(value.length - 1, 1);
  1954. switch (flag.toLowerCase()) {
  1955. case "i":
  1956. return "getIdentity";
  1957. case "p":
  1958. return "getPerson";
  1959. case "u":
  1960. return "getUnit";
  1961. case "g":
  1962. return "getGroup";
  1963. default:
  1964. return (this.json.selectType === "unit") ? "getUnit" : "getIdentity";
  1965. }
  1966. }
  1967. return (this.json.selectType === "unit") ? "getUnit" : "getIdentity";
  1968. },
  1969. _getBusinessData: function () {
  1970. if (this.json.section == "yes") {
  1971. return this._getBusinessSectionData();
  1972. } else {
  1973. if (this.json.type === "Opinion") {
  1974. return this._getBusinessSectionDataByPerson();
  1975. } else {
  1976. return this.form.businessData.data[this.json.name] || "";
  1977. }
  1978. }
  1979. },
  1980. _getBusinessSectionData: function () {
  1981. switch (this.json.sectionBy) {
  1982. case "person":
  1983. return this._getBusinessSectionDataByPerson();
  1984. case "unit":
  1985. return this._getBusinessSectionDataByUnit();
  1986. case "activity":
  1987. return this._getBusinessSectionDataByActivity();
  1988. case "splitValue":
  1989. return this._getBusinessSectionDataBySplitValue();
  1990. case "script":
  1991. return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
  1992. default:
  1993. return this.form.businessData.data[this.json.name] || "";
  1994. }
  1995. },
  1996. _getBusinessSectionDataByPerson: function () {
  1997. this.form.sectionListObj[this.json.name] = layout.desktop.session.user.id;
  1998. var dataObj = this.form.businessData.data[this.json.name];
  1999. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  2000. },
  2001. _getBusinessSectionDataByUnit: function () {
  2002. this.form.sectionListObj[this.json.name] = "";
  2003. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  2004. if (key) this.form.sectionListObj[this.json.name] = key;
  2005. var dataObj = this.form.businessData.data[this.json.name];
  2006. if (!dataObj) return "";
  2007. return (key) ? (dataObj[key] || "") : "";
  2008. },
  2009. _getBusinessSectionDataByActivity: function () {
  2010. this.form.sectionListObj[this.json.name] = "";
  2011. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  2012. if (key) this.form.sectionListObj[this.json.name] = key;
  2013. var dataObj = this.form.businessData.data[this.json.name];
  2014. if (!dataObj) return "";
  2015. return (key) ? (dataObj[key] || "") : "";
  2016. },
  2017. _getBusinessSectionDataBySplitValue: function () {
  2018. this.form.sectionListObj[this.json.name] = "";
  2019. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  2020. if (key) this.form.sectionListObj[this.json.name] = key;
  2021. var dataObj = this.form.businessData.data[this.json.name];
  2022. if (!dataObj) return "";
  2023. return (key) ? (dataObj[key] || "") : "";
  2024. },
  2025. _getBusinessSectionDataByScript: function (code) {
  2026. this.form.sectionListObj[this.json.name] = "";
  2027. var dataObj = this.form.businessData.data[this.json.name];
  2028. if (!dataObj) return "";
  2029. var key = this.form.Macro.exec(code, this);
  2030. if (key) this.form.sectionListObj[this.json.name] = key;
  2031. return (key) ? (dataObj[key] || "") : "";
  2032. },
  2033. loadPathData: function (path) {
  2034. var data = null;
  2035. this.form.workAction.getJobDataByPath(this.form.businessData.work.job, path, function (json) {
  2036. data = json.data || null;
  2037. }, null, false);
  2038. return data;
  2039. },
  2040. _setBusinessData: function (v) {
  2041. if (this.json.section == "yes") {
  2042. // var d = this.loadPathData(this.json.name);
  2043. // if (d) this.form.businessData.data[this.json.name] = d;
  2044. this._setBusinessSectionData(v);
  2045. } else {
  2046. if (this.json.type === "Opinion") {
  2047. // var d = this.loadPathData(this.json.name);
  2048. // if (d) this.form.businessData.data[this.json.name] = d;
  2049. this._setBusinessSectionDataByPerson(v);
  2050. } else {
  2051. if (this.form.businessData.data[this.json.name]) {
  2052. this.form.businessData.data[this.json.name] = v;
  2053. } else {
  2054. this.form.businessData.data[this.json.name] = v;
  2055. this.form.Macro.environment.setData(this.form.businessData.data);
  2056. }
  2057. if (this.json.isTitle) this.form.businessData.work.title = v;
  2058. }
  2059. }
  2060. },
  2061. _setBusinessSectionData: function (v) {
  2062. switch (this.json.sectionBy) {
  2063. case "person":
  2064. this._setBusinessSectionDataByPerson(v);
  2065. break;
  2066. case "unit":
  2067. this._setBusinessSectionDataByUnit(v);
  2068. break;
  2069. case "activity":
  2070. this._setBusinessSectionDataByActivity(v);
  2071. break;
  2072. case "splitValue":
  2073. this._setBusinessSectionDataBySplitValue(v);
  2074. break;
  2075. case "script":
  2076. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  2077. break;
  2078. default:
  2079. if (this.form.businessData.data[this.json.name]) {
  2080. this.form.businessData.data[this.json.name] = v;
  2081. } else {
  2082. this.form.businessData.data[this.json.name] = v;
  2083. this.form.Macro.environment.setData(this.form.businessData.data);
  2084. }
  2085. }
  2086. },
  2087. _setBusinessSectionDataByPerson: function (v) {
  2088. var resetData = false;
  2089. var key = layout.desktop.session.user.id;
  2090. this.form.sectionListObj[this.json.name] = key;
  2091. var dataObj = this.form.businessData.data[this.json.name];
  2092. if (!dataObj) {
  2093. dataObj = {};
  2094. this.form.businessData.data[this.json.name] = dataObj;
  2095. resetData = true;
  2096. }
  2097. if (!dataObj[key]) resetData = true;
  2098. dataObj[key] = v;
  2099. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2100. },
  2101. _setBusinessSectionDataByUnit: function (v) {
  2102. var resetData = false;
  2103. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  2104. if (key) {
  2105. this.form.sectionListObj[this.json.name] = key;
  2106. var dataObj = this.form.businessData.data[this.json.name];
  2107. if (!dataObj) {
  2108. dataObj = {};
  2109. this.form.businessData.data[this.json.name] = dataObj;
  2110. resetData = true;
  2111. }
  2112. if (!dataObj[key]) resetData = true;
  2113. dataObj[key] = v;
  2114. }
  2115. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2116. },
  2117. _setBusinessSectionDataByActivity: function (v) {
  2118. var resetData = false;
  2119. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  2120. if (key) {
  2121. this.form.sectionListObj[this.json.name] = key;
  2122. var dataObj = this.form.businessData.data[this.json.name];
  2123. if (!dataObj) {
  2124. dataObj = {};
  2125. this.form.businessData.data[this.json.name] = dataObj;
  2126. resetData = true;
  2127. }
  2128. if (!dataObj[key]) resetData = true;
  2129. dataObj[key] = v;
  2130. }
  2131. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2132. },
  2133. _setBusinessSectionDataBySplitValue: function (v) {
  2134. var resetData = false;
  2135. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  2136. if (key) {
  2137. this.form.sectionListObj[this.json.name] = key;
  2138. var dataObj = this.form.businessData.data[this.json.name];
  2139. if (!dataObj) {
  2140. dataObj = {};
  2141. this.form.businessData.data[this.json.name] = dataObj;
  2142. resetData = true;
  2143. }
  2144. if (!dataObj[key]) resetData = true;
  2145. dataObj[key] = v;
  2146. }
  2147. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2148. },
  2149. _setBusinessSectionDataByScript: function (code, v) {
  2150. var resetData = false;
  2151. var key = this.form.Macro.exec(code, this);
  2152. if (key) {
  2153. this.form.sectionListObj[this.json.name] = key;
  2154. var dataObj = this.form.businessData.data[this.json.name];
  2155. if (!dataObj) {
  2156. dataObj = {};
  2157. this.form.businessData.data[this.json.name] = dataObj;
  2158. resetData = true;
  2159. }
  2160. if (!dataObj[key]) resetData = true;
  2161. dataObj[key] = v;
  2162. }
  2163. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2164. },
  2165. createErrorNode: function (text) {
  2166. var _self = this;
  2167. var node;
  2168. if (this.processor.css && this.processor.css.errorContentNode) {
  2169. node = new Element("div", {
  2170. "styles": this.processor.css.errorContentNode,
  2171. "text": text
  2172. });
  2173. if (this.processor.css.errorCloseNode) {
  2174. var closeNode = new Element("div", {
  2175. "styles": this.processor.css.errorCloseNode,
  2176. "events": {
  2177. "click": function () {
  2178. this.destroy();
  2179. if (_self.errorHeightOverflow) {
  2180. _self.errorHeightOverflow = false;
  2181. _self.processor.errorHeightChange();
  2182. }
  2183. }.bind(node)
  2184. }
  2185. }).inject(node);
  2186. }
  2187. } else {
  2188. node = new Element("div");
  2189. var iconNode = new Element("div", {
  2190. "styles": {
  2191. "width": "20px",
  2192. "height": "20px",
  2193. "float": "left",
  2194. "background": "url(" + "../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  2195. }
  2196. }).inject(node);
  2197. var textNode = new Element("div", {
  2198. "styles": {
  2199. "height": "auto",
  2200. "min-height": "20px",
  2201. "line-height": "20px",
  2202. "margin-left": "20px",
  2203. "color": "red",
  2204. "word-break": "break-all"
  2205. },
  2206. "text": text
  2207. }).inject(node);
  2208. }
  2209. return node;
  2210. },
  2211. notValidationMode: function (text) {
  2212. if (!this.isNotValidationMode) {
  2213. //this.isNotValidationMode = true;
  2214. //this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  2215. //this.node.setStyle("border-color", "red");
  2216. this.errNode = this.createErrorNode(text);
  2217. if (this.errContainer) {
  2218. this.errContainer.empty();
  2219. this.errNode.inject(this.errContainer);
  2220. } else {
  2221. this.errNode.inject(this.container, "after");
  2222. }
  2223. if (!this.errNode.isIntoView()) this.errNode.scrollIntoView(false);
  2224. var errorSize = this.errNode.getSize();
  2225. if (!layout.mobile && errorSize.y > 26) {
  2226. this.errorHeightOverflow = true;
  2227. }
  2228. }
  2229. },
  2230. needValid: function () {
  2231. return ((this.json.validationCount && typeOf(this.json.validationCount.toInt()) === "number") ||
  2232. (this.json.validation && this.json.validation.code));
  2233. },
  2234. validOnSelect: function () {
  2235. if (!this.errNode) return true;
  2236. var flag = true;
  2237. if (this.json.validationCount && typeOf(this.json.validationCount.toInt()) === "number") {
  2238. if (this.selector.selector.selectedItems.length < this.json.validationCount.toInt()) {
  2239. flag = MWF.xApplication.process.Xform.LP.selectItemCountNotice.replace("{count}", this.json.validationCount);
  2240. }
  2241. }
  2242. if (flag === true) {
  2243. if (this.json.validation && this.json.validation.code) {
  2244. var data = this.getData();
  2245. this.setData(data);
  2246. flag = this.form.Macro.exec(this.json.validation.code, this);
  2247. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2248. }
  2249. }
  2250. if (flag.toString() != "true") {
  2251. this.notValidationMode(flag);
  2252. this.processor.errorHeightChange();
  2253. return false;
  2254. } else if (this.errNode) {
  2255. this.errNode.destroy();
  2256. this.errNode = null;
  2257. if (this.errorHeightOverflow) {
  2258. this.errorHeightOverflow = false;
  2259. this.processor.errorHeightChange();
  2260. }
  2261. }
  2262. return true;
  2263. },
  2264. validation: function () {
  2265. var data = this.getData();
  2266. this.setData(data);
  2267. var flag = true;
  2268. if (this.json.validationCount && typeOf(this.json.validationCount.toInt()) === "number") {
  2269. if (data.length < this.json.validationCount.toInt()) {
  2270. //"请至少选择" + this.json.validationCount + "项"
  2271. flag = MWF.xApplication.process.Xform.LP.selectItemCountNotice.replace("{count}", this.json.validationCount);
  2272. }
  2273. }
  2274. if (flag === true) {
  2275. if (this.json.validation && this.json.validation.code) {
  2276. flag = this.form.Macro.exec(this.json.validation.code, this);
  2277. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2278. }
  2279. }
  2280. if (flag.toString() != "true") {
  2281. this.notValidationMode(flag);
  2282. return false;
  2283. } else if (this.errNode) {
  2284. this.errNode.destroy();
  2285. this.errNode = null;
  2286. }
  2287. return true;
  2288. }
  2289. });
  2290. MWF.ProcessFlow.Processor.EmpowerChecker = new Class({
  2291. initialize: function (org) {
  2292. this.org = org;
  2293. this.form = org.form;
  2294. this.json = org.json;
  2295. this.processor = org.processor;
  2296. this.flow = org.processor.flow;
  2297. },
  2298. load: function (data, callback, container) {
  2299. var p = this.getEmpowerData( data );
  2300. return Promise.resolve(p).then(function ( eArr ) {
  2301. if (eArr.length > 0) {
  2302. this.loadDom(eArr, data, container);
  2303. } else {
  2304. if (callback) callback(data);
  2305. }
  2306. }.bind(this));
  2307. },
  2308. loadDom: function(eArr, data, container){
  2309. var _self = this;
  2310. var titleNode = new Element("div.o2flow-empower-areaTitle").inject(container);
  2311. new Element("div.o2flow-empower-areaTitleText", { text: this.json.title }).inject(titleNode);
  2312. var selectAllNode = new Element("div.o2flow-empower-selectAllNode").inject( titleNode );
  2313. var contentNode = new Element("div.o2flow-empower-areaContent").inject(container);
  2314. this.selectAllRadio = new MWF.ProcessFlow.widget.Radio2(selectAllNode, this.flow, {
  2315. optionList: [{
  2316. value: "true", text: this.flow.lp.selectAll
  2317. }],
  2318. value: "true",
  2319. onCheck: function(el, value){
  2320. _self.empowerCheckbox.checkAll();
  2321. },
  2322. onUncheck: function(el, value){
  2323. _self.empowerCheckbox.uncheckAll();
  2324. },
  2325. });
  2326. this.selectAllRadio.load();
  2327. this.empowerCheckbox = new MWF.ProcessFlow.widget.Checkbox(contentNode, this.flow, {
  2328. optionList: eArr.map(function (e) {
  2329. return {
  2330. value: e.id,
  2331. text: e.fromIdentity.split("@")[0] + " " + this.flow.lp.empowerTo + " " + e.toIdentity.split("@")[0],
  2332. data: e
  2333. };
  2334. }.bind(this)),
  2335. values: eArr.map(function (e) {
  2336. return e.id;
  2337. })
  2338. });
  2339. this.empowerCheckbox.load();
  2340. },
  2341. hasEmpowerIdentity: function (data) {
  2342. var p = this.getEmpowerData( data );
  2343. return Promise.resolve(p).then(function ( arr ) {
  2344. return arr.length > 0;
  2345. });
  2346. },
  2347. isNeedCheck: function(data){
  2348. return typeOf(data) === "array" && this.json.isCheckEmpower && this.json.identityResultType === "identity";
  2349. },
  2350. getIdentityDn: function( data ){
  2351. return data.filter(function (d) {
  2352. return d.distinguishedName && d.distinguishedName.substr(d.distinguishedName.length - 1, 1).toLowerCase() === "i";
  2353. }).map(function (d) {
  2354. return d.distinguishedName;
  2355. });
  2356. },
  2357. getEmpowerData: function(data){
  2358. if( !this.isNeedCheck(data) )return [];
  2359. var array = this.getIdentityDn( data );
  2360. if( array.length < 1)return [];
  2361. return o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  2362. "application": (this.form.businessData.work || this.form.businessData.workCompleted).application,
  2363. "process": (this.form.businessData.work || this.form.businessData.workCompleted).process,
  2364. "work": (this.form.businessData.work || this.form.businessData.workCompleted).id,
  2365. "identityList": array
  2366. }, function (json) {
  2367. return json.data.filter(function (d) {
  2368. return d.fromIdentity !== d.toIdentity;
  2369. });
  2370. }.bind(this), function () {
  2371. return [];
  2372. })
  2373. },
  2374. getSelectedData: function (callback) {
  2375. var json = {};
  2376. this.empowerSelectNodes.each(function (node) {
  2377. if (node.retrieve("isSelected")) {
  2378. var d = node.retrieve("data");
  2379. json[d.fromIdentity] = d;
  2380. }
  2381. }.bind(this));
  2382. if (callback) callback(json);
  2383. },
  2384. setIgnoreEmpowerFlag : function(data, callback){
  2385. var ignoreList = this.empowerCheckbox.getUncheckData().map(function (d) {
  2386. return d.data.fromIdentity;
  2387. });
  2388. for( var i=0; i<data.length; i++ ){
  2389. var d = data[i];
  2390. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  2391. d.ignoreEmpower = true;
  2392. }else if( d.ignoreEmpower ){
  2393. delete d.ignoreEmpower;
  2394. }
  2395. }
  2396. if( callback )callback( data );
  2397. },
  2398. });
  2399. MWF.ProcessFlow.Processor.UnitOptions = new Class({
  2400. Extends: MWF.APPOrg.UnitOptions
  2401. });
  2402. MWF.ProcessFlow.Processor.IdentityOptions = new Class({
  2403. Extends: MWF.APPOrg.IdentityOptions
  2404. });
  2405. MWF.ProcessFlow.Processor.GroupOptions = new Class({
  2406. Extends: MWF.APPOrg.GroupOptions
  2407. });
  2408. MWF.ProcessFlow.widget = {};
  2409. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  2410. MWF.ProcessFlow.widget.QuickSelect = new Class({
  2411. Extends: MTooltips,
  2412. options: {
  2413. event : "click",
  2414. hasArrow : false,
  2415. hideByClickBody : true,
  2416. offset : {
  2417. x : 0,
  2418. y : 5
  2419. },
  2420. nodeStyles: {
  2421. "font-size" : "13px",
  2422. "position" : "absolute",
  2423. "max-width" : "500px",
  2424. "min-width" : "260px",
  2425. "z-index" : 20002,
  2426. "background-color" : "#fff",
  2427. "padding" : "10px 0px 10px 0px",
  2428. "border-radius" : "8px",
  2429. "box-shadow": "0px 0px 8px 0px rgba(0,0,0,0.25)",
  2430. "-webkit-user-select": "text",
  2431. "-moz-user-select": "text"
  2432. }
  2433. },
  2434. _loadCustom : function( callback ){
  2435. this.node.loadCss( this.flow.path + this.flow.options.style + "/style.css" );
  2436. var width = this.target.getSize().x ;
  2437. this.node.setStyles({
  2438. "max-width": width+"px",
  2439. "min-width": width+"px"
  2440. });
  2441. var work = this.flow.form.businessData.work;
  2442. var d = {
  2443. process: work.process,
  2444. activity: work.activity,
  2445. activityAlias: work.activityAlias,
  2446. activityName: work.activityName
  2447. };
  2448. // if( work.activityAlias ){
  2449. // d.activityAlias = work.activityAlias
  2450. // }else{
  2451. // d.activityName = work.activityName;
  2452. // }
  2453. var p = o2.Actions.load("x_processplatform_assemble_surface").TaskProcessModeAction.listMode( d );
  2454. Promise.resolve(p).then(function (json) {
  2455. debugger;
  2456. var list = this.filterData(json.data);
  2457. var data = list.map(function (d) {
  2458. return {
  2459. type: d.action,
  2460. text: this.getText( d ),
  2461. data: d
  2462. }
  2463. }.bind(this));
  2464. if( !data || !data.length ){
  2465. new Element("div.o2flow-quick-select-item", {
  2466. text: this.flow.lp.noQuickSelectDataNote
  2467. }).inject( this.contentNode );
  2468. }else{
  2469. this.loadItems(data)
  2470. }
  2471. //setTimeout( function () {
  2472. if(callback)callback( data );
  2473. //}, 50);
  2474. }.bind(this));
  2475. },
  2476. loadItems: function(data){
  2477. var _self = this;
  2478. data.each( function (d) {
  2479. var item = new Element("div.o2flow-quick-select-item", {
  2480. events: {
  2481. mouseover: function () {
  2482. this.addClass("o2flow-quick-select-item-active");
  2483. this.getFirst().addClass("o2flow-quick-select-item-contnet-active");
  2484. if( _self.flow.options.mainColorEnable ){
  2485. this.addClass("mainColor_bg");
  2486. this.getFirst().addClass("mainColor_bg");
  2487. }
  2488. },
  2489. mouseout: function () {
  2490. this.removeClass("o2flow-quick-select-item-active");
  2491. this.getFirst().removeClass("o2flow-quick-select-item-contnet-active");
  2492. if( _self.flow.options.mainColorEnable ) {
  2493. this.removeClass("mainColor_bg");
  2494. this.getFirst().removeClass("mainColor_bg");
  2495. }
  2496. },
  2497. click: function () {
  2498. var d = Object.clone( item.retrieve("data"));
  2499. _self.flow.changeAction( d.type, d.data );
  2500. _self.hide();
  2501. }
  2502. }
  2503. }).inject( this.contentNode );
  2504. item.store( "data", d );
  2505. var title = new Element("div.o2flow-quick-select-itemtitle", {
  2506. text: this.flow.lp.flowActions[d.type]
  2507. }).inject( item );
  2508. title.addClass( "o2flow-"+d.type+"-color" );
  2509. var content = new Element("div.o2flow-quick-select-itemtext", {
  2510. text: ":"+ d.text
  2511. }).inject( item )
  2512. }.bind(this))
  2513. },
  2514. filterData: function( data ){
  2515. //var onekeyList = listData();
  2516. return data.filter(function (d) {
  2517. var flag = (d.action === "process" && this.flow.processEnable) || (d.action === "reset" && this.flow.resetEnable) || (d.action === "addTask" && this.flow.addTaskEnable);
  2518. if( !flag )return false;
  2519. if( d.action === "process" && !this.flow.getRouteConfig(d.routeName) )return false;
  2520. return true;
  2521. }.bind(this));
  2522. },
  2523. getText: function( d ){
  2524. //选择[送办理],意见:请办理,处理人:张三、李四、张三、李四、张三、李四、张三、李四、张三、李四、张三、李四、张三、李四
  2525. //选择[前加签],意见:请处理,加签人:赵六
  2526. //保留待办,意见:请处理,重置给:王五
  2527. var text, orgtexts = [], lp = this.flow.lp;
  2528. switch (d.action) {
  2529. case "process":
  2530. Object.each( d.organizations, function (value, key) {
  2531. if( value && value.length ){
  2532. orgtexts.push( ( this.flow.getSingleOrgConfig( d.routeId , key ) ).title + ":" + value.clean().map(function(v){ return v.split("@")[0]; }).join("、"));
  2533. }
  2534. }.bind(this));
  2535. text = lp.submitQuickText.replace("{route}", d.routeName ).replace("{opinion}", d.opinion);
  2536. if( !orgtexts.length ){
  2537. return text.replace("{org}", "");
  2538. }else{
  2539. return text.replace("{org}", "," + orgtexts.join(",") );
  2540. }
  2541. case "addTask":
  2542. if( d.organizations && d.organizations.default ){
  2543. orgtexts.push( d.organizations.default.clean().map(function(v){ return v.split("@")[0]; }).join("、") );
  2544. }
  2545. var route = d.routeId === "before" ? lp.addTaskBefore : lp.addTaskAfter;
  2546. var mode = lp[ d.routeGroup ] || "";
  2547. return lp.addTaskQuickText.replace("{route}", route ).replace("{mode}", mode).replace("{opinion}", d.opinion).replace("{org}", orgtexts.join(",") );
  2548. case "reset":
  2549. if( d.organizations && d.organizations.default ){
  2550. orgtexts.push( d.organizations.default.clean().map(function(v){ return v.split("@")[0]; }).join("、") );
  2551. }
  2552. return lp.resetQuickText.replace("{opinion}", d.opinion).replace("{org}", orgtexts.join(",") );
  2553. //return lp.resetQuickText.replace("{flag}", d.keepTask ? "" : lp.not ).replace("{opinion}", d.opinion).replace("{org}", orgtexts.join(",") );
  2554. }
  2555. },
  2556. saveData: function () {
  2557. debugger;
  2558. var work = this.flow.form.businessData.work || this.flow.form.businessData.workCompleted;
  2559. var d = {
  2560. process: work.process,
  2561. processName: work.processName,
  2562. activity: work.activity,
  2563. activityName: work.activityName,
  2564. activityAlias: work.activityAlias,
  2565. action: this.flow.currentAction
  2566. };
  2567. // routeId: "",
  2568. // routeName: "",
  2569. // routeGroup:决策组.
  2570. // keepTask:是否保留待办.
  2571. // opinion:意见.
  2572. // organizations:人员组织列表.
  2573. var quickData = {};
  2574. switch ( this.flow.currentAction ) {
  2575. case "process":
  2576. quickData = this.flow.processor.getQuickData();
  2577. break;
  2578. case "addTask":
  2579. quickData = this.flow.addTask.getQuickData();
  2580. break;
  2581. case "reset":
  2582. quickData = this.flow.reset.getQuickData();
  2583. break;
  2584. }
  2585. d = Object.merge(d, quickData);
  2586. o2.Actions.load("x_processplatform_assemble_surface").TaskProcessModeAction.saveMode( d, null, null, false );
  2587. },
  2588. });
  2589. MWF.ProcessFlow.widget.Opinion = new Class({
  2590. Implements: [Options, Events],
  2591. options: {
  2592. isHandwriting: false,
  2593. opinion: "",
  2594. tabletToolHidden: [],
  2595. tabletWidth: 0,
  2596. tabletHeight: 0
  2597. },
  2598. initialize: function( container, flow, options ){
  2599. this.setOptions( options );
  2600. this.container = container;
  2601. this.flow = flow;
  2602. this.lp = flow.lp;
  2603. },
  2604. load: function(){
  2605. this.loadData( function () {
  2606. this.loadDom();
  2607. }.bind(this));
  2608. },
  2609. loadData: function ( callback ) {
  2610. MWF.require("MWF.widget.UUID", function () {
  2611. MWF.UD.getDataJson("idea", function (json) {
  2612. if (json) {
  2613. if (json.ideas) {
  2614. this.opinionList = json.ideas;
  2615. if(callback)callback();
  2616. }else{
  2617. this.opinionList = [];
  2618. if(callback)callback();
  2619. }
  2620. } else {
  2621. MWF.UD.getPublicData("idea", function (pjson) {
  2622. if (pjson && pjson.ideas) {
  2623. this.opinionList = pjson.ideas;
  2624. if(callback)callback();
  2625. }else{
  2626. this.opinionList = [];
  2627. if(callback)callback();
  2628. }
  2629. }.bind(this));
  2630. }
  2631. }.bind(this));
  2632. }.bind(this));
  2633. },
  2634. loadDom: function(){
  2635. var url = this.flow.path+this.flow.options.style+"/widget/opinion.html";
  2636. this.container.loadHtml(url, {
  2637. "bind": {
  2638. "lp": this.lp, "opinionList": this.opinionList, "opinion": this.options.opinion || ""
  2639. },
  2640. "module": this
  2641. }, function(){
  2642. if( this.options.isHandwriting )this.handwritingButton.show();
  2643. this.opinionTextarea.addEvent("change", function () {
  2644. this.removeRequireStyle();
  2645. }.bind(this));
  2646. this.loaded = true;
  2647. this.fireEvent("load");
  2648. }.bind(this)
  2649. );
  2650. },
  2651. setRequireStyle: function(){
  2652. this.opinionTextarea.addClass("o2flow-invalid-bg");
  2653. },
  2654. removeRequireStyle: function(){
  2655. if(this.opinionTextarea.hasClass("o2flow-invalid-bg")){
  2656. this.opinionTextarea.removeClass("o2flow-invalid-bg");
  2657. }
  2658. },
  2659. getValue: function(){
  2660. return this.opinionTextarea.get("value");
  2661. },
  2662. setValue: function( value ){
  2663. this.opinionTextarea.set("value", value);
  2664. },
  2665. selectOpinion: function( opinion ){
  2666. var op = this.opinionTextarea.get("value");
  2667. if ( !op ) {
  2668. this.opinionTextarea.set("value", opinion );
  2669. } else {
  2670. this.opinionTextarea.set("value", op + ", " + opinion );
  2671. }
  2672. this.removeRequireStyle();
  2673. },
  2674. overItemNode: function (ev) {
  2675. ev.target.addClass("o2flow-bg-opacity");
  2676. if( this.flow.options.mainColorEnable ){
  2677. ev.target.addClass("mainColor_bg_opacity");
  2678. }
  2679. },
  2680. outItemNode: function (ev) {
  2681. ev.target.removeClass("o2flow-bg-opacity");
  2682. if( this.flow.options.mainColorEnable ) {
  2683. ev.target.removeClass("mainColor_bg_opacity");
  2684. }
  2685. },
  2686. handwriting: function () {
  2687. if( !this.tablet )this.createHandwriting();
  2688. this.handwritingMask.show();
  2689. this.handwritingNode.show();
  2690. this.handwritingNode.position({
  2691. "relativeTo": this.flow.node,
  2692. "position": "center",
  2693. "edge": "center"
  2694. });
  2695. },
  2696. createHandwriting: function () {
  2697. this.handwritingMask.inject( this.flow.node );
  2698. this.handwritingNode.show().inject(this.flow.node, "after");
  2699. //兼容以前的默认高宽
  2700. var x = 600;
  2701. var y = 320;
  2702. x = Math.max(this.options.tabletWidth || x, 600);
  2703. this.options.tabletWidth = x;
  2704. y = Math.max(this.options.tabletHeight ? (parseInt(this.options.tabletHeight) + 110) : y, 320);
  2705. var zidx = this.flow.node.getStyle("z-index");
  2706. this.handwritingNode.setStyles({
  2707. "height": "" + y + "px",
  2708. "width": "" + x + "px",
  2709. "z-index": zidx + 1
  2710. });
  2711. this.handwritingNode.position({
  2712. "relativeTo": this.flow.node,
  2713. "position": "center",
  2714. "edge": "center"
  2715. });
  2716. if( this.flow.options.mainColorEnable )this.handwritingSaveNode.addClass("mainColor_bg");
  2717. var h = this.handwritingSaveNode.getSize().y + this.flow.getOffsetY(this.handwritingSaveNode);
  2718. this.handwritingAreaNode.setStyle("height", "" + ( y - h ) + "px");
  2719. MWF.require("MWF.widget.Tablet", function () {
  2720. var handWritingOptions = this.getHandWritingOptions();
  2721. this.tablet = new MWF.widget.Tablet(this.handwritingAreaNode, handWritingOptions, null);
  2722. this.tablet.load();
  2723. }.bind(this));
  2724. },
  2725. getHandWritingOptions: function(){
  2726. return {
  2727. "style": "default",
  2728. "toolHidden": this.options.tabletToolHidden || [],
  2729. "contentWidth": this.options.tabletWidth || 0,
  2730. "contentHeight": this.options.tabletHeight || 0,
  2731. "iconfontEnable": true,
  2732. "mainColorEnable": this.flow.options.mainColorEnable,
  2733. "onSave": function (base64code, base64Image, imageFile) {
  2734. if( !this.tablet.isBlank() ){
  2735. this.handwritingFile = imageFile;
  2736. this.handwritingButton.getElement("i").removeClass("o2icon-edit2").
  2737. addClass("o2icon-checkbox").addClass("o2flow-handwriting-buttonok");
  2738. this.removeRequireStyle();
  2739. }else{
  2740. this.handwritingFile = null;
  2741. this.handwritingButton.getElement("i").addClass("o2icon-edit2").
  2742. removeClass("o2icon-checkbox").removeClass("o2flow-handwriting-buttonok");
  2743. }
  2744. this.handwritingNode.hide();
  2745. this.handwritingMask.hide();
  2746. }.bind(this),
  2747. "onCancel": function () {
  2748. this.handwritingFile = null;
  2749. this.handwritingButton.getElement("i").addClass("o2icon-edit2").
  2750. removeClass("o2icon-checkbox").removeClass("o2flow-handwriting-buttonok");
  2751. this.handwritingNode.hide();
  2752. this.handwritingMask.hide();
  2753. }.bind(this)
  2754. };
  2755. },
  2756. saveTablet: function () {
  2757. if (this.tablet) this.tablet.save();
  2758. }
  2759. });
  2760. MWF.ProcessFlow.widget.Radio = new Class({
  2761. Implements: [Options, Events],
  2762. options: {
  2763. optionList: [],
  2764. value: null,
  2765. cancelEnable: true
  2766. },
  2767. initialize: function( container, flow, options ){
  2768. this.container = container;
  2769. this.flow = flow;
  2770. this.lp = flow.lp;
  2771. this.setOptions( options );
  2772. },
  2773. load: function(){
  2774. this.checkedItems = [];
  2775. this.container.loadHtml(this.getUrl(), {"bind": {"lp": this.lp, "optionList": this.options.optionList}, "module": this}, function(){
  2776. if( this.options.value !== null )this.setValue( this.options.value );
  2777. this.fireEvent("load");
  2778. }.bind(this));
  2779. },
  2780. getUrl: function(){
  2781. return this.flow.path+this.flow.options.style+"/widget/radio.html";
  2782. },
  2783. setValue: function( values ){
  2784. while( this.checkedItems.length ){
  2785. this.uncheck( this.checkedItems[0] );
  2786. }
  2787. if( typeOf( values ) === "null" )return;
  2788. values = typeOf( values ) === "array" ? values : [values];
  2789. this.container.getElements(".o2flow-radio").each(function (el) {
  2790. if(values.contains( el.dataset["o2Value"] )){
  2791. this.check(el)
  2792. }
  2793. }.bind(this))
  2794. },
  2795. getData: function( value ){
  2796. if( !value )value = this.getValue();
  2797. var arr = this.options.optionList.filter(function (o) {
  2798. return o.value === value;
  2799. });
  2800. return arr[0] || null;
  2801. },
  2802. getValue: function(){
  2803. var data = this.checkedItems.map(function (item) {
  2804. return item.dataset["o2Value"];
  2805. });
  2806. return data[0] || null;
  2807. },
  2808. getText: function(){
  2809. var data = this.checkedItems.map(function (item) {
  2810. return item.dataset["o2Text"];
  2811. });
  2812. return data[0] || null;
  2813. },
  2814. toggle: function( ev ){
  2815. var el = this.flow.getEl(ev, "o2flow-radio");
  2816. if( this.checkedItems.contains( el ) ){
  2817. if( this.options.cancelEnable )this.uncheck( el, true )
  2818. }else{
  2819. this.check( el )
  2820. }
  2821. },
  2822. check: function(el){
  2823. while( this.checkedItems.length ){
  2824. this.uncheck( this.checkedItems[0] );
  2825. }
  2826. el.addClass("o2flow-radio-active");
  2827. if( this.flow.options.mainColorEnable )el.addClass("mainColor_bg");
  2828. el.getElement("i").removeClass("o2icon-icon_circle").addClass("o2icon-checkbox").addClass("o2flow-radio-icon");
  2829. el.dataset["o2Checked"] = true;
  2830. this.checkedItems.push(el);
  2831. this.removeRequireStyle();
  2832. this.fireEvent("check", [el, el.dataset["o2Value"]])
  2833. },
  2834. uncheck: function(el, isFire){
  2835. el.removeClass("o2flow-radio-active");
  2836. if( this.flow.options.mainColorEnable )el.removeClass("mainColor_bg");
  2837. el.getElement("i").removeClass("o2icon-checkbox").addClass("o2icon-icon_circle").removeClass("o2flow-radio-icon");
  2838. el.dataset["o2Checked"] = false;
  2839. this.checkedItems.erase(el);
  2840. if(isFire)this.fireEvent("uncheck", [el, el.dataset["o2Value"]])
  2841. },
  2842. setRequireStyle: function(){
  2843. this.container.addClass("o2flow-invalid-bg");
  2844. },
  2845. removeRequireStyle: function(){
  2846. if(this.container.hasClass("o2flow-invalid-bg")){
  2847. this.container.removeClass("o2flow-invalid-bg");
  2848. }
  2849. },
  2850. // over: function (ev) {
  2851. // var el = this.flow.getEl(ev, "o2flow-radio");
  2852. // if( !el.dataset["o2Checked"] ){
  2853. // el.getElement("i").addClass("o2flow-radio-over");
  2854. // }
  2855. // },
  2856. // out: function (ev) {
  2857. // var el = this.flow.getEl(ev, "o2flow-radio");
  2858. // el.getElement("i").removeClass("o2flow-radio-over")
  2859. // }
  2860. });
  2861. MWF.ProcessFlow.widget.Radio2 = new Class({
  2862. Extends: MWF.ProcessFlow.widget.Radio,
  2863. options: {
  2864. optionList: [],
  2865. value: null,
  2866. cancelEnable: true,
  2867. activeIcon: "o2icon-radio-checked"
  2868. },
  2869. getUrl: function(){
  2870. return this.flow.path+this.flow.options.style+"/widget/radio2.html";
  2871. },
  2872. setValue: function( values ){
  2873. while( this.checkedItems.length ){
  2874. this.uncheck( this.checkedItems[0] );
  2875. }
  2876. values = typeOf( values ) === "array" ? values : [values];
  2877. this.container.getElements(".o2flow-radio2").each(function (el) {
  2878. if(values.contains( el.dataset["o2Value"] ))this.check(el)
  2879. }.bind(this))
  2880. },
  2881. toggle: function( ev ){
  2882. var el = this.flow.getEl(ev, "o2flow-radio2");
  2883. if( this.checkedItems.contains( el ) ){
  2884. if( this.options.cancelEnable )this.uncheck( el, true )
  2885. }else{
  2886. this.check( el )
  2887. }
  2888. },
  2889. check: function(el){
  2890. while( this.checkedItems.length ){
  2891. this.uncheck( this.checkedItems[0] );
  2892. }
  2893. el.addClass("o2flow-radio2-active");
  2894. if( this.flow.options.mainColorEnable )el.addClass("mainColor_color");
  2895. el.getElement("i").removeClass("o2icon-icon_circle").addClass(this.options.activeIcon).addClass("o2flow-radio2-icon");
  2896. if( this.flow.options.mainColorEnable )el.getElement("i").addClass("mainColor_color");
  2897. el.dataset["o2Checked"] = true;
  2898. this.checkedItems.push(el);
  2899. this.removeRequireStyle();
  2900. this.fireEvent("check", [el, el.dataset["o2Value"]])
  2901. },
  2902. uncheck: function(el, isFire){
  2903. el.removeClass("o2flow-radio2-active");
  2904. if( this.flow.options.mainColorEnable )el.removeClass("mainColor_color");
  2905. el.getElement("i").removeClass(this.options.activeIcon).addClass("o2icon-icon_circle").removeClass("o2flow-radio2-icon");
  2906. if( this.flow.options.mainColorEnable )el.getElement("i").removeClass("mainColor_color");
  2907. el.dataset["o2Checked"] = false;
  2908. this.checkedItems.erase(el);
  2909. if(isFire)this.fireEvent("uncheck", [el, el.dataset["o2Value"]])
  2910. }
  2911. });
  2912. MWF.ProcessFlow.widget.Checkbox = new Class({
  2913. Implements: [Options, Events],
  2914. options: {
  2915. optionList: [],
  2916. values: []
  2917. },
  2918. initialize: function( container, flow, options ){
  2919. this.container = container;
  2920. this.flow = flow;
  2921. this.lp = flow.lp;
  2922. this.setOptions( options );
  2923. },
  2924. load: function(){
  2925. this.checkedItems = [];
  2926. this.container.loadHtml(this.getUrl(), {"bind": {"lp": this.lp, "optionList": this.options.optionList}, "module": this}, function(){
  2927. if( this.options.values.length )this.setValue( this.options.values );
  2928. this.fireEvent("load");
  2929. }.bind(this));
  2930. },
  2931. getUrl: function(){
  2932. return this.flow.path+this.flow.options.style+"/widget/checkbox.html";
  2933. },
  2934. setValue: function( values ){
  2935. while( this.checkedItems.length ){
  2936. this.uncheck( this.checkedItems[0] );
  2937. }
  2938. values = typeOf( values ) === "array" ? values : [values];
  2939. this.container.getElements(".o2flow-radio").each(function (el) {
  2940. if(values.contains( el.dataset["o2Value"] )){
  2941. this.check(el)
  2942. }
  2943. }.bind(this))
  2944. },
  2945. getData: function( value ){
  2946. if( !value )value = this.getValue();
  2947. value = typeOf( value ) === "array" ? value : [value];
  2948. var arr = this.options.optionList.filter(function (o) {
  2949. return value.contains(o.value);
  2950. });
  2951. return arr;
  2952. },
  2953. getValue: function(){
  2954. return this.checkedItems.map(function (item) {
  2955. return item.dataset["o2Value"];
  2956. });
  2957. },
  2958. getText: function(){
  2959. return this.checkedItems.map(function (item) {
  2960. return item.dataset["o2Text"];
  2961. });
  2962. },
  2963. toggle: function( ev ){
  2964. var el = this.flow.getEl(ev, "o2flow-radio");
  2965. if( this.checkedItems.contains( el ) ){
  2966. this.uncheck( el, true )
  2967. }else{
  2968. this.check( el )
  2969. }
  2970. },
  2971. check: function(el){
  2972. el.addClass("o2flow-radio-active");
  2973. if( this.flow.options.mainColorEnable )el.addClass("mainColor_bg");
  2974. el.getElement("i").removeClass("o2icon-icon_circle").addClass("o2icon-checkbox").addClass("o2flow-radio-icon");
  2975. el.dataset["o2Checked"] = true;
  2976. this.checkedItems.push(el);
  2977. this.removeRequireStyle();
  2978. this.fireEvent("check", [el, el.dataset["o2Value"]])
  2979. },
  2980. uncheck: function(el, isFire){
  2981. el.removeClass("o2flow-radio-active");
  2982. if( this.flow.options.mainColorEnable )el.removeClass("mainColor_bg");
  2983. el.getElement("i").removeClass("o2icon-checkbox").addClass("o2icon-icon_circle").removeClass("o2flow-radio-icon");
  2984. el.dataset["o2Checked"] = false;
  2985. this.checkedItems.erase(el);
  2986. if(isFire)this.fireEvent("uncheck", [el, el.dataset["o2Value"]])
  2987. },
  2988. checkAll: function(){
  2989. this.container.getElements(".o2flow-radio").each(function (el) {
  2990. this.check(el)
  2991. }.bind(this))
  2992. },
  2993. uncheckAll: function(){
  2994. this.container.getElements(".o2flow-radio").each(function (el) {
  2995. this.uncheck(el)
  2996. }.bind(this))
  2997. },
  2998. getUncheckData: function(){
  2999. var value = this.getValue();
  3000. return this.options.optionList.filter(function (o) {
  3001. return !value.contains(o.value);
  3002. });
  3003. },
  3004. setRequireStyle: function(){
  3005. this.container.addClass("o2flow-invalid-bg");
  3006. },
  3007. removeRequireStyle: function(){
  3008. if(this.container.hasClass("o2flow-invalid-bg")){
  3009. this.container.removeClass("o2flow-invalid-bg");
  3010. }
  3011. }
  3012. });