Flow.js 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158
  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.form.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. var visibleRouteConfigList = routeConfigList.filter(function(route){
  974. if ( route.hiddenScriptText ) {
  975. return this.form.Macro.exec(route.hiddenScriptText, this).toString() !== "true";
  976. }
  977. return true;
  978. }.bind(this));
  979. visibleRouteConfigList.each(function (route, i) {
  980. var routeName = route.name;
  981. if (route.displayNameScriptText && this.form && this.form.Macro) {
  982. routeName = this.form.Macro.exec(route.displayNameScriptText, this);
  983. }
  984. optionList.push({
  985. value: route.id,
  986. text: routeName,
  987. data: route
  988. });
  989. if( route.id === this.options.defaultRoute || route.name === this.options.defaultRoute) {
  990. defaultRoute = route.id;
  991. this.options.defaultRoute = "";
  992. isSelectedDefault = true;
  993. }else if ( !isSelectedDefault && (visibleRouteConfigList.length === 1 || route.sole )) { //sole表示优先路由
  994. defaultRoute = route.id;
  995. }
  996. }.bind(this));
  997. this.routeRadio = new MWF.ProcessFlow.widget.Radio(this.routeArea, this.flow, {
  998. optionList: optionList,
  999. onCheck: function(el, value){
  1000. var routeConfig = this.getData().data;
  1001. var checkOpinion = function(){
  1002. var op = _self.opinion.getValue();
  1003. if( op === (_self.lastDefaultOpinion || "") || op === "" ){
  1004. _self.lastDefaultOpinion = routeConfig.opinion || "";
  1005. _self.opinion.setValue( _self.lastDefaultOpinion );
  1006. }
  1007. };
  1008. if( _self.opinion.loaded ){
  1009. checkOpinion()
  1010. }else{
  1011. _self.opinion.addEvent("load", checkOpinion);
  1012. }
  1013. _self.loadOrgs( routeConfig );
  1014. },
  1015. onUncheck: function(el, value){
  1016. var routeConfig = this.getData( value ).data;
  1017. var op = _self.opinion.getValue();
  1018. if (op === (routeConfig.opinion || "") || op === "" ) {
  1019. _self.lastDefaultOpinion = "";
  1020. _self.opinion.setValue("");
  1021. }
  1022. _self.loadOrgs();
  1023. },
  1024. onLoad: function(){
  1025. if( defaultRoute ){
  1026. this.setValue( defaultRoute );
  1027. }else{
  1028. _self.loadOrgs();
  1029. }
  1030. }
  1031. });
  1032. this.routeRadio.load();
  1033. },
  1034. loadOrgs: function( routeConfig ){
  1035. for( var r in this.routeOrgMap ){
  1036. this.routeOrgMap[r].hide();
  1037. }
  1038. var notFireResize = !this.loadEventFired;
  1039. if( routeConfig ){
  1040. var routeId = routeConfig.id;
  1041. var orgList = this.routeOrgMap[routeId];
  1042. if( orgList ){
  1043. orgList.load( notFireResize );
  1044. }else{
  1045. orgList = new MWF.ProcessFlow.Processor.OrgList(this, {
  1046. routeId: routeId
  1047. });
  1048. this.routeOrgMap[routeId] = orgList;
  1049. orgList.load( notFireResize );
  1050. }
  1051. this.currentOrgList = orgList;
  1052. }else{
  1053. this.orgsWraper.hide();
  1054. //this.setSize(0);
  1055. if( !notFireResize )this.flow.resize();
  1056. this.currentOrgList = null;
  1057. }
  1058. this.checkLoadEvent();
  1059. },
  1060. cancel: function(){
  1061. this.destroy();
  1062. this.fireEvent("cancel");
  1063. },
  1064. submit: function (ev) {
  1065. if (this.hasRouteGroup && !this.routeGroupRadio.getValue() ) {
  1066. this.routeGroupRadio.setRequireStyle();
  1067. this.flow.noticeError(
  1068. MWF.xApplication.process.Work.LP.mustSelectRouteGroup,
  1069. this.routeGroupArea,
  1070. null,
  1071. {"x": "center", "y": "top"}
  1072. );
  1073. return false;
  1074. }
  1075. if (!this.routeRadio.getValue()) {
  1076. this.routeRadio.setRequireStyle();
  1077. this.flow.noticeError(
  1078. MWF.xApplication.process.Work.LP.mustSelectRoute,
  1079. this.routeArea,
  1080. null, //{"x": 0, "y": 30}
  1081. {"x": "center", "y": "top"}
  1082. );
  1083. return false;
  1084. }
  1085. var routeName = this.routeRadio.getData().data.name;
  1086. var opinion = this.opinion.getValue();
  1087. var medias = [];
  1088. if (this.opinion.handwritingFile) medias.push(this.opinion.handwritingFile);
  1089. var currentRouteId = this.routeRadio.getValue();
  1090. var routeConfig = this.getRouteConfig(currentRouteId);
  1091. if (!opinion && medias.length === 0) {
  1092. if (routeConfig.opinionRequired === true) {
  1093. this.opinion.setRequireStyle();
  1094. this.flow.noticeError(
  1095. MWF.xApplication.process.Work.LP.opinionRequired,
  1096. this.opinion.opinionTextarea,
  1097. null,
  1098. {"x": "center", "y": "top"}
  1099. );
  1100. return false;
  1101. }
  1102. }
  1103. var orgItems = this.currentOrgList ? this.currentOrgList.orgVisableItems : [];
  1104. var appendTaskOrgItem = "";
  1105. if (routeConfig.type === "appendTask" && routeConfig.appendTaskIdentityType === "select") {
  1106. if (!orgItems || orgItems.length === 0) {
  1107. this.flow.noticeError(
  1108. MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig,
  1109. this.node,
  1110. null
  1111. );
  1112. return false;
  1113. } else {
  1114. appendTaskOrgItem = orgItems[0];
  1115. }
  1116. }
  1117. this.currentOrgList.saveOrgsWithCheckEmpower(function () {
  1118. var appandTaskIdentityList;
  1119. if (appendTaskOrgItem) {
  1120. appandTaskIdentityList = appendTaskOrgItem.getData();
  1121. if (!appandTaskIdentityList || appandTaskIdentityList.length === 0) {
  1122. this.flow.noticeError(
  1123. MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice,
  1124. this.node
  1125. );
  1126. return;
  1127. }
  1128. }
  1129. if (routeConfig.validationScriptText) {
  1130. var validation = this.form.Macro.exec(routeConfig.validationScriptText, this);
  1131. if (!validation || validation.toString() !== "true") {
  1132. if (typeOf(validation) === "string") {
  1133. this.flow.noticeError( validation, this.node );
  1134. return false;
  1135. } else {
  1136. //"路由校验失败"
  1137. this.flow.noticeError(
  1138. MWF.xApplication.process.Work.LP.routeValidFailure,
  1139. this.node
  1140. );
  1141. return false;
  1142. }
  1143. }
  1144. }
  1145. this.node.mask({
  1146. "inject": {"where": "bottom", "target": this.node},
  1147. "destroyOnHide": true,
  1148. "style": {
  1149. "background-color": "#999",
  1150. "opacity": 0.3,
  1151. "z-index": this.flow.options.zIndex+1
  1152. }
  1153. });
  1154. var array = [routeName, opinion, medias, appandTaskIdentityList, orgItems, function () {
  1155. if (appendTaskOrgItem) appendTaskOrgItem.setData([]);
  1156. }];
  1157. this.flow.quickSelector.saveData();
  1158. this.fireEvent("submit", array);
  1159. }.bind(this));
  1160. },
  1161. getQuickData: function(){
  1162. var organizations = {};
  1163. var orgItems = this.currentOrgList ? this.currentOrgList.orgVisableItems : [];
  1164. orgItems.each(function (org) {
  1165. var vs = org.getValue();
  1166. organizations[org.json.name] = vs.map(function (o) {
  1167. return typeOf(o) === "string" ? o : o.distinguishedName;
  1168. })
  1169. });
  1170. var route = this.routeRadio.getData().data;
  1171. return {
  1172. routeGroup: this.routeGroupRadio ? this.routeGroupRadio.getValue() : "",
  1173. routeId: route.id,
  1174. routeName: route.name,
  1175. opinion: this.opinion.getValue(),
  1176. organizations: organizations
  1177. }
  1178. },
  1179. destroy: function () {
  1180. Object.values( this.routeOrgMap ).each(function (orgList) {
  1181. Object.values( orgList.orgMap ).each(function( org ){
  1182. if(org.clearTooltip)org.clearTooltip();
  1183. });
  1184. });
  1185. },
  1186. getRouteGroupConfig: function () {
  1187. var config = this.flow.getRouteGroupConfig();
  1188. this.routeGroupObject = this.flow.routeGroupObject;
  1189. this.routeGroupNameList = this.flow.routeGroupNameList;
  1190. this.hasRouteGroup = this.flow.hasRouteGroup;
  1191. return config;
  1192. },
  1193. getRouteConfigList: function () {
  1194. return this.flow.getRouteConfigList();
  1195. },
  1196. getRouteConfig: function (routeId) {
  1197. return this.flow.getRouteConfig( routeId );
  1198. },
  1199. getOrgConfig: function (routeId) {
  1200. return this.flow.getOrgConfig( routeId );
  1201. },
  1202. getVisableOrgConfig: function (routeId) {
  1203. return this.flow.getVisableOrgConfig(routeId);
  1204. },
  1205. isOrgHidden: function (d) {
  1206. return this.flow.isOrgHidden(d);
  1207. },
  1208. getMaxOrgLength: function () {
  1209. return this.flow.getMaxOrgLength();
  1210. },
  1211. getOffsetY: function (node) {
  1212. return (node.getStyle("margin-top").toInt() || 0) +
  1213. (node.getStyle("margin-bottom").toInt() || 0) +
  1214. (node.getStyle("padding-top").toInt() || 0) +
  1215. (node.getStyle("padding-bottom").toInt() || 0) +
  1216. (node.getStyle("border-top-width").toInt() || 0) +
  1217. (node.getStyle("border-bottom-width").toInt() || 0);
  1218. },
  1219. // setSize: function (currentOrgLength, flag) {
  1220. // this.flow.resize()
  1221. // return;
  1222. // }
  1223. });
  1224. MWF.xDesktop.requireApp("process.Xform", "Org", null, false);
  1225. MWF.ProcessFlow.Processor.OrgList = new Class({
  1226. Implements: [Options, Events],
  1227. options: {
  1228. routeId: ""
  1229. },
  1230. initialize: function (processor, options) {
  1231. this.processor = processor;
  1232. this.form = processor.form;
  1233. this.flow = processor.flow;
  1234. this.businessData = this.form.businessData;
  1235. this.wraper = processor.orgsWraper;
  1236. this.container = processor.orgsArea;
  1237. this.node = new Element("div").inject( processor.orgsArea );
  1238. this.setOptions(options);
  1239. this.orgs = [];
  1240. this.orgMap = {};
  1241. this.domMap = {};
  1242. },
  1243. load: function ( notFireResize ) {
  1244. this.orgVisableItems = [];
  1245. var configVisable = this.getVisableOrgConfig();
  1246. if (configVisable.length) {
  1247. this.wraper.show();
  1248. this.node.show();
  1249. this.loadOrgs();
  1250. //this.processor.setSize(configVisable.length);
  1251. if(!notFireResize)this.flow.resize();
  1252. } else {
  1253. this.orgMap = {};
  1254. this.domMap = {};
  1255. this.node.hide();
  1256. this.wraper.hide();
  1257. //this.processor.setSize(0);
  1258. if(!notFireResize)this.flow.resize();
  1259. }
  1260. },
  1261. hide: function(){
  1262. this.node.hide();
  1263. },
  1264. getVisableOrgConfig: function(){
  1265. return this.processor.getVisableOrgConfig( this.options.routeId );
  1266. },
  1267. getQuickOrgData: function( orgConfig ){
  1268. if( !this.processor.quickData )return;
  1269. if( this.processor.quickData.rId !== this.options.routeId )return;
  1270. if( !this.processor.quickData.organizations )return;
  1271. var d = this.processor.quickData.organizations[orgConfig.name];
  1272. delete this.processor.quickData.organizations[orgConfig.name];
  1273. return d;
  1274. },
  1275. loadOrgs: function () {
  1276. var lastDom, configVisable = this.getVisableOrgConfig(), len = configVisable.length, lineNode;
  1277. configVisable.each(function (config, i) {
  1278. var dom, cfgId = config.id, quickOrgData = this.getQuickOrgData( config );
  1279. if( i % 2 === 0 )lineNode = new Element("div.o2flow-org-line").inject( this.node );
  1280. if( this.domMap[cfgId] ){
  1281. dom = this.domMap[cfgId].show().inject( lineNode );
  1282. if( quickOrgData && this.orgMap[cfgId]){
  1283. var org = this.orgMap[cfgId];
  1284. org.setData( quickOrgData );
  1285. org.resetSelectorData();
  1286. }
  1287. this.orgVisableItems.push( this.orgMap[cfgId] );
  1288. }else{
  1289. //dom = new Element("div" ).inject( lastDom || this.node, lastDom ? "after" : "bottom" );
  1290. dom = new Element("div" ).inject( lineNode );
  1291. this.domMap[cfgId] = dom;
  1292. this.loadOrg(dom, config, false, quickOrgData );
  1293. }
  1294. if( (i + 1 === len) && (len % 2 === 1) ){ //fullsize
  1295. dom.addClass("o2flow-org-fullsize-node").removeClass("o2flow-org-left-node").removeClass("o2flow-org-right-node");
  1296. }else{
  1297. if( i % 2 === 0 ){ //left
  1298. dom.removeClass("o2flow-org-fullsize-node").addClass("o2flow-org-left-node").removeClass("o2flow-org-right-node");
  1299. }else{
  1300. dom.removeClass("o2flow-org-fullsize-node").removeClass("o2flow-org-left-node").addClass("o2flow-org-right-node");
  1301. }
  1302. }
  1303. //lastDom = dom;
  1304. }.bind(this));
  1305. },
  1306. loadOrg: function (container, json, ignoreOldData, quickOrgData) {
  1307. var titleNode = new Element("div.o2flow-selector-title").inject(container);
  1308. new Element("div.o2flow-selector-titletext", { "text": json.title }).inject(titleNode);
  1309. var errorNode = new Element("div.o2flow-selector-errornode").inject(titleNode);
  1310. var contentNode = new Element("div.o2flow-selector-content").inject(container);
  1311. contentNode.setStyle( "height", MWF.ProcessFlow_ORG_HEIGHT + "px" );
  1312. var org = new MWF.ProcessFlow.Processor.Org(contentNode, this.form, json, this);
  1313. org.ignoreOldData = ignoreOldData;
  1314. org.errContainer = errorNode;
  1315. org.load( quickOrgData );
  1316. this.orgVisableItems.push(org);
  1317. this.orgMap[json.id] = org;
  1318. },
  1319. clearAllOrgs: function () {
  1320. //清空组织所选人
  1321. Object.values(this.orgMap).each(function (org) {
  1322. org.setDataToOriginal();
  1323. })
  1324. this.orgMap = {};
  1325. this.domMap = {};
  1326. this.orgVisableItems = [];
  1327. this.node.empty();
  1328. },
  1329. getSelectedData: function (filedName) {
  1330. var data = [];
  1331. for (var i = 0; i < this.orgVisableItems.length; i++) {
  1332. var org = this.orgVisableItems[i];
  1333. if (org.json.name === filedName) {
  1334. var selector = org.selector.selector;
  1335. selector.selectedItems.each(function (item) {
  1336. data.push(item.data)
  1337. })
  1338. }
  1339. }
  1340. return data;
  1341. },
  1342. isErrorHeightOverflow: function () {
  1343. var hasOverflow = false;
  1344. (this.orgVisableItems || []).each(function (item) {
  1345. if (item.errorHeightOverflow) {
  1346. hasOverflow = true;
  1347. }
  1348. }.bind(this));
  1349. return hasOverflow;
  1350. },
  1351. checkErrorHeightOverflow: function (force) {
  1352. if (force || this.isErrorHeightOverflow()) {
  1353. //this.processor.setSize(this.orgVisableItems.length, true);
  1354. this.flow.resize();
  1355. }
  1356. },
  1357. errorHeightChange: function () {
  1358. this.checkErrorHeightOverflow(true)
  1359. },
  1360. validationOrgs: function () {
  1361. if (!this.orgVisableItems || !this.orgVisableItems.length) return true;
  1362. var flag = true;
  1363. this.orgVisableItems.each(function (item) {
  1364. if (!item.validation()) flag = false;
  1365. }.bind(this));
  1366. this.checkErrorHeightOverflow();
  1367. return flag;
  1368. },
  1369. isOrgsHasEmpower: function () {
  1370. if (!this.orgVisableItems || !this.orgVisableItems.length) return true;
  1371. this.needCheckEmpowerOrg = [];
  1372. var ps = this.orgVisableItems.map(function (item) {
  1373. return Promise.resolve( item.hasEmpowerIdentity() ).then(function ( flag ) {
  1374. if( flag )return item;
  1375. }.bind(this));
  1376. }.bind(this));
  1377. return Promise.all( ps ).then(function ( array ) {
  1378. this.needCheckEmpowerOrg = array.clean();
  1379. return this.needCheckEmpowerOrg.length > 0;
  1380. }.bind(this));
  1381. },
  1382. saveOrgs: function (keepSilent) {
  1383. if (!this.orgVisableItems || !this.orgVisableItems.length) return true;
  1384. var flag = true;
  1385. this.orgVisableItems.each(function (item) {
  1386. if (!item.save(!keepSilent)) flag = false;
  1387. }.bind(this));
  1388. return flag;
  1389. },
  1390. saveOrgsWithCheckEmpower: function (callback) {
  1391. var visableOrg = this.getVisableOrgConfig();
  1392. var needOrgLength = visableOrg.length;
  1393. var loadedOrgLength = 0;
  1394. if ( this.orgVisableItems && this.orgVisableItems.length)loadedOrgLength = this.orgVisableItems.length;
  1395. if( needOrgLength !== loadedOrgLength ){
  1396. this.flow.noticeError(
  1397. MWF.xApplication.process.Work.LP.loadedOrgCountUnexpected,
  1398. this.node
  1399. );
  1400. return false;
  1401. }
  1402. if (!this.orgVisableItems || !this.orgVisableItems.length) {
  1403. if (callback) callback();
  1404. return true;
  1405. }
  1406. if (!this.validationOrgs()) return false;
  1407. Promise.resolve( this.isOrgsHasEmpower() ).then(function (flag) {
  1408. if( flag ){
  1409. this.showEmpowerDlg(callback);
  1410. }else{
  1411. if (callback) callback();
  1412. return true;
  1413. }
  1414. }.bind(this));
  1415. },
  1416. showEmpowerDlg: function (callback) {
  1417. var empowerNode = new Element("div.o2flow-empower-node");
  1418. empowerNode.loadCss( this.flow.path + this.flow.options.style + "/style.css" );
  1419. var empowerTitleNode = new Element("div.o2flow-empower-titleNode", {
  1420. text: MWF.xApplication.process.Xform.LP.empowerDlgText
  1421. }).inject(empowerNode);
  1422. var orgs = this.needCheckEmpowerOrg;
  1423. var len = orgs.length;
  1424. var lines = ((len + 1) / 2).toInt();
  1425. var empowerTable = new Element("table.o2flow-empower-table", {
  1426. "cellspacing": 0, "cellpadding": 0, "border": 0, "width": "100%"
  1427. }).inject(empowerNode);
  1428. for (var n = 0; n < lines; n++) {
  1429. var tr = new Element("tr").inject(empowerTable);
  1430. new Element("td.o2flow-empower-oddTd").inject(tr);
  1431. new Element("td.o2flow-empower-evenTd").inject(tr);
  1432. }
  1433. var trs = empowerTable.getElements("tr");
  1434. orgs.each(function (org, i) {
  1435. var sNode;
  1436. var width;
  1437. if (i + 1 == len && (len % 2 === 1)) {
  1438. sNode = trs[trs.length - 1].getFirst("td");
  1439. sNode.set("colspan", 2);
  1440. trs[trs.length - 1].getLast("td").destroy();
  1441. width = "50%";
  1442. } else {
  1443. var row = ((i + 2) / 2).toInt();
  1444. var tr = trs[row - 1];
  1445. sNode = (i % 2 === 0) ? tr.getFirst("td") : tr.getLast("td");
  1446. }
  1447. org.loadCheckEmpower(sNode);
  1448. }.bind(this));
  1449. var width = 840;
  1450. empowerNode.setStyle("height", lines * MWF.ProcessFlow_ORG_HEIGHT + 20);
  1451. empowerNode.setStyle("width", width + "px");
  1452. empowerNode.setStyle("opacity", 0);
  1453. this.node.getParent().mask({
  1454. "opacity": 0.7,
  1455. "background-color": "#eee",
  1456. "z-index": this.flow.options.zIndex + 2
  1457. });
  1458. this.empowerDlg = o2.DL.open({
  1459. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1460. "style": this.form.json.dialogStyle || "user",
  1461. "isResize": false,
  1462. "content": empowerNode,
  1463. //"container" : this.node,
  1464. "width": width + 40, //600,
  1465. "height": "auto", //dlgHeight,
  1466. "mark": true,
  1467. "zindex": this.flow.options.zIndex + 3,
  1468. "onPostShow": function () {
  1469. if (this.nodeWidth)this.node.setStyle("width", this.nodeWidth + "px");
  1470. if (this.nodeHeight)this.node.setStyle("height", this.nodeHeight + "px");
  1471. empowerNode.setStyle("opacity", 1);
  1472. },
  1473. "buttonList": [
  1474. {
  1475. "type": "ok",
  1476. "text": MWF.LP.process.button.ok,
  1477. "action": function (d, e) {
  1478. orgs.each(function (org, i) {
  1479. org.saveCheckedEmpowerData(function () {
  1480. if (i === orgs.length - 1) {
  1481. if (callback) callback();
  1482. this.node.getParent().unmask();
  1483. this.empowerDlg.close();
  1484. }
  1485. }.bind(this))
  1486. }.bind(this))
  1487. }.bind(this)
  1488. },
  1489. {
  1490. "type": "cancel",
  1491. "text": MWF.LP.process.button.cancel,
  1492. "action": function () {
  1493. this.node.getParent().unmask();
  1494. this.empowerDlg.close();
  1495. }.bind(this)
  1496. }
  1497. ]
  1498. });
  1499. },
  1500. });
  1501. MWF.ProcessFlow.Processor.Org = new Class({
  1502. Implements: [Options, Events],
  1503. options: {
  1504. moduleEvents: ["queryLoadSelector", "postLoadSelector", "postLoadContent", "queryLoadCategory", "postLoadCategory",
  1505. "selectCategory", "unselectCategory", "queryLoadItem", "postLoadItem", "selectItem", "unselectItem", "change"]
  1506. },
  1507. initialize: function (container, form, json, processor, options) {
  1508. this.form = form;
  1509. this.json = json;
  1510. this.processor = processor;
  1511. this.container = $(container);
  1512. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1513. this.setOptions(options);
  1514. },
  1515. load: function ( quickData ) {
  1516. var options = this.getOptions();
  1517. if (options) {
  1518. if( quickData )options.values = quickData;
  1519. this.selector = new MWF.O2Selector(this.container, options);
  1520. }
  1521. },
  1522. clearTooltip: function(){
  1523. if( this.selector && this.selector.selector && this.selector.selector.clearTooltip ){
  1524. this.selector.selector.clearTooltip();
  1525. }
  1526. },
  1527. _getOrgOptions: function () {
  1528. this.selectTypeList = typeOf(this.json.selectType) == "array" ? this.json.selectType : [this.json.selectType];
  1529. if (this.selectTypeList.contains("identity")) {
  1530. this.identityOptions = new MWF.ProcessFlow.Processor.IdentityOptions(this.form, this.json);
  1531. }
  1532. if (this.selectTypeList.contains("unit")) {
  1533. this.unitOptions = new MWF.ProcessFlow.Processor.UnitOptions(this.form, this.json);
  1534. }
  1535. if( this.selectTypeList.contains( "group" ) ){
  1536. this.groupOptions = new MWF.ProcessFlow.Processor.GroupOptions( this.form, this.json );
  1537. }
  1538. },
  1539. getDefaultOptions: function(){
  1540. return {
  1541. "style": "flow",
  1542. "mainColorEnable": this.processor.flow.options.mainColorEnable,
  1543. "width": "auto",
  1544. "height": MWF.ProcessFlow_ORG_HEIGHT,
  1545. "embedded": true,
  1546. "hasLetter": false, //字母
  1547. "hasTop": true //可选、已选的标题
  1548. };
  1549. },
  1550. getOptionEvents: function(){
  1551. return {};
  1552. },
  1553. getOptions: function () {
  1554. var _self = this;
  1555. this._getOrgOptions();
  1556. if (this.selectTypeList.length === 0) return false;
  1557. var exclude = [];
  1558. if (this.json.exclude) {
  1559. var v = this.form.Macro.exec(this.json.exclude.code, this);
  1560. exclude = typeOf(v) === "array" ? v : [v];
  1561. }
  1562. var identityOpt;
  1563. if (this.identityOptions) {
  1564. identityOpt = this.identityOptions.getOptions();
  1565. if (this.json.identityRange !== "all") {
  1566. if (!identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length)) {
  1567. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  1568. identityOpt.disabled = true;
  1569. // return false;
  1570. }
  1571. }
  1572. if (!identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange !== "all") {
  1573. if (!identityOpt.dutys || !identityOpt.dutys.length) {
  1574. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  1575. identityOpt.disabled = true;
  1576. // return false;
  1577. }
  1578. }
  1579. if (this.ignoreOldData) {
  1580. identityOpt.values = this._computeValue() || [];
  1581. } else {
  1582. identityOpt.values = this.getValue() || [];
  1583. }
  1584. identityOpt.exclude = exclude;
  1585. }
  1586. var unitOpt;
  1587. if (this.unitOptions) {
  1588. unitOpt = this.unitOptions.getOptions();
  1589. if (this.json.unitRange !== "all") {
  1590. if (!unitOpt.units || !unitOpt.units.length) {
  1591. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  1592. unitOpt.disabled = true;
  1593. // return false;
  1594. }
  1595. }
  1596. if (this.ignoreOldData) {
  1597. unitOpt.values = this._computeValue() || [];
  1598. } else {
  1599. unitOpt.values = this.getValue() || [];
  1600. }
  1601. unitOpt.exclude = exclude;
  1602. }
  1603. var groupOpt;
  1604. if( this.groupOptions ){
  1605. groupOpt = this.groupOptions.getOptions();
  1606. if (this.ignoreOldData) {
  1607. groupOpt.values = this._computeValue() || [];
  1608. } else {
  1609. groupOpt.values = this.getValue() || [];
  1610. }
  1611. groupOpt.exclude = exclude;
  1612. }
  1613. var defaultOpt = this.getDefaultOptions();
  1614. if (this.json.events && typeOf(this.json.events) === "object") {
  1615. Object.each(this.json.events, function (e, key) {
  1616. if (e.code) {
  1617. if (this.options.moduleEvents.indexOf(key) !== -1) {
  1618. if (key === "postLoadSelector") {
  1619. this.addEvent("loadSelector", function (selector) {
  1620. return this.form.Macro.fire(e.code, selector);
  1621. }.bind(this))
  1622. } else if (key === "queryLoadSelector") {
  1623. defaultOpt["onQueryLoad"] = function (target) {
  1624. return this.form.Macro.fire(e.code, target);
  1625. }.bind(this)
  1626. } else {
  1627. defaultOpt["on" + key.capitalize()] = function (target) {
  1628. return this.form.Macro.fire(e.code, target);
  1629. }.bind(this)
  1630. }
  1631. }
  1632. }
  1633. }.bind(this));
  1634. }
  1635. if (this.needValid()) {
  1636. defaultOpt["onValid"] = function (selector) {
  1637. this.validOnSelect();
  1638. }.bind(this);
  1639. }
  1640. if (this.form.json.selectorStyle) {
  1641. defaultOpt = Object.merge(Object.clone(this.form.json.selectorStyle), defaultOpt);
  1642. if (this.form.json.selectorStyle.style) defaultOpt.style = this.form.json.selectorStyle.style;
  1643. }
  1644. var events = this.getOptionEvents();
  1645. if (this.selectTypeList.length === 1) {
  1646. var opts = Object.merge(
  1647. defaultOpt,
  1648. {
  1649. "type": this.selectTypeList[0],
  1650. "onLoad": function () {
  1651. //this 为 selector
  1652. _self.selectOnLoad(this, this.selector)
  1653. }
  1654. },
  1655. events,
  1656. identityOpt || unitOpt || groupOpt
  1657. )
  1658. return this.filterOptionValues( opts, this.selectTypeList[0] );
  1659. } else if (this.selectTypeList.length > 1) {
  1660. var options = {
  1661. "type": "",
  1662. "types": this.selectTypeList,
  1663. "onLoad": function () {
  1664. //this 为 selector
  1665. _self.selectOnLoad(this)
  1666. }
  1667. };
  1668. if (identityOpt) {
  1669. options.identityOptions = Object.merge(
  1670. defaultOpt, events, identityOpt
  1671. );
  1672. }
  1673. if (unitOpt) {
  1674. options.unitOptions = Object.merge(
  1675. defaultOpt, events, unitOpt
  1676. );
  1677. }
  1678. if (groupOpt) {
  1679. options.groupOptions = Object.merge(
  1680. defaultOpt, events, groupOpt
  1681. );
  1682. }
  1683. return options;
  1684. }
  1685. },
  1686. filterOptionValues: function( options, type ){
  1687. var suffix;
  1688. switch (type) {
  1689. case "identity": suffix = "I"; break;
  1690. case "unit": suffix = "U"; break;
  1691. case "group": suffix = "G"; break;
  1692. }
  1693. options.values = (options.values || []).filter(function (v) {
  1694. if( typeOf(v) === "string" ){
  1695. if( v.contains("@") ){
  1696. return v.split("@").getLast().toUpperCase() === suffix;
  1697. }else{
  1698. return true;
  1699. }
  1700. }else if( typeOf(v) === "object" ){
  1701. if( v.distinguishedName ){
  1702. return v.distinguishedName.split("@").getLast().toUpperCase() === suffix;
  1703. }else{
  1704. return false;
  1705. }
  1706. }
  1707. return false;
  1708. }.bind(this));
  1709. return options;
  1710. },
  1711. selectOnLoad: function (selector) {
  1712. //if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  1713. this.fireEvent("loadSelector", [selector])
  1714. },
  1715. loadOrgWidget: function (value, node) {
  1716. var height = node.getStyle("height").toInt();
  1717. if (node.getStyle("overflow") === "visible" && !height) node.setStyle("overflow", "hidden");
  1718. if (value && value.length) {
  1719. value.each(function (data) {
  1720. if( typeOf(data) === "string" ){
  1721. data = { distinguishedName : data, name : o2.name.cn(data) };
  1722. }
  1723. var flag = data.distinguishedName.substr(data.distinguishedName.length - 1, 1);
  1724. var copyData = Object.clone(data);
  1725. if (this.json.displayTextScript && this.json.displayTextScript.code) {
  1726. this.currentData = copyData;
  1727. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  1728. if (displayName) {
  1729. copyData.displayName = displayName;
  1730. }
  1731. this.currentData = null;
  1732. }
  1733. var widget;
  1734. switch (flag.toLowerCase()) {
  1735. case "i":
  1736. widget = new MWF.widget.O2Identity(copyData, node, this.getOrgWidgetOption());
  1737. break;
  1738. case "p":
  1739. widget = new MWF.widget.O2Person(copyData, node, this.getOrgWidgetOption());
  1740. break;
  1741. case "u":
  1742. widget = new MWF.widget.O2Unit(copyData, node, this.getOrgWidgetOption());
  1743. break;
  1744. case "g":
  1745. widget = new MWF.widget.O2Group(copyData, node, this.getOrgWidgetOption());
  1746. break;
  1747. default:
  1748. widget = new MWF.widget.O2Other(copyData, node, this.getOrgWidgetOption());
  1749. }
  1750. widget.field = this;
  1751. widget.load();
  1752. }.bind(this));
  1753. }
  1754. },
  1755. getOrgWidgetOption: function(){
  1756. return {"style": "xform", "lazy": true, "delay":true}
  1757. },
  1758. hasEmpowerIdentity: function () {
  1759. var data = this.getData();
  1760. if (!this.empowerChecker){
  1761. this.empowerChecker = new MWF.ProcessFlow.Processor.EmpowerChecker(this);
  1762. }
  1763. return this.empowerChecker.hasEmpowerIdentity(data);
  1764. },
  1765. checkEmpower: function (data, callback, container) {
  1766. if (typeOf(data) === "array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity") {
  1767. if (!this.empowerChecker){
  1768. this.empowerChecker = new MWF.ProcessFlow.Processor.EmpowerChecker(this);
  1769. }
  1770. this.empowerChecker.load(data, callback, container);
  1771. } else {
  1772. if (callback) callback(data);
  1773. }
  1774. },
  1775. loadCheckEmpower: function (container, callback) {
  1776. this.checkEmpower(this.getData(), callback, container);
  1777. },
  1778. saveCheckedEmpowerData: function (callback) {
  1779. var data = this.getData();
  1780. var simple = this.json.storeRange === "simple";
  1781. //this.empowerChecker.replaceEmpowerIdentity(data, function( newData ){
  1782. this.empowerChecker.setIgnoreEmpowerFlag(data, function (newData) {
  1783. var values = [];
  1784. newData.each(function (d) {
  1785. values.push(MWF.org.parseOrgData(d, true, simple));
  1786. }.bind(this));
  1787. this.setData(values);
  1788. if (callback) callback(values);
  1789. }.bind(this))
  1790. },
  1791. save: function (isValid) {
  1792. if (isValid) {
  1793. if (this.validation()) {
  1794. return true;
  1795. } else {
  1796. this.processor.checkErrorHeightOverflow();
  1797. return false;
  1798. }
  1799. } else {
  1800. this.setData(this.getData());
  1801. return true;
  1802. }
  1803. },
  1804. resetSelectorData: function () {
  1805. if (this.selector && this.selector.selector) {
  1806. this.selector.selector.emptySelectedItems();
  1807. this.selector.selector.options.values = this.getValue() || [];
  1808. this.selector.selector.setSelectedItem();
  1809. }
  1810. },
  1811. setDataToOriginal: function () {
  1812. var v = this._computeValue();
  1813. this.setData(v || "");
  1814. },
  1815. resetData: function () {
  1816. var v = this.getValue() || [];
  1817. //this.setData((v) ? v.join(", ") : "");
  1818. this.setData(v);
  1819. },
  1820. getData: function () {
  1821. if (this.selector) {
  1822. return this.getSelectedData();
  1823. } else {
  1824. return this.getValue();
  1825. }
  1826. },
  1827. getSelectedData: function () {
  1828. var simple = this.json.storeRange === "simple";
  1829. var data = [];
  1830. if (this.selector && this.selector.selector) {
  1831. this.selector.selector.selectedItems.each(function (item) {
  1832. data.push(MWF.org.parseOrgData(item.data, true, simple));
  1833. })
  1834. }
  1835. return data;
  1836. },
  1837. getValue: function () {
  1838. var value = this._getBusinessData();
  1839. if (!value) value = this._computeValue();
  1840. return value || "";
  1841. },
  1842. _computeValue: function () {
  1843. var values = [];
  1844. if (this.json.identityValue) {
  1845. this.json.identityValue.each(function (v) {
  1846. if (v) values.push(v)
  1847. });
  1848. }
  1849. if (this.json.unitValue) {
  1850. this.json.unitValue.each(function (v) {
  1851. if (v) values.push(v)
  1852. });
  1853. }
  1854. // if (this.json.groupValue) {
  1855. // this.json.groupValue.each(function (v) {
  1856. // if (v) values.push(v)
  1857. // });
  1858. // }
  1859. if (this.json.dutyValue) {
  1860. var dutys = JSON.decode(this.json.dutyValue);
  1861. var par;
  1862. if (dutys.length) {
  1863. dutys.each(function (duty) {
  1864. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  1865. var code = "return this.org.getDuty(\"" + duty.name + "\", \"" + par + "\")";
  1866. var d = this.form.Macro.exec(code, this);
  1867. if (typeOf(d) !== "array") d = (d) ? [d.toString()] : [];
  1868. d.each(function (dd) {
  1869. if (dd) values.push(dd);
  1870. });
  1871. }.bind(this));
  1872. }
  1873. }
  1874. if (this.json.defaultValue && this.json.defaultValue.code) {
  1875. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  1876. if (typeOf(fd) !== "array") fd = (fd) ? [fd] : [];
  1877. fd.each(function (fdd) {
  1878. if (fdd) {
  1879. if (typeOf(fdd) === "string") {
  1880. var data;
  1881. this.getOrgAction()[this.getValueMethod(fdd)](function (json) {
  1882. data = json.data
  1883. }.bind(this), null, fdd, false);
  1884. values.push(data);
  1885. } else {
  1886. values.push(fdd);
  1887. }
  1888. }
  1889. }.bind(this));
  1890. }
  1891. if (this.json.count > 0) {
  1892. return values.slice(0, this.json.count);
  1893. }
  1894. return values;
  1895. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  1896. },
  1897. getOrgAction: function () {
  1898. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1899. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  1900. return this.orgAction;
  1901. },
  1902. setData: function (value) {
  1903. if (!value) return false;
  1904. var oldValues = this.getValue();
  1905. var values = [];
  1906. var simple = this.json.storeRange === "simple";
  1907. var type = typeOf(value);
  1908. if (type === "array") {
  1909. value.each(function (v) {
  1910. var vtype = typeOf(v);
  1911. var data = null;
  1912. if (vtype === "string") {
  1913. this.getOrgAction()[this.getValueMethod(v)](function (json) {
  1914. data = MWF.org.parseOrgData(json.data, true, simple);
  1915. }.bind(this), null, v, false);
  1916. }
  1917. if (vtype === "object") {
  1918. data = MWF.org.parseOrgData(v, true, simple);
  1919. if (data.woPerson) delete data.woPerson;
  1920. }
  1921. if (data) values.push(data);
  1922. }.bind(this));
  1923. }
  1924. if (type === "string") {
  1925. var vData;
  1926. this.getOrgAction()[this.getValueMethod(value)](function (json) {
  1927. vData = MWF.org.parseOrgData(json.data, true, simple);
  1928. }.bind(this), null, value, false);
  1929. if (vData) values.push(vData);
  1930. }
  1931. if (type === "object") {
  1932. var vData = MWF.org.parseOrgData(value, true, simple);
  1933. if (vData.woPerson) delete vData.woPerson;
  1934. values.push(vData);
  1935. }
  1936. var change = false;
  1937. if (oldValues.length && values.length) {
  1938. if (oldValues.length === values.length) {
  1939. for (var i = 0; i < oldValues.length; i++) {
  1940. if ((oldValues[i].distinguishedName !== values[i].distinguishedName) || (oldValues[i].name !== values[i].name) || (oldValues[i].unique !== values[i].unique)) {
  1941. change = true;
  1942. break;
  1943. }
  1944. }
  1945. } else {
  1946. change = true;
  1947. }
  1948. } else if (values.length || oldValues.length) {
  1949. change = true;
  1950. }
  1951. this._setBusinessData(values);
  1952. if (change) this.fireEvent("change");
  1953. },
  1954. getValueMethod: function (value) {
  1955. if (value) {
  1956. var flag = value.substr(value.length - 1, 1);
  1957. switch (flag.toLowerCase()) {
  1958. case "i":
  1959. return "getIdentity";
  1960. case "p":
  1961. return "getPerson";
  1962. case "u":
  1963. return "getUnit";
  1964. case "g":
  1965. return "getGroup";
  1966. default:
  1967. return (this.json.selectType === "unit") ? "getUnit" : "getIdentity";
  1968. }
  1969. }
  1970. return (this.json.selectType === "unit") ? "getUnit" : "getIdentity";
  1971. },
  1972. _getBusinessData: function () {
  1973. if (this.json.section == "yes") {
  1974. return this._getBusinessSectionData();
  1975. } else {
  1976. if (this.json.type === "Opinion") {
  1977. return this._getBusinessSectionDataByPerson();
  1978. } else {
  1979. return this.form.businessData.data[this.json.name] || "";
  1980. }
  1981. }
  1982. },
  1983. _getBusinessSectionData: function () {
  1984. switch (this.json.sectionBy) {
  1985. case "person":
  1986. return this._getBusinessSectionDataByPerson();
  1987. case "unit":
  1988. return this._getBusinessSectionDataByUnit();
  1989. case "activity":
  1990. return this._getBusinessSectionDataByActivity();
  1991. case "splitValue":
  1992. return this._getBusinessSectionDataBySplitValue();
  1993. case "script":
  1994. return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
  1995. default:
  1996. return this.form.businessData.data[this.json.name] || "";
  1997. }
  1998. },
  1999. _getBusinessSectionDataByPerson: function () {
  2000. this.form.sectionListObj[this.json.name] = layout.desktop.session.user.id;
  2001. var dataObj = this.form.businessData.data[this.json.name];
  2002. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  2003. },
  2004. _getBusinessSectionDataByUnit: function () {
  2005. this.form.sectionListObj[this.json.name] = "";
  2006. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  2007. if (key) this.form.sectionListObj[this.json.name] = key;
  2008. var dataObj = this.form.businessData.data[this.json.name];
  2009. if (!dataObj) return "";
  2010. return (key) ? (dataObj[key] || "") : "";
  2011. },
  2012. _getBusinessSectionDataByActivity: function () {
  2013. this.form.sectionListObj[this.json.name] = "";
  2014. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  2015. if (key) this.form.sectionListObj[this.json.name] = key;
  2016. var dataObj = this.form.businessData.data[this.json.name];
  2017. if (!dataObj) return "";
  2018. return (key) ? (dataObj[key] || "") : "";
  2019. },
  2020. _getBusinessSectionDataBySplitValue: function () {
  2021. this.form.sectionListObj[this.json.name] = "";
  2022. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  2023. if (key) this.form.sectionListObj[this.json.name] = key;
  2024. var dataObj = this.form.businessData.data[this.json.name];
  2025. if (!dataObj) return "";
  2026. return (key) ? (dataObj[key] || "") : "";
  2027. },
  2028. _getBusinessSectionDataByScript: function (code) {
  2029. this.form.sectionListObj[this.json.name] = "";
  2030. var dataObj = this.form.businessData.data[this.json.name];
  2031. if (!dataObj) return "";
  2032. var key = this.form.Macro.exec(code, this);
  2033. if (key) this.form.sectionListObj[this.json.name] = key;
  2034. return (key) ? (dataObj[key] || "") : "";
  2035. },
  2036. loadPathData: function (path) {
  2037. var data = null;
  2038. this.form.workAction.getJobDataByPath(this.form.businessData.work.job, path, function (json) {
  2039. data = json.data || null;
  2040. }, null, false);
  2041. return data;
  2042. },
  2043. _setBusinessData: function (v) {
  2044. if (this.json.section == "yes") {
  2045. // var d = this.loadPathData(this.json.name);
  2046. // if (d) this.form.businessData.data[this.json.name] = d;
  2047. this._setBusinessSectionData(v);
  2048. } else {
  2049. if (this.json.type === "Opinion") {
  2050. // var d = this.loadPathData(this.json.name);
  2051. // if (d) this.form.businessData.data[this.json.name] = d;
  2052. this._setBusinessSectionDataByPerson(v);
  2053. } else {
  2054. if (this.form.businessData.data[this.json.name]) {
  2055. this.form.businessData.data[this.json.name] = v;
  2056. } else {
  2057. this.form.businessData.data[this.json.name] = v;
  2058. this.form.Macro.environment.setData(this.form.businessData.data);
  2059. }
  2060. if (this.json.isTitle) this.form.businessData.work.title = v;
  2061. }
  2062. }
  2063. },
  2064. _setBusinessSectionData: function (v) {
  2065. switch (this.json.sectionBy) {
  2066. case "person":
  2067. this._setBusinessSectionDataByPerson(v);
  2068. break;
  2069. case "unit":
  2070. this._setBusinessSectionDataByUnit(v);
  2071. break;
  2072. case "activity":
  2073. this._setBusinessSectionDataByActivity(v);
  2074. break;
  2075. case "splitValue":
  2076. this._setBusinessSectionDataBySplitValue(v);
  2077. break;
  2078. case "script":
  2079. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  2080. break;
  2081. default:
  2082. if (this.form.businessData.data[this.json.name]) {
  2083. this.form.businessData.data[this.json.name] = v;
  2084. } else {
  2085. this.form.businessData.data[this.json.name] = v;
  2086. this.form.Macro.environment.setData(this.form.businessData.data);
  2087. }
  2088. }
  2089. },
  2090. _setBusinessSectionDataByPerson: function (v) {
  2091. var resetData = false;
  2092. var key = layout.desktop.session.user.id;
  2093. this.form.sectionListObj[this.json.name] = key;
  2094. var dataObj = this.form.businessData.data[this.json.name];
  2095. if (!dataObj) {
  2096. dataObj = {};
  2097. this.form.businessData.data[this.json.name] = dataObj;
  2098. resetData = true;
  2099. }
  2100. if (!dataObj[key]) resetData = true;
  2101. dataObj[key] = v;
  2102. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2103. },
  2104. _setBusinessSectionDataByUnit: function (v) {
  2105. var resetData = false;
  2106. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  2107. if (key) {
  2108. this.form.sectionListObj[this.json.name] = key;
  2109. var dataObj = this.form.businessData.data[this.json.name];
  2110. if (!dataObj) {
  2111. dataObj = {};
  2112. this.form.businessData.data[this.json.name] = dataObj;
  2113. resetData = true;
  2114. }
  2115. if (!dataObj[key]) resetData = true;
  2116. dataObj[key] = v;
  2117. }
  2118. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2119. },
  2120. _setBusinessSectionDataByActivity: function (v) {
  2121. var resetData = false;
  2122. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  2123. if (key) {
  2124. this.form.sectionListObj[this.json.name] = key;
  2125. var dataObj = this.form.businessData.data[this.json.name];
  2126. if (!dataObj) {
  2127. dataObj = {};
  2128. this.form.businessData.data[this.json.name] = dataObj;
  2129. resetData = true;
  2130. }
  2131. if (!dataObj[key]) resetData = true;
  2132. dataObj[key] = v;
  2133. }
  2134. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2135. },
  2136. _setBusinessSectionDataBySplitValue: function (v) {
  2137. var resetData = false;
  2138. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  2139. if (key) {
  2140. this.form.sectionListObj[this.json.name] = key;
  2141. var dataObj = this.form.businessData.data[this.json.name];
  2142. if (!dataObj) {
  2143. dataObj = {};
  2144. this.form.businessData.data[this.json.name] = dataObj;
  2145. resetData = true;
  2146. }
  2147. if (!dataObj[key]) resetData = true;
  2148. dataObj[key] = v;
  2149. }
  2150. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2151. },
  2152. _setBusinessSectionDataByScript: function (code, v) {
  2153. var resetData = false;
  2154. var key = this.form.Macro.exec(code, this);
  2155. if (key) {
  2156. this.form.sectionListObj[this.json.name] = key;
  2157. var dataObj = this.form.businessData.data[this.json.name];
  2158. if (!dataObj) {
  2159. dataObj = {};
  2160. this.form.businessData.data[this.json.name] = dataObj;
  2161. resetData = true;
  2162. }
  2163. if (!dataObj[key]) resetData = true;
  2164. dataObj[key] = v;
  2165. }
  2166. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  2167. },
  2168. createErrorNode: function (text) {
  2169. var _self = this;
  2170. var node;
  2171. if (this.processor.css && this.processor.css.errorContentNode) {
  2172. node = new Element("div", {
  2173. "styles": this.processor.css.errorContentNode,
  2174. "text": text
  2175. });
  2176. if (this.processor.css.errorCloseNode) {
  2177. var closeNode = new Element("div", {
  2178. "styles": this.processor.css.errorCloseNode,
  2179. "events": {
  2180. "click": function () {
  2181. this.destroy();
  2182. if (_self.errorHeightOverflow) {
  2183. _self.errorHeightOverflow = false;
  2184. _self.processor.errorHeightChange();
  2185. }
  2186. }.bind(node)
  2187. }
  2188. }).inject(node);
  2189. }
  2190. } else {
  2191. node = new Element("div");
  2192. var iconNode = new Element("div", {
  2193. "styles": {
  2194. "width": "20px",
  2195. "height": "20px",
  2196. "float": "left",
  2197. "background": "url(" + "../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  2198. }
  2199. }).inject(node);
  2200. var textNode = new Element("div", {
  2201. "styles": {
  2202. "height": "auto",
  2203. "min-height": "20px",
  2204. "line-height": "20px",
  2205. "margin-left": "20px",
  2206. "color": "red",
  2207. "word-break": "break-all"
  2208. },
  2209. "text": text
  2210. }).inject(node);
  2211. }
  2212. return node;
  2213. },
  2214. notValidationMode: function (text) {
  2215. if (!this.isNotValidationMode) {
  2216. //this.isNotValidationMode = true;
  2217. //this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  2218. //this.node.setStyle("border-color", "red");
  2219. this.errNode = this.createErrorNode(text);
  2220. if (this.errContainer) {
  2221. this.errContainer.empty();
  2222. this.errNode.inject(this.errContainer);
  2223. } else {
  2224. this.errNode.inject(this.container, "after");
  2225. }
  2226. if (!this.errNode.isIntoView()) this.errNode.scrollIntoView(false);
  2227. var errorSize = this.errNode.getSize();
  2228. if (!layout.mobile && errorSize.y > 26) {
  2229. this.errorHeightOverflow = true;
  2230. }
  2231. }
  2232. },
  2233. needValid: function () {
  2234. return ((this.json.validationCount && typeOf(this.json.validationCount.toInt()) === "number") ||
  2235. (this.json.validation && this.json.validation.code));
  2236. },
  2237. validOnSelect: function () {
  2238. if (!this.errNode) return true;
  2239. var flag = true;
  2240. if (this.json.validationCount && typeOf(this.json.validationCount.toInt()) === "number") {
  2241. if (this.selector.selector.selectedItems.length < this.json.validationCount.toInt()) {
  2242. flag = MWF.xApplication.process.Xform.LP.selectItemCountNotice.replace("{count}", this.json.validationCount);
  2243. }
  2244. }
  2245. if (flag === true) {
  2246. if (this.json.validation && this.json.validation.code) {
  2247. var data = this.getData();
  2248. this.setData(data);
  2249. flag = this.form.Macro.exec(this.json.validation.code, this);
  2250. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2251. }
  2252. }
  2253. if (flag.toString() != "true") {
  2254. this.notValidationMode(flag);
  2255. this.processor.errorHeightChange();
  2256. return false;
  2257. } else if (this.errNode) {
  2258. this.errNode.destroy();
  2259. this.errNode = null;
  2260. if (this.errorHeightOverflow) {
  2261. this.errorHeightOverflow = false;
  2262. this.processor.errorHeightChange();
  2263. }
  2264. }
  2265. return true;
  2266. },
  2267. validation: function () {
  2268. var data = this.getData();
  2269. this.setData(data);
  2270. var flag = true;
  2271. if (this.json.validationCount && typeOf(this.json.validationCount.toInt()) === "number") {
  2272. if (data.length < this.json.validationCount.toInt()) {
  2273. //"请至少选择" + this.json.validationCount + "项"
  2274. flag = MWF.xApplication.process.Xform.LP.selectItemCountNotice.replace("{count}", this.json.validationCount);
  2275. }
  2276. }
  2277. if (flag === true) {
  2278. if (this.json.validation && this.json.validation.code) {
  2279. flag = this.form.Macro.exec(this.json.validation.code, this);
  2280. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2281. }
  2282. }
  2283. if (flag.toString() != "true") {
  2284. this.notValidationMode(flag);
  2285. return false;
  2286. } else if (this.errNode) {
  2287. this.errNode.destroy();
  2288. this.errNode = null;
  2289. }
  2290. return true;
  2291. }
  2292. });
  2293. MWF.ProcessFlow.Processor.EmpowerChecker = new Class({
  2294. initialize: function (org) {
  2295. this.org = org;
  2296. this.form = org.form;
  2297. this.json = org.json;
  2298. this.processor = org.processor;
  2299. this.flow = org.processor.flow;
  2300. },
  2301. load: function (data, callback, container) {
  2302. var p = this.getEmpowerData( data );
  2303. return Promise.resolve(p).then(function ( eArr ) {
  2304. if (eArr.length > 0) {
  2305. this.loadDom(eArr, data, container);
  2306. } else {
  2307. if (callback) callback(data);
  2308. }
  2309. }.bind(this));
  2310. },
  2311. loadDom: function(eArr, data, container){
  2312. var _self = this;
  2313. var titleNode = new Element("div.o2flow-empower-areaTitle").inject(container);
  2314. new Element("div.o2flow-empower-areaTitleText", { text: this.json.title }).inject(titleNode);
  2315. var selectAllNode = new Element("div.o2flow-empower-selectAllNode").inject( titleNode );
  2316. var contentNode = new Element("div.o2flow-empower-areaContent").inject(container);
  2317. this.selectAllRadio = new MWF.ProcessFlow.widget.Radio2(selectAllNode, this.flow, {
  2318. optionList: [{
  2319. value: "true", text: this.flow.lp.selectAll
  2320. }],
  2321. value: "true",
  2322. onCheck: function(el, value){
  2323. _self.empowerCheckbox.checkAll();
  2324. },
  2325. onUncheck: function(el, value){
  2326. _self.empowerCheckbox.uncheckAll();
  2327. },
  2328. });
  2329. this.selectAllRadio.load();
  2330. this.empowerCheckbox = new MWF.ProcessFlow.widget.Checkbox(contentNode, this.flow, {
  2331. optionList: eArr.map(function (e) {
  2332. return {
  2333. value: e.id,
  2334. text: e.fromIdentity.split("@")[0] + " " + this.flow.lp.empowerTo + " " + e.toIdentity.split("@")[0],
  2335. data: e
  2336. };
  2337. }.bind(this)),
  2338. values: eArr.map(function (e) {
  2339. return e.id;
  2340. })
  2341. });
  2342. this.empowerCheckbox.load();
  2343. },
  2344. hasEmpowerIdentity: function (data) {
  2345. var p = this.getEmpowerData( data );
  2346. return Promise.resolve(p).then(function ( arr ) {
  2347. return arr.length > 0;
  2348. });
  2349. },
  2350. isNeedCheck: function(data){
  2351. return typeOf(data) === "array" && this.json.isCheckEmpower && this.json.identityResultType === "identity";
  2352. },
  2353. getIdentityDn: function( data ){
  2354. return data.filter(function (d) {
  2355. return d.distinguishedName && d.distinguishedName.substr(d.distinguishedName.length - 1, 1).toLowerCase() === "i";
  2356. }).map(function (d) {
  2357. return d.distinguishedName;
  2358. });
  2359. },
  2360. getEmpowerData: function(data){
  2361. if( !this.isNeedCheck(data) )return [];
  2362. var array = this.getIdentityDn( data );
  2363. if( array.length < 1)return [];
  2364. return o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  2365. "application": (this.form.businessData.work || this.form.businessData.workCompleted).application,
  2366. "process": (this.form.businessData.work || this.form.businessData.workCompleted).process,
  2367. "work": (this.form.businessData.work || this.form.businessData.workCompleted).id,
  2368. "identityList": array
  2369. }, function (json) {
  2370. return json.data.filter(function (d) {
  2371. return d.fromIdentity !== d.toIdentity;
  2372. });
  2373. }.bind(this), function () {
  2374. return [];
  2375. })
  2376. },
  2377. getSelectedData: function (callback) {
  2378. var json = {};
  2379. this.empowerSelectNodes.each(function (node) {
  2380. if (node.retrieve("isSelected")) {
  2381. var d = node.retrieve("data");
  2382. json[d.fromIdentity] = d;
  2383. }
  2384. }.bind(this));
  2385. if (callback) callback(json);
  2386. },
  2387. setIgnoreEmpowerFlag : function(data, callback){
  2388. var ignoreList = this.empowerCheckbox.getUncheckData().map(function (d) {
  2389. return d.data.fromIdentity;
  2390. });
  2391. for( var i=0; i<data.length; i++ ){
  2392. var d = data[i];
  2393. if( ignoreList.indexOf( d.distinguishedName ) > -1 ){
  2394. d.ignoreEmpower = true;
  2395. }else if( d.ignoreEmpower ){
  2396. delete d.ignoreEmpower;
  2397. }
  2398. }
  2399. if( callback )callback( data );
  2400. },
  2401. });
  2402. MWF.ProcessFlow.Processor.UnitOptions = new Class({
  2403. Extends: MWF.APPOrg.UnitOptions
  2404. });
  2405. MWF.ProcessFlow.Processor.IdentityOptions = new Class({
  2406. Extends: MWF.APPOrg.IdentityOptions
  2407. });
  2408. MWF.ProcessFlow.Processor.GroupOptions = new Class({
  2409. Extends: MWF.APPOrg.GroupOptions
  2410. });
  2411. MWF.ProcessFlow.widget = {};
  2412. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  2413. MWF.ProcessFlow.widget.QuickSelect = new Class({
  2414. Extends: MTooltips,
  2415. options: {
  2416. event : "click",
  2417. hasArrow : false,
  2418. hideByClickBody : true,
  2419. offset : {
  2420. x : 0,
  2421. y : 5
  2422. },
  2423. nodeStyles: {
  2424. "font-size" : "13px",
  2425. "position" : "absolute",
  2426. "max-width" : "500px",
  2427. "min-width" : "260px",
  2428. "z-index" : 20002,
  2429. "background-color" : "#fff",
  2430. "padding" : "10px 0px 10px 0px",
  2431. "border-radius" : "8px",
  2432. "box-shadow": "0px 0px 8px 0px rgba(0,0,0,0.25)",
  2433. "-webkit-user-select": "text",
  2434. "-moz-user-select": "text"
  2435. }
  2436. },
  2437. _loadCustom : function( callback ){
  2438. this.node.loadCss( this.flow.path + this.flow.options.style + "/style.css" );
  2439. var width = this.target.getSize().x ;
  2440. this.node.setStyles({
  2441. "max-width": width+"px",
  2442. "min-width": width+"px"
  2443. });
  2444. var work = this.flow.form.businessData.work;
  2445. var d = {
  2446. process: work.process,
  2447. activity: work.activity,
  2448. activityAlias: work.activityAlias,
  2449. activityName: work.activityName
  2450. };
  2451. // if( work.activityAlias ){
  2452. // d.activityAlias = work.activityAlias
  2453. // }else{
  2454. // d.activityName = work.activityName;
  2455. // }
  2456. var p = o2.Actions.load("x_processplatform_assemble_surface").TaskProcessModeAction.listMode( d );
  2457. Promise.resolve(p).then(function (json) {
  2458. debugger;
  2459. var list = this.filterData(json.data);
  2460. var data = list.map(function (d) {
  2461. return {
  2462. type: d.action,
  2463. text: this.getText( d ),
  2464. data: d
  2465. }
  2466. }.bind(this));
  2467. if( !data || !data.length ){
  2468. new Element("div.o2flow-quick-select-item", {
  2469. text: this.flow.lp.noQuickSelectDataNote
  2470. }).inject( this.contentNode );
  2471. }else{
  2472. this.loadItems(data)
  2473. }
  2474. //setTimeout( function () {
  2475. if(callback)callback( data );
  2476. //}, 50);
  2477. }.bind(this));
  2478. },
  2479. loadItems: function(data){
  2480. var _self = this;
  2481. data.each( function (d) {
  2482. var item = new Element("div.o2flow-quick-select-item", {
  2483. events: {
  2484. mouseover: function () {
  2485. this.addClass("o2flow-quick-select-item-active");
  2486. this.getFirst().addClass("o2flow-quick-select-item-contnet-active");
  2487. if( _self.flow.options.mainColorEnable ){
  2488. this.addClass("mainColor_bg");
  2489. this.getFirst().addClass("mainColor_bg");
  2490. }
  2491. },
  2492. mouseout: function () {
  2493. this.removeClass("o2flow-quick-select-item-active");
  2494. this.getFirst().removeClass("o2flow-quick-select-item-contnet-active");
  2495. if( _self.flow.options.mainColorEnable ) {
  2496. this.removeClass("mainColor_bg");
  2497. this.getFirst().removeClass("mainColor_bg");
  2498. }
  2499. },
  2500. click: function () {
  2501. var d = Object.clone( item.retrieve("data"));
  2502. _self.flow.changeAction( d.type, d.data );
  2503. _self.hide();
  2504. }
  2505. }
  2506. }).inject( this.contentNode );
  2507. item.store( "data", d );
  2508. var title = new Element("div.o2flow-quick-select-itemtitle", {
  2509. text: this.flow.lp.flowActions[d.type]
  2510. }).inject( item );
  2511. title.addClass( "o2flow-"+d.type+"-color" );
  2512. var content = new Element("div.o2flow-quick-select-itemtext", {
  2513. text: ":"+ d.text
  2514. }).inject( item )
  2515. }.bind(this))
  2516. },
  2517. filterData: function( data ){
  2518. //var onekeyList = listData();
  2519. return data.filter(function (d) {
  2520. var flag = (d.action === "process" && this.flow.processEnable) || (d.action === "reset" && this.flow.resetEnable) || (d.action === "addTask" && this.flow.addTaskEnable);
  2521. if( !flag )return false;
  2522. if( d.action === "process" && !this.flow.getRouteConfig(d.routeName) )return false;
  2523. return true;
  2524. }.bind(this));
  2525. },
  2526. getText: function( d ){
  2527. //选择[送办理],意见:请办理,处理人:张三、李四、张三、李四、张三、李四、张三、李四、张三、李四、张三、李四、张三、李四
  2528. //选择[前加签],意见:请处理,加签人:赵六
  2529. //保留待办,意见:请处理,重置给:王五
  2530. var text, orgtexts = [], lp = this.flow.lp;
  2531. switch (d.action) {
  2532. case "process":
  2533. Object.each( d.organizations, function (value, key) {
  2534. if( value && value.length ){
  2535. orgtexts.push( ( this.flow.getSingleOrgConfig( d.routeId , key ) ).title + ":" + value.clean().map(function(v){ return v.split("@")[0]; }).join("、"));
  2536. }
  2537. }.bind(this));
  2538. text = lp.submitQuickText.replace("{route}", d.routeName ).replace("{opinion}", d.opinion);
  2539. if( !orgtexts.length ){
  2540. return text.replace("{org}", "");
  2541. }else{
  2542. return text.replace("{org}", "," + orgtexts.join(",") );
  2543. }
  2544. case "addTask":
  2545. if( d.organizations && d.organizations.default ){
  2546. orgtexts.push( d.organizations.default.clean().map(function(v){ return v.split("@")[0]; }).join("、") );
  2547. }
  2548. var route = d.routeId === "before" ? lp.addTaskBefore : lp.addTaskAfter;
  2549. var mode = lp[ d.routeGroup ] || "";
  2550. return lp.addTaskQuickText.replace("{route}", route ).replace("{mode}", mode).replace("{opinion}", d.opinion).replace("{org}", orgtexts.join(",") );
  2551. case "reset":
  2552. if( d.organizations && d.organizations.default ){
  2553. orgtexts.push( d.organizations.default.clean().map(function(v){ return v.split("@")[0]; }).join("、") );
  2554. }
  2555. return lp.resetQuickText.replace("{opinion}", d.opinion).replace("{org}", orgtexts.join(",") );
  2556. //return lp.resetQuickText.replace("{flag}", d.keepTask ? "" : lp.not ).replace("{opinion}", d.opinion).replace("{org}", orgtexts.join(",") );
  2557. }
  2558. },
  2559. saveData: function () {
  2560. debugger;
  2561. var work = this.flow.form.businessData.work || this.flow.form.businessData.workCompleted;
  2562. var d = {
  2563. process: work.process,
  2564. processName: work.processName,
  2565. activity: work.activity,
  2566. activityName: work.activityName,
  2567. activityAlias: work.activityAlias,
  2568. action: this.flow.currentAction
  2569. };
  2570. // routeId: "",
  2571. // routeName: "",
  2572. // routeGroup:决策组.
  2573. // keepTask:是否保留待办.
  2574. // opinion:意见.
  2575. // organizations:人员组织列表.
  2576. var quickData = {};
  2577. switch ( this.flow.currentAction ) {
  2578. case "process":
  2579. quickData = this.flow.processor.getQuickData();
  2580. break;
  2581. case "addTask":
  2582. quickData = this.flow.addTask.getQuickData();
  2583. break;
  2584. case "reset":
  2585. quickData = this.flow.reset.getQuickData();
  2586. break;
  2587. }
  2588. d = Object.merge(d, quickData);
  2589. o2.Actions.load("x_processplatform_assemble_surface").TaskProcessModeAction.saveMode( d, null, null, false );
  2590. },
  2591. });
  2592. MWF.ProcessFlow.widget.Opinion = new Class({
  2593. Implements: [Options, Events],
  2594. options: {
  2595. isHandwriting: false,
  2596. opinion: "",
  2597. tabletToolHidden: [],
  2598. tabletWidth: 0,
  2599. tabletHeight: 0
  2600. },
  2601. initialize: function( container, flow, options ){
  2602. this.setOptions( options );
  2603. this.container = container;
  2604. this.flow = flow;
  2605. this.lp = flow.lp;
  2606. },
  2607. load: function(){
  2608. this.loadData( function () {
  2609. this.loadDom();
  2610. }.bind(this));
  2611. },
  2612. loadData: function ( callback ) {
  2613. MWF.require("MWF.widget.UUID", function () {
  2614. MWF.UD.getDataJson("idea", function (json) {
  2615. if (json) {
  2616. if (json.ideas) {
  2617. this.opinionList = json.ideas;
  2618. if(callback)callback();
  2619. }else{
  2620. this.opinionList = [];
  2621. if(callback)callback();
  2622. }
  2623. } else {
  2624. MWF.UD.getPublicData("idea", function (pjson) {
  2625. if (pjson && pjson.ideas) {
  2626. this.opinionList = pjson.ideas;
  2627. if(callback)callback();
  2628. }else{
  2629. this.opinionList = [];
  2630. if(callback)callback();
  2631. }
  2632. }.bind(this));
  2633. }
  2634. }.bind(this));
  2635. }.bind(this));
  2636. },
  2637. loadDom: function(){
  2638. var url = this.flow.path+this.flow.options.style+"/widget/opinion.html";
  2639. this.container.loadHtml(url, {
  2640. "bind": {
  2641. "lp": this.lp, "opinionList": this.opinionList, "opinion": this.options.opinion || ""
  2642. },
  2643. "module": this
  2644. }, function(){
  2645. if( this.options.isHandwriting )this.handwritingButton.show();
  2646. this.opinionTextarea.addEvent("change", function () {
  2647. this.removeRequireStyle();
  2648. }.bind(this));
  2649. this.loaded = true;
  2650. this.fireEvent("load");
  2651. }.bind(this)
  2652. );
  2653. },
  2654. setRequireStyle: function(){
  2655. this.opinionTextarea.addClass("o2flow-invalid-bg");
  2656. },
  2657. removeRequireStyle: function(){
  2658. if(this.opinionTextarea.hasClass("o2flow-invalid-bg")){
  2659. this.opinionTextarea.removeClass("o2flow-invalid-bg");
  2660. }
  2661. },
  2662. getValue: function(){
  2663. return this.opinionTextarea.get("value");
  2664. },
  2665. setValue: function( value ){
  2666. this.opinionTextarea.set("value", value);
  2667. },
  2668. selectOpinion: function( opinion ){
  2669. var op = this.opinionTextarea.get("value");
  2670. if ( !op ) {
  2671. this.opinionTextarea.set("value", opinion );
  2672. } else {
  2673. this.opinionTextarea.set("value", op + ", " + opinion );
  2674. }
  2675. this.removeRequireStyle();
  2676. },
  2677. overItemNode: function (ev) {
  2678. ev.target.addClass("o2flow-bg-opacity");
  2679. if( this.flow.options.mainColorEnable ){
  2680. ev.target.addClass("mainColor_bg_opacity");
  2681. }
  2682. },
  2683. outItemNode: function (ev) {
  2684. ev.target.removeClass("o2flow-bg-opacity");
  2685. if( this.flow.options.mainColorEnable ) {
  2686. ev.target.removeClass("mainColor_bg_opacity");
  2687. }
  2688. },
  2689. handwriting: function () {
  2690. if( !this.tablet )this.createHandwriting();
  2691. this.handwritingMask.show();
  2692. this.handwritingNode.show();
  2693. this.handwritingNode.position({
  2694. "relativeTo": this.flow.node,
  2695. "position": "center",
  2696. "edge": "center"
  2697. });
  2698. },
  2699. createHandwriting: function () {
  2700. this.handwritingMask.inject( this.flow.node );
  2701. this.handwritingNode.show().inject(this.flow.node, "after");
  2702. //兼容以前的默认高宽
  2703. var x = 600;
  2704. var y = 320;
  2705. x = Math.max(this.options.tabletWidth || x, 600);
  2706. this.options.tabletWidth = x;
  2707. y = Math.max(this.options.tabletHeight ? (parseInt(this.options.tabletHeight) + 110) : y, 320);
  2708. var zidx = this.flow.node.getStyle("z-index");
  2709. this.handwritingNode.setStyles({
  2710. "height": "" + y + "px",
  2711. "width": "" + x + "px",
  2712. "z-index": zidx + 1
  2713. });
  2714. this.handwritingNode.position({
  2715. "relativeTo": this.flow.node,
  2716. "position": "center",
  2717. "edge": "center"
  2718. });
  2719. if( this.flow.options.mainColorEnable )this.handwritingSaveNode.addClass("mainColor_bg");
  2720. var h = this.handwritingSaveNode.getSize().y + this.flow.getOffsetY(this.handwritingSaveNode);
  2721. this.handwritingAreaNode.setStyle("height", "" + ( y - h ) + "px");
  2722. MWF.require("MWF.widget.Tablet", function () {
  2723. var handWritingOptions = this.getHandWritingOptions();
  2724. this.tablet = new MWF.widget.Tablet(this.handwritingAreaNode, handWritingOptions, null);
  2725. this.tablet.load();
  2726. }.bind(this));
  2727. },
  2728. getHandWritingOptions: function(){
  2729. return {
  2730. "style": "default",
  2731. "toolHidden": this.options.tabletToolHidden || [],
  2732. "contentWidth": this.options.tabletWidth || 0,
  2733. "contentHeight": this.options.tabletHeight || 0,
  2734. "iconfontEnable": true,
  2735. "mainColorEnable": this.flow.options.mainColorEnable,
  2736. "onSave": function (base64code, base64Image, imageFile) {
  2737. if( !this.tablet.isBlank() ){
  2738. this.handwritingFile = imageFile;
  2739. this.handwritingButton.getElement("i").removeClass("o2icon-edit2").
  2740. addClass("o2icon-checkbox").addClass("o2flow-handwriting-buttonok");
  2741. this.removeRequireStyle();
  2742. }else{
  2743. this.handwritingFile = null;
  2744. this.handwritingButton.getElement("i").addClass("o2icon-edit2").
  2745. removeClass("o2icon-checkbox").removeClass("o2flow-handwriting-buttonok");
  2746. }
  2747. this.handwritingNode.hide();
  2748. this.handwritingMask.hide();
  2749. }.bind(this),
  2750. "onCancel": function () {
  2751. this.handwritingFile = null;
  2752. this.handwritingButton.getElement("i").addClass("o2icon-edit2").
  2753. removeClass("o2icon-checkbox").removeClass("o2flow-handwriting-buttonok");
  2754. this.handwritingNode.hide();
  2755. this.handwritingMask.hide();
  2756. }.bind(this)
  2757. };
  2758. },
  2759. saveTablet: function () {
  2760. if (this.tablet) this.tablet.save();
  2761. }
  2762. });
  2763. MWF.ProcessFlow.widget.Radio = new Class({
  2764. Implements: [Options, Events],
  2765. options: {
  2766. optionList: [],
  2767. value: null,
  2768. cancelEnable: true
  2769. },
  2770. initialize: function( container, flow, options ){
  2771. this.container = container;
  2772. this.flow = flow;
  2773. this.lp = flow.lp;
  2774. this.setOptions( options );
  2775. },
  2776. load: function(){
  2777. this.checkedItems = [];
  2778. this.container.loadHtml(this.getUrl(), {"bind": {"lp": this.lp, "optionList": this.options.optionList}, "module": this}, function(){
  2779. if( this.options.value !== null )this.setValue( this.options.value );
  2780. this.fireEvent("load");
  2781. }.bind(this));
  2782. },
  2783. getUrl: function(){
  2784. return this.flow.path+this.flow.options.style+"/widget/radio.html";
  2785. },
  2786. setValue: function( values ){
  2787. while( this.checkedItems.length ){
  2788. this.uncheck( this.checkedItems[0] );
  2789. }
  2790. if( typeOf( values ) === "null" )return;
  2791. values = typeOf( values ) === "array" ? values : [values];
  2792. this.container.getElements(".o2flow-radio").each(function (el) {
  2793. if(values.contains( el.dataset["o2Value"] )){
  2794. this.check(el)
  2795. }
  2796. }.bind(this))
  2797. },
  2798. getData: function( value ){
  2799. if( !value )value = this.getValue();
  2800. var arr = this.options.optionList.filter(function (o) {
  2801. return o.value === value;
  2802. });
  2803. return arr[0] || null;
  2804. },
  2805. getValue: function(){
  2806. var data = this.checkedItems.map(function (item) {
  2807. return item.dataset["o2Value"];
  2808. });
  2809. return data[0] || null;
  2810. },
  2811. getText: function(){
  2812. var data = this.checkedItems.map(function (item) {
  2813. return item.dataset["o2Text"];
  2814. });
  2815. return data[0] || null;
  2816. },
  2817. toggle: function( ev ){
  2818. var el = this.flow.getEl(ev, "o2flow-radio");
  2819. if( this.checkedItems.contains( el ) ){
  2820. if( this.options.cancelEnable )this.uncheck( el, true )
  2821. }else{
  2822. this.check( el )
  2823. }
  2824. },
  2825. check: function(el){
  2826. while( this.checkedItems.length ){
  2827. this.uncheck( this.checkedItems[0] );
  2828. }
  2829. el.addClass("o2flow-radio-active");
  2830. if( this.flow.options.mainColorEnable )el.addClass("mainColor_bg");
  2831. el.getElement("i").removeClass("o2icon-icon_circle").addClass("o2icon-checkbox").addClass("o2flow-radio-icon");
  2832. el.dataset["o2Checked"] = true;
  2833. this.checkedItems.push(el);
  2834. this.removeRequireStyle();
  2835. this.fireEvent("check", [el, el.dataset["o2Value"]])
  2836. },
  2837. uncheck: function(el, isFire){
  2838. el.removeClass("o2flow-radio-active");
  2839. if( this.flow.options.mainColorEnable )el.removeClass("mainColor_bg");
  2840. el.getElement("i").removeClass("o2icon-checkbox").addClass("o2icon-icon_circle").removeClass("o2flow-radio-icon");
  2841. el.dataset["o2Checked"] = false;
  2842. this.checkedItems.erase(el);
  2843. if(isFire)this.fireEvent("uncheck", [el, el.dataset["o2Value"]])
  2844. },
  2845. setRequireStyle: function(){
  2846. this.container.addClass("o2flow-invalid-bg");
  2847. },
  2848. removeRequireStyle: function(){
  2849. if(this.container.hasClass("o2flow-invalid-bg")){
  2850. this.container.removeClass("o2flow-invalid-bg");
  2851. }
  2852. },
  2853. // over: function (ev) {
  2854. // var el = this.flow.getEl(ev, "o2flow-radio");
  2855. // if( !el.dataset["o2Checked"] ){
  2856. // el.getElement("i").addClass("o2flow-radio-over");
  2857. // }
  2858. // },
  2859. // out: function (ev) {
  2860. // var el = this.flow.getEl(ev, "o2flow-radio");
  2861. // el.getElement("i").removeClass("o2flow-radio-over")
  2862. // }
  2863. });
  2864. MWF.ProcessFlow.widget.Radio2 = new Class({
  2865. Extends: MWF.ProcessFlow.widget.Radio,
  2866. options: {
  2867. optionList: [],
  2868. value: null,
  2869. cancelEnable: true,
  2870. activeIcon: "o2icon-radio-checked"
  2871. },
  2872. getUrl: function(){
  2873. return this.flow.path+this.flow.options.style+"/widget/radio2.html";
  2874. },
  2875. setValue: function( values ){
  2876. while( this.checkedItems.length ){
  2877. this.uncheck( this.checkedItems[0] );
  2878. }
  2879. values = typeOf( values ) === "array" ? values : [values];
  2880. this.container.getElements(".o2flow-radio2").each(function (el) {
  2881. if(values.contains( el.dataset["o2Value"] ))this.check(el)
  2882. }.bind(this))
  2883. },
  2884. toggle: function( ev ){
  2885. var el = this.flow.getEl(ev, "o2flow-radio2");
  2886. if( this.checkedItems.contains( el ) ){
  2887. if( this.options.cancelEnable )this.uncheck( el, true )
  2888. }else{
  2889. this.check( el )
  2890. }
  2891. },
  2892. check: function(el){
  2893. while( this.checkedItems.length ){
  2894. this.uncheck( this.checkedItems[0] );
  2895. }
  2896. el.addClass("o2flow-radio2-active");
  2897. if( this.flow.options.mainColorEnable )el.addClass("mainColor_color");
  2898. el.getElement("i").removeClass("o2icon-icon_circle").addClass(this.options.activeIcon).addClass("o2flow-radio2-icon");
  2899. if( this.flow.options.mainColorEnable )el.getElement("i").addClass("mainColor_color");
  2900. el.dataset["o2Checked"] = true;
  2901. this.checkedItems.push(el);
  2902. this.removeRequireStyle();
  2903. this.fireEvent("check", [el, el.dataset["o2Value"]])
  2904. },
  2905. uncheck: function(el, isFire){
  2906. el.removeClass("o2flow-radio2-active");
  2907. if( this.flow.options.mainColorEnable )el.removeClass("mainColor_color");
  2908. el.getElement("i").removeClass(this.options.activeIcon).addClass("o2icon-icon_circle").removeClass("o2flow-radio2-icon");
  2909. if( this.flow.options.mainColorEnable )el.getElement("i").removeClass("mainColor_color");
  2910. el.dataset["o2Checked"] = false;
  2911. this.checkedItems.erase(el);
  2912. if(isFire)this.fireEvent("uncheck", [el, el.dataset["o2Value"]])
  2913. }
  2914. });
  2915. MWF.ProcessFlow.widget.Checkbox = new Class({
  2916. Implements: [Options, Events],
  2917. options: {
  2918. optionList: [],
  2919. values: []
  2920. },
  2921. initialize: function( container, flow, options ){
  2922. this.container = container;
  2923. this.flow = flow;
  2924. this.lp = flow.lp;
  2925. this.setOptions( options );
  2926. },
  2927. load: function(){
  2928. this.checkedItems = [];
  2929. this.container.loadHtml(this.getUrl(), {"bind": {"lp": this.lp, "optionList": this.options.optionList}, "module": this}, function(){
  2930. if( this.options.values.length )this.setValue( this.options.values );
  2931. this.fireEvent("load");
  2932. }.bind(this));
  2933. },
  2934. getUrl: function(){
  2935. return this.flow.path+this.flow.options.style+"/widget/checkbox.html";
  2936. },
  2937. setValue: function( values ){
  2938. while( this.checkedItems.length ){
  2939. this.uncheck( this.checkedItems[0] );
  2940. }
  2941. values = typeOf( values ) === "array" ? values : [values];
  2942. this.container.getElements(".o2flow-radio").each(function (el) {
  2943. if(values.contains( el.dataset["o2Value"] )){
  2944. this.check(el)
  2945. }
  2946. }.bind(this))
  2947. },
  2948. getData: function( value ){
  2949. if( !value )value = this.getValue();
  2950. value = typeOf( value ) === "array" ? value : [value];
  2951. var arr = this.options.optionList.filter(function (o) {
  2952. return value.contains(o.value);
  2953. });
  2954. return arr;
  2955. },
  2956. getValue: function(){
  2957. return this.checkedItems.map(function (item) {
  2958. return item.dataset["o2Value"];
  2959. });
  2960. },
  2961. getText: function(){
  2962. return this.checkedItems.map(function (item) {
  2963. return item.dataset["o2Text"];
  2964. });
  2965. },
  2966. toggle: function( ev ){
  2967. var el = this.flow.getEl(ev, "o2flow-radio");
  2968. if( this.checkedItems.contains( el ) ){
  2969. this.uncheck( el, true )
  2970. }else{
  2971. this.check( el )
  2972. }
  2973. },
  2974. check: function(el){
  2975. el.addClass("o2flow-radio-active");
  2976. if( this.flow.options.mainColorEnable )el.addClass("mainColor_bg");
  2977. el.getElement("i").removeClass("o2icon-icon_circle").addClass("o2icon-checkbox").addClass("o2flow-radio-icon");
  2978. el.dataset["o2Checked"] = true;
  2979. this.checkedItems.push(el);
  2980. this.removeRequireStyle();
  2981. this.fireEvent("check", [el, el.dataset["o2Value"]])
  2982. },
  2983. uncheck: function(el, isFire){
  2984. el.removeClass("o2flow-radio-active");
  2985. if( this.flow.options.mainColorEnable )el.removeClass("mainColor_bg");
  2986. el.getElement("i").removeClass("o2icon-checkbox").addClass("o2icon-icon_circle").removeClass("o2flow-radio-icon");
  2987. el.dataset["o2Checked"] = false;
  2988. this.checkedItems.erase(el);
  2989. if(isFire)this.fireEvent("uncheck", [el, el.dataset["o2Value"]])
  2990. },
  2991. checkAll: function(){
  2992. this.container.getElements(".o2flow-radio").each(function (el) {
  2993. this.check(el)
  2994. }.bind(this))
  2995. },
  2996. uncheckAll: function(){
  2997. this.container.getElements(".o2flow-radio").each(function (el) {
  2998. this.uncheck(el)
  2999. }.bind(this))
  3000. },
  3001. getUncheckData: function(){
  3002. var value = this.getValue();
  3003. return this.options.optionList.filter(function (o) {
  3004. return !value.contains(o.value);
  3005. });
  3006. },
  3007. setRequireStyle: function(){
  3008. this.container.addClass("o2flow-invalid-bg");
  3009. },
  3010. removeRequireStyle: function(){
  3011. if(this.container.hasClass("o2flow-invalid-bg")){
  3012. this.container.removeClass("o2flow-invalid-bg");
  3013. }
  3014. }
  3015. });