Processor.js 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236
  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.xDesktop.requireApp("process.Xform", "Org", null, false);
  5. MWF.xApplication.process.Work.Processor = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "mediaNode": null,
  11. "opinion": "",
  12. "tabletWidth" : 0,
  13. "tabletHeight" : 0,
  14. "orgHeight" : 276,
  15. "maxOrgCountPerline" : 2
  16. },
  17. initialize: function(node, task, options, form){
  18. this.setOptions(options);
  19. this.path = "/x_component_process_Work/$Processor/";
  20. this.cssPath = "/x_component_process_Work/$Processor/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.task = task;
  23. this.node = $(node);
  24. this.selectedRoute = null;
  25. this.form = form;
  26. this.load();
  27. },
  28. load: function(){
  29. this.routeOpinionTile = new Element("div", {"styles": this.css.routeOpinionTile, "text": MWF.xApplication.process.Work.LP.inputOpinion}).inject(this.node);
  30. this.routeOpinionArea = new Element("div", {"styles": this.css.routeOpinionArea}).inject(this.node);
  31. this.setOpinion();
  32. if( layout.mobile ){
  33. this.orgsArea = new Element("div", {"styles": this.css.orgsArea}).inject(this.node);
  34. this.orgsTile = new Element("div", {"styles": this.css.orgsTitle, "text": MWF.xApplication.process.Work.LP.selectPerson}).inject(this.orgsArea);
  35. this.orgsArea.hide()
  36. }else{
  37. this.orgsArea = new Element("div", {"styles": this.css.orgsArea}).inject(this.node);
  38. this.orgsTile = new Element("div", {"styles": this.css.orgsTitle, "text": MWF.xApplication.process.Work.LP.selectPerson}).inject(this.orgsArea);
  39. }
  40. this.buttonsArea = new Element("div", {"styles": this.css.buttonsArea}).inject(this.node);
  41. this.setButtons();
  42. if( layout.mobile ){
  43. this.routeSelectorTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute}).inject(this.routeOpinionTile, "before");
  44. this.routeSelectorArea = new Element("div", {"styles": this.css.routeSelectorArea}).inject(this.routeSelectorTile, "after");
  45. this.setRouteList();
  46. }else{
  47. this.getRouteGroupList();
  48. if( this.hasDecisionOpinion ){
  49. //if( this.getMaxOrgLength() > 1 ){
  50. this.routeContainer = new Element("div", {
  51. "styles" : this.css.routeContainer
  52. }).inject(this.routeOpinionTile, "before");
  53. this.routeLeftWarper = new Element("div", { "styles":
  54. this.getMaxOrgLength() > 1 ? this.css.routeLeftWarper : this.css.routeLeftWarper_single
  55. }).inject(this.routeContainer);
  56. this.routeGroupTitle = new Element("div", { "styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRouteGroup }).inject(this.routeLeftWarper);
  57. this.routeGroupArea = new Element("div", { "styles": this.css.routeSelectorArea_hasGroup }).inject(this.routeLeftWarper);
  58. this.routeRightWarper = new Element("div", { "styles":
  59. this.getMaxOrgLength() > 1 ? this.css.routeRightWarper : this.css.routeRightWarper_single
  60. }).inject(this.routeContainer);
  61. this.routeSelectorTile = new Element("div", { "styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute }).inject(this.routeRightWarper);
  62. this.routeSelectorArea = new Element("div", { "styles": this.css.routeSelectorArea_hasGroup }).inject(this.routeRightWarper);
  63. this.setRouteGroupList();
  64. //}else{
  65. // this.routeGroupTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute }).inject(this.routeOpinionTile, "before");
  66. // this.routeGroupArea = new Element("div", {"styles": this.css.routeSelectorArea_hasGroup_wide }).inject(this.routeGroupTile, "after");
  67. // this.setRouteGroupList();
  68. //}
  69. }else{
  70. this.routeSelectorTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute}).inject(this.routeOpinionTile, "before");
  71. this.routeSelectorArea = new Element("div", {"styles": this.css.routeSelectorArea}).inject(this.routeSelectorTile, "after");
  72. this.setRouteList();
  73. }
  74. }
  75. this.fireEvent("postLoad");
  76. },
  77. getRouteGroupList : function(){
  78. if( this.routeGroupObject )return this.routeGroupObject;
  79. this.routeGroupObject = {};
  80. this.routeGroupNameList = [];
  81. this.hasDecisionOpinion = false;
  82. var routeList = this.getRouteDataList();
  83. routeList.each(function(route, i){
  84. if( route.hiddenScriptText ){ //如果隐藏路由,返回
  85. if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
  86. }
  87. if( route.displayNameScriptText ){ //如果有显示名称公式
  88. route.displayName = this.form.Macro.exec(route.displayNameScriptText, this);
  89. }else{
  90. route.displayName = route.name;
  91. }
  92. if( route.decisionOpinion ){
  93. this.hasDecisionOpinion = true;
  94. var decisionOpinionList = route.decisionOpinion.split("#");
  95. decisionOpinionList.each( function( decisionOption ){
  96. this.routeGroupNameList.combine( [decisionOption] );
  97. var d = this.splitByStartNumber( decisionOption );
  98. if( !this.routeGroupObject[ d.name ] )this.routeGroupObject[ d.name ] = [];
  99. this.routeGroupObject[ d.name ].push( route );
  100. }.bind(this))
  101. }else{
  102. var defaultName = MWF.xApplication.process.Work.LP.defaultDecisionOpinionName;
  103. this.routeGroupNameList.combine( [defaultName] );
  104. if( !this.routeGroupObject[ defaultName ] )this.routeGroupObject[ defaultName ] = [];
  105. this.routeGroupObject[ defaultName].push( route );
  106. }
  107. }.bind(this));
  108. return this.routeGroupObject;
  109. },
  110. splitByStartNumber : function( str ){
  111. var obj = {
  112. name : "",
  113. order : ""
  114. };
  115. for( var i=0; i<str.length; i++ ){
  116. if( parseInt(str.substr(i,1)).toString() !== "NaN" ){
  117. obj.order = obj.order + str.substr(i,1);
  118. }else{
  119. obj.name = str.substr( i, str.length );
  120. break;
  121. }
  122. }
  123. return obj;
  124. },
  125. setRouteGroupList : function(){
  126. var _self = this;
  127. //var keys = Object.keys( this.routeGroupObject );
  128. //var length = keys.length;
  129. //var sortArray = MWF.xApplication.process.Work.LP.routeGroupOrderList;
  130. //keys.sort( function( a, b ){
  131. // var aIdx = sortArray.indexOf(a);
  132. // var bIdx = sortArray.indexOf(b);
  133. // if( aIdx === -1 )aIdx = sortArray.length;
  134. // if( bIdx === -1 )aIdx = sortArray.length;
  135. // return aIdx - bIdx;
  136. //});
  137. var keys = this.routeGroupNameList;
  138. keys.sort( function( a, b ){
  139. var aIdx = parseInt(this.splitByStartNumber( a ).order || "9999999");
  140. var bIdx = parseInt(this.splitByStartNumber( b ).order || "9999999");
  141. return aIdx - bIdx;
  142. }.bind(this));
  143. var list = [];
  144. keys.each( function( k ){
  145. list.push( this.splitByStartNumber( k).name )
  146. }.bind(this))
  147. list.each( function( routeGroupName ){
  148. var routeList = this.routeGroupObject[routeGroupName];
  149. var routeGroupNode = new Element("div", {"styles": this.css.routeGroupNode, "text": routeGroupName}).inject(this.routeGroupArea);
  150. routeGroupNode.store( "routeList", routeList );
  151. routeGroupNode.store( "routeGroupName", routeGroupName );
  152. routeGroupNode.addEvents({
  153. "mouseover": function(e){_self.overRouteGroup(this);},
  154. "mouseout": function(e){_self.outRouteGroup(this);},
  155. "click": function(e){_self.selectRouteGroup(this);}
  156. });
  157. if ( length === 1 ){
  158. this.selectRouteGroup(routeGroupNode);
  159. }else{
  160. this.setSize(0);
  161. }
  162. }.bind(this))
  163. },
  164. overRouteGroup: function(node){
  165. if (this.selectedRouteGroup){
  166. if (this.selectedRouteGroup.get("text") != node.get("text")){
  167. node.setStyles(this.css.routeGroupNode_over);
  168. }
  169. }else{
  170. node.setStyles(this.css.routeGroupNode_over);
  171. }
  172. },
  173. outRouteGroup: function(node){
  174. if (this.selectedRouteGroup){
  175. if (this.selectedRouteGroup.get("text") != node.get("text")){
  176. node.setStyles(this.css.routeGroupNode);
  177. }
  178. }else{
  179. node.setStyles(this.css.routeGroupNode);
  180. }
  181. },
  182. selectRouteGroup: function(node){
  183. if (this.selectedRouteGroup){
  184. if (this.selectedRouteGroup.get("text") != node.get("text")){
  185. this.selectedRouteGroup.setStyles(this.css.routeGroupNode);
  186. this.selectedRouteGroup = node;
  187. this.selectedRouteGroup.setStyles(this.css.routeGroupNode_selected);
  188. var routeList = this.selectedRouteGroup.retrieve("routeList");
  189. this.setRouteList( routeList );
  190. }else{
  191. //this.selectedRouteGroup.setStyles(this.css.routeNode);
  192. //this.selectedRouteGroup.getFirst().setStyles(this.css.routeIconNode);
  193. //this.selectedRouteGroup.getLast().setStyles(this.css.routeTextNode);
  194. //
  195. //this.selectedRouteGroup = null;
  196. }
  197. }else{
  198. this.selectedRouteGroup = node;
  199. node.setStyles(this.css.routeGroupNode_selected);
  200. var routeList = this.selectedRouteGroup.retrieve("routeList");
  201. this.setRouteList( routeList );
  202. }
  203. this.routeGroupArea.setStyle("background-color", "#FFF");
  204. },
  205. setRouteList: function( routeList ){
  206. var _self = this;
  207. //if( this.hasDecisionOpinion && this.getMaxOrgLength() === 1 ){
  208. // if( this.routeSelectorArea )this.routeSelectorArea.destroy();
  209. // this.routeSelectorArea = new Element("div", { styles : this.css.routeSelectorArea_hasGroup_single }).inject( this.selectedRouteGroup, "after" );
  210. //}else{
  211. this.routeSelectorArea.empty();
  212. //}
  213. this.selectedRoute = null;
  214. //this.task.routeNameList = ["送审核", "送办理", "送公司领导阅"];
  215. if( !routeList )routeList = this.getRouteDataList();
  216. //this.task.routeNameList.each(function(route, i){
  217. routeList.each(function(route, i){
  218. if( route.hiddenScriptText ){
  219. if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
  220. }
  221. var routeName = route.name;
  222. if( route.displayNameScriptText ){
  223. routeName = this.form.Macro.exec(route.displayNameScriptText, this);
  224. }
  225. var routeNode = new Element("div", {"styles": this.css.routeNode, "text": routeName}).inject(this.routeSelectorArea);
  226. //var routeIconNode = new Element("div", {"styles": this.css.routeIconNode}).inject(routeNode);
  227. //var routeTextNode = new Element("div", {"styles": this.css.routeTextNode, "text": routeName}).inject(routeNode);
  228. routeNode.store( "route", route.id );
  229. routeNode.store( "routeName", route.name );
  230. routeNode.addEvents({
  231. "mouseover": function(e){_self.overRoute(this);},
  232. "mouseout": function(e){_self.outRoute(this);},
  233. "click": function(e){_self.selectRoute(this);}
  234. });
  235. if (routeList.length==1){
  236. this.selectRoute(routeNode);
  237. }else{
  238. this.setSize(0);
  239. }
  240. }.bind(this));
  241. },
  242. overRoute: function(node){
  243. if (this.selectedRoute){
  244. if (this.selectedRoute.get("text") != node.get("text")){
  245. node.setStyles(this.css.routeNode_over);
  246. //node.setStyle("background-color", "#f7e1d0");
  247. }
  248. }else{
  249. node.setStyles(this.css.routeNode_over);
  250. }
  251. },
  252. outRoute: function(node){
  253. if (this.selectedRoute){
  254. if (this.selectedRoute.get("text") != node.get("text")){
  255. node.setStyles(this.css.routeNode);
  256. }
  257. }else{
  258. node.setStyles(this.css.routeNode);
  259. }
  260. },
  261. selectRoute: function(node){
  262. if (this.selectedRoute){
  263. if (this.selectedRoute.get("text") != node.get("text")){
  264. this.selectedRoute.setStyles(this.css.routeNode);
  265. //this.selectedRoute.getFirst().setStyles(this.css.routeIconNode);
  266. //this.selectedRoute.getLast().setStyles(this.css.routeTextNode);
  267. this.selectedRoute = node;
  268. node.setStyles(this.css.routeNode_selected);
  269. //node.setStyle("background-color", "#da7429");
  270. //node.getFirst().setStyle("background-image", "url("+"/x_component_process_Work/$Processor/default/checked.png)");
  271. //node.getLast().setStyle("color", "#FFF");
  272. }else{
  273. this.selectedRoute.setStyles(this.css.routeNode);
  274. //this.selectedRoute.getFirst().setStyles(this.css.routeIconNode);
  275. //this.selectedRoute.getLast().setStyles(this.css.routeTextNode);
  276. this.selectedRoute = null;
  277. }
  278. }else{
  279. this.selectedRoute = node;
  280. node.setStyles(this.css.routeNode_selected);
  281. //node.setStyle("background-color", "#da7429");
  282. //node.getFirst().setStyle("background-image", "url("+"/x_component_process_Work/$Processor/default/checked.png)");
  283. //node.getLast().setStyle("color", "#FFF");
  284. }
  285. this.routeSelectorArea.setStyle("background-color", "#FFF");
  286. if( layout.mobile ){
  287. this.loadOrgs_mobile( this.selectedRoute ? this.selectedRoute.retrieve("route") : "" );
  288. }else{
  289. this.loadOrgs( this.selectedRoute ? this.selectedRoute.retrieve("route") : "" );
  290. }
  291. //临时添加
  292. if(this.form.data.json.events.afterSelectRoute){
  293. this.form.Macro.exec(this.form.data.json.events.afterSelectRoute.code, node);
  294. }
  295. },
  296. setOpinion: function(){
  297. this.selectIdeaNode = new Element("div", {"styles": this.css.selectIdeaNode}).inject(this.routeOpinionArea);
  298. this.selectIdeaScrollNode = new Element("div", {"styles": this.css.selectIdeaScrollNode}).inject(this.selectIdeaNode);
  299. this.selectIdeaAreaNode = new Element("div", {"styles": {
  300. "overflow": "hidden"
  301. }}).inject(this.selectIdeaScrollNode);
  302. this.inputOpinionNode = new Element("div", {"styles": this.css.inputOpinionNode}).inject(this.routeOpinionArea);
  303. this.inputTextarea = new Element("textarea", {"styles": this.css.inputTextarea, "value": this.options.opinion || MWF.xApplication.process.Work.LP.inputText}).inject(this.inputOpinionNode);
  304. this.inputTextarea.addEvents({
  305. "focus": function(){if (this.get("value")==MWF.xApplication.process.Work.LP.inputText) this.set("value", "");},
  306. "blur": function(){if (!this.get("value")) this.set("value", MWF.xApplication.process.Work.LP.inputText);},
  307. "keydown": function(){this.inputTextarea.setStyles( this.inputTextareaStyle || this.css.inputTextarea);}.bind(this)
  308. });
  309. this.mediaActionArea = new Element("div", {"styles": this.css.inputOpinionMediaActionArea}).inject(this.inputOpinionNode);
  310. this.handwritingAction = new Element("div", {"styles": this.css.inputOpinionHandwritingAction, "text": MWF.xApplication.process.Work.LP.handwriting}).inject(this.mediaActionArea);
  311. this.handwritingAction.addEvent("click", function(){
  312. this.handwriting();
  313. }.bind(this));
  314. // if (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia){
  315. // this.audioRecordAction = new Element("div", {"styles": this.css.inputOpinionAudioRecordAction, "text": MWF.xApplication.process.Work.LP.audioRecord}).inject(this.mediaActionArea);
  316. // this.audioRecordAction.addEvent("click", function(){
  317. // this.audioRecord();
  318. // }.bind(this));
  319. // }
  320. if (layout.mobile){
  321. this.selectIdeaNode.inject(this.routeOpinionArea, "after");
  322. }
  323. MWF.require("MWF.widget.ScrollBar", function(){
  324. new MWF.widget.ScrollBar(this.selectIdeaScrollNode, {
  325. "style":"small", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  326. });
  327. }.bind(this));
  328. MWF.require("MWF.widget.UUID", function(){
  329. MWF.UD.getDataJson("idea", function(json){
  330. if (json){
  331. if (json.ideas){
  332. this.setIdeaList(json.ideas);
  333. }
  334. }else{
  335. MWF.UD.getPublicData("idea", function(pjson){
  336. if (pjson){
  337. if (pjson.ideas){
  338. this.setIdeaList(pjson.ideas);
  339. }
  340. }
  341. }.bind(this));
  342. }
  343. }.bind(this));
  344. }.bind(this));
  345. },
  346. audioRecord: function(){
  347. if (!this.audioRecordNode) this.createAudioRecord();
  348. this.audioRecordNode.show();
  349. this.audioRecordNode.position({
  350. "relativeTo": this.options.mediaNode || this.node,
  351. "position": "center",
  352. "edge": "center"
  353. });
  354. MWF.require("MWF.widget.AudioRecorder", function () {
  355. this.audioRecorder = new MWF.widget.AudioRecorder(this.audioRecordNode, {
  356. "onSave" : function( blobFile ){
  357. this.soundFile = blobFile;
  358. this.audioRecordNode.hide();
  359. // this.page.get("div_image").node.set("src",base64Image);
  360. }.bind(this),
  361. "onCancel": function(){
  362. this.soundFile = null;
  363. this.audioRecordNode.hide();
  364. }.bind(this)
  365. }, null );
  366. }.bind(this));
  367. },
  368. createAudioRecord: function(){
  369. this.audioRecordNode = new Element("div", {"styles": this.css.handwritingNode}).inject(this.node, "after");
  370. var size = (this.options.mediaNode || this.node).getSize();
  371. // var y = Math.max(size.y, 320);
  372. // var x = Math.max(size.x, 400);
  373. // for (k in this.node.style){
  374. // if (this.node.style[k]) this.audioRecordNode.style[k] = this.node.style[k];
  375. // }
  376. var zidx = this.node.getStyle("z-index");
  377. this.audioRecordNode.setStyles({
  378. "height": ""+size.y+"px",
  379. "width": ""+size.x+"px",
  380. "z-index": zidx+1
  381. });
  382. },
  383. handwriting: function(){
  384. if (!this.handwritingNode) this.createHandwriting();
  385. if(this.handwritingNodeMask)this.handwritingNodeMask.show();
  386. this.handwritingNode.show();
  387. this.handwritingNode.position({
  388. "relativeTo": this.options.mediaNode || this.node,
  389. "position": "center",
  390. "edge": "center"
  391. });
  392. },
  393. createHandwriting: function(){
  394. this.handwritingNodeMask = new Element("div", {"styles": this.css.handwritingMask}).inject(this.node);
  395. this.handwritingNode = new Element("div", {"styles": this.css.handwritingNode}).inject(this.node, "after");
  396. //var size = (this.options.mediaNode || this.node).getSize();
  397. //var y = size.y;
  398. //var x = size.x;
  399. //兼容以前的默认高宽
  400. var x = 600;
  401. var y = 320;
  402. if (!layout.mobile){
  403. x = Math.max( this.options.tabletWidth || x , 500);
  404. y = Math.max(this.options.tabletHeight ? (parseInt(this.options.tabletHeight) + 110) : y, 320);
  405. //y = Math.max(size.y, 320);
  406. //x = Math.max(size.x, 480);
  407. }
  408. // for (k in this.node.style){
  409. // if (this.node.style[k]) this.handwritingNode.style[k] = this.node.style[k];
  410. // }
  411. var zidx = this.node.getStyle("z-index");
  412. this.handwritingNode.setStyles({
  413. "height": ""+y+"px",
  414. "width": ""+x+"px",
  415. "z-index": zidx+1
  416. });
  417. if( layout.mobile ){
  418. this.handwritingNode.addEvent('touchmove' , function(e){
  419. e.preventDefault();
  420. })
  421. }
  422. this.handwritingNode.position({
  423. "relativeTo": this.options.mediaNode || this.node,
  424. "position": "center",
  425. "edge": "center"
  426. });
  427. this.handwritingAreaNode = new Element("div", {"styles": this.css.handwritingAreaNode}).inject(this.handwritingNode);
  428. this.handwritingActionNode = new Element("div", {"styles": this.css.handwritingActionNode, "text": MWF.xApplication.process.Work.LP.saveWrite}).inject(this.handwritingNode);
  429. var h = this.handwritingActionNode.getSize().y+this.handwritingActionNode.getStyle("margin-top").toInt()+this.handwritingActionNode.getStyle("margin-bottom").toInt();
  430. h = y - h;
  431. this.handwritingAreaNode.setStyle("height", ""+h+"px");
  432. MWF.require("MWF.widget.Tablet", function () {
  433. this.tablet = new MWF.widget.Tablet(this.handwritingAreaNode, {
  434. "style": "default",
  435. "contentWidth" : this.options.tabletWidth || 0,
  436. "contentHeight" : this.options.tabletHeight || 0,
  437. "onSave" : function( base64code, base64Image, imageFile ){
  438. this.handwritingFile = imageFile;
  439. this.handwritingNode.hide();
  440. this.handwritingNodeMask.hide();
  441. // this.page.get("div_image").node.set("src",base64Image);
  442. }.bind(this),
  443. "onCancel": function(){
  444. this.handwritingFile = null;
  445. this.handwritingNode.hide();
  446. this.handwritingNodeMask.hide();
  447. }.bind(this)
  448. }, null );
  449. this.tablet.load();
  450. }.bind(this));
  451. this.handwritingActionNode.addEvent("click", function(){
  452. //this.handwritingNode.hide();
  453. if (this.tablet) this.tablet.save();
  454. }.bind(this));
  455. },
  456. setIdeaList: function(ideas){
  457. var _self = this;
  458. ideas.each(function(idea){
  459. new Element("div", {
  460. "styles": this.css.selectIdeaItemNode,
  461. "text": idea,
  462. "events": {
  463. "click": function(){
  464. if (_self.inputTextarea.get("value")==MWF.xApplication.process.Work.LP.inputText){
  465. _self.inputTextarea.set("value", this.get("text"));
  466. }else{
  467. _self.inputTextarea.set("value", _self.inputTextarea.get("value")+", "+this.get("text"));
  468. }
  469. },
  470. "dblclick": function(){
  471. if (_self.inputTextarea.get("value")==MWF.xApplication.process.Work.LP.inputText){
  472. _self.inputTextarea.set("value", this.get("text"));
  473. }else{
  474. _self.inputTextarea.set("value", _self.inputTextarea.get("value")+", "+this.get("text"));
  475. }
  476. },
  477. "mouseover": function(){this.setStyles(_self.css.selectIdeaItemNode_over);},
  478. "mouseout": function(){this.setStyles(_self.css.selectIdeaItemNode);}
  479. }
  480. }).inject(this.selectIdeaAreaNode);
  481. }.bind(this));
  482. },
  483. setButtons: function(){
  484. this.cancelButton = new Element("div", {"styles": this.css.cancelButton}).inject(this.buttonsArea);
  485. var iconNode = new Element("div", {"styles": this.css.cancelIconNode}).inject(this.cancelButton);
  486. var textNode = new Element("div", {"styles": this.css.cancelTextNode, "text": MWF.xApplication.process.Work.LP.cancel}).inject(this.cancelButton);
  487. this.okButton = new Element("div", {"styles": this.css.okButton}).inject(this.buttonsArea);
  488. var iconNode = new Element("div", {"styles": this.css.okIconNode}).inject(this.okButton);
  489. var textNode = new Element("div", {"styles": this.css.okTextNode, "text": MWF.xApplication.process.Work.LP.ok}).inject(this.okButton);
  490. this.cancelButton.addEvent("click", function(){
  491. this.destroy();
  492. this.fireEvent("cancel");
  493. }.bind(this));
  494. this.okButton.addEvent("click", function( ev ){
  495. if( layout.mobile ){
  496. this.submit_mobile(ev)
  497. }else{
  498. this.submit_pc(ev)
  499. }
  500. }.bind(this));
  501. },
  502. submit_mobile : function(ev){
  503. if (!this.selectedRoute) {
  504. this.routeSelectorArea.setStyle("background-color", "#ffe9e9");
  505. new mBox.Notice({
  506. type: "error",
  507. position: {"x": "center", "y": "top"},
  508. move: false,
  509. target: this.routeSelectorArea,
  510. delayClose: 6000,
  511. content: MWF.xApplication.process.Work.LP.mustSelectRoute
  512. });
  513. return false;
  514. }
  515. var routeName = this.selectedRoute.retrieve("routeName") || this.selectedRoute.get("text");
  516. var opinion = this.inputTextarea.get("value");
  517. if (opinion === MWF.xApplication.process.Work.LP.inputText) opinion = "";
  518. var medias = [];
  519. if (this.handwritingFile) medias.push(this.handwritingFile);
  520. if (this.soundFile) medias.push(this.soundFile);
  521. if (this.videoFile) medias.push(this.videoFile);
  522. var currentRouteId = this.selectedRoute.retrieve("route");
  523. var routeData = this.getRouteData( currentRouteId );
  524. if( !opinion && medias.length === 0 ){
  525. if( routeData.opinionRequired == true ){
  526. this.inputTextarea.setStyle("background-color", "#ffe9e9");
  527. new mBox.Notice({
  528. type: "error",
  529. position: {"x": "center", "y": "top"},
  530. move: false,
  531. target: this.inputTextarea,
  532. delayClose: 6000,
  533. content: MWF.xApplication.process.Work.LP.opinionRequired
  534. });
  535. return false;
  536. }
  537. }
  538. if( routeData.validationScriptText ){
  539. var validation = this.form.Macro.exec(routeData.validationScriptText, this);
  540. if( !validation || validation.toString() !== "true" ){
  541. if( typeOf(validation) === "string" ){
  542. new mBox.Notice({
  543. type: "error",
  544. position: {"x": "center", "y": "top"},
  545. move: false,
  546. target: this.node,
  547. delayClose: 6000,
  548. content: validation
  549. });
  550. return false;
  551. }else{
  552. //"路由校验失败"
  553. new mBox.Notice({
  554. type: "error",
  555. position: {"x": "center", "y": "top"},
  556. move: false,
  557. target: this.node,
  558. delayClose: 6000,
  559. content: MWF.xApplication.process.Work.LP.routeValidFailure
  560. });
  561. return false;
  562. }
  563. }
  564. }
  565. //var array = [routeName, opinion, medias];
  566. //this.node.mask({
  567. // "inject": {"where": "bottom", "target": this.node},
  568. // "destroyOnHide": true,
  569. // "style": {
  570. // "background-color": "#999",
  571. // "opacity": 0.3,
  572. // "z-index":600
  573. // }
  574. //});
  575. //this.fireEvent("submit", array );
  576. var appendTaskOrgItem;
  577. if( routeData.type === "appendTask" && routeData.appendTaskIdentityType === "select" ){
  578. if( !this.orgItems || this.orgItems.length === 0 ){
  579. new mBox.Notice({
  580. type: "error",
  581. position: {"x": "center", "y": "top"},
  582. move: false,
  583. target: this.orgsArea,
  584. delayClose: 6000,
  585. content: MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig //"没有配置转交人,请联系管理员"
  586. });
  587. return false;
  588. }else{
  589. appendTaskOrgItem = this.orgItems[0]
  590. }
  591. }
  592. if( !this.saveOrgs() )return false;
  593. //this.saveOrgsWithCheckEmpower( function(){
  594. var array = [routeName, opinion, medias];
  595. if( appendTaskOrgItem ){
  596. var appandTaskIdentityList = appendTaskOrgItem.getData();
  597. if( !appandTaskIdentityList || appandTaskIdentityList.length === 0){
  598. new mBox.Notice({
  599. type: "error",
  600. position: {"x": "center", "y": "top"},
  601. move: false,
  602. target: this.orgsArea,
  603. delayClose: 6000,
  604. content: MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice //"请选择转交人"
  605. });
  606. return;
  607. }else{
  608. array.push( appendTaskOrgItem.getData() );
  609. appendTaskOrgItem.setData([]);
  610. }
  611. }
  612. if( routeData.validationScriptText ){
  613. var validation = this.form.Macro.exec(routeData.validationScriptText, this);
  614. if( !validation || validation.toString() !== "true" ){
  615. if( typeOf(validation) === "string" ){
  616. MWF.xDesktop.notice(
  617. "error",
  618. {"x": "center", "y": "center"},
  619. validation,
  620. this.node,
  621. {"x": 0, "y": 30},
  622. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  623. );
  624. return false;
  625. }else{
  626. //"路由校验失败"
  627. MWF.xDesktop.notice(
  628. "error",
  629. {"x": "center", "y": "center"},
  630. MWF.xApplication.process.Work.LP.routeValidFailure,
  631. this.node,
  632. {"x": 0, "y": 30},
  633. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  634. );
  635. return false;
  636. }
  637. }
  638. }
  639. this.node.mask({
  640. "inject": {"where": "bottom", "target": this.node},
  641. "destroyOnHide": true,
  642. "style": {
  643. "background-color": "#999",
  644. "opacity": 0.3,
  645. "z-index":600
  646. }
  647. });
  648. this.fireEvent("submit", array );
  649. //}.bind(this))
  650. },
  651. submit_pc : function(ev){
  652. if (this.hasDecisionOpinion && !this.selectedRouteGroup) {
  653. this.routeGroupArea.setStyle("background-color", "#ffe9e9");
  654. MWF.xDesktop.notice(
  655. "error",
  656. {"x": "center", "y": "top"},
  657. MWF.xApplication.process.Work.LP.mustSelectRouteGroup,
  658. this.routeGroupArea,
  659. null, //{"x": 0, "y": 30}
  660. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  661. );
  662. return false;
  663. }
  664. if (!this.selectedRoute) {
  665. this.routeSelectorArea.setStyle("background-color", "#ffe9e9");
  666. //new mBox.Notice({
  667. // type: "error",
  668. // position: {"x": "center", "y": "top"},
  669. // move: false,
  670. // target: this.routeSelectorArea,
  671. // delayClose: 6000,
  672. // content: MWF.xApplication.process.Work.LP.mustSelectRoute
  673. //});
  674. MWF.xDesktop.notice(
  675. "error",
  676. {"x": "center", "y": "top"},
  677. MWF.xApplication.process.Work.LP.mustSelectRoute,
  678. this.routeSelectorArea,
  679. null, //{"x": 0, "y": 30}
  680. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  681. );
  682. return false;
  683. }
  684. var routeName = this.selectedRoute.retrieve("routeName") || this.selectedRoute.get("text");
  685. var opinion = this.inputTextarea.get("value");
  686. if (opinion === MWF.xApplication.process.Work.LP.inputText) opinion = "";
  687. var medias = [];
  688. if (this.handwritingFile) medias.push(this.handwritingFile);
  689. if (this.soundFile) medias.push(this.soundFile);
  690. if (this.videoFile) medias.push(this.videoFile);
  691. var currentRouteId = this.selectedRoute.retrieve("route");
  692. var routeData = this.getRouteData( currentRouteId );
  693. if( !opinion && medias.length === 0 ){
  694. if( routeData.opinionRequired == true ){
  695. this.inputTextarea.setStyle("background-color", "#ffe9e9");
  696. //new mBox.Notice({
  697. // type: "error",
  698. // position: {"x": "center", "y": "top"},
  699. // move: false,
  700. // target: this.inputTextarea,
  701. // delayClose: 6000,
  702. // content: MWF.xApplication.process.Work.LP.opinionRequired
  703. //});
  704. MWF.xDesktop.notice(
  705. "error",
  706. {"x": "center", "y": "top"},
  707. MWF.xApplication.process.Work.LP.opinionRequired,
  708. this.inputTextarea,
  709. null, //{"x": 0, "y": 30}
  710. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  711. );
  712. return false;
  713. }
  714. }
  715. var appendTaskOrgItem = "";
  716. if( routeData.type === "appendTask" && routeData.appendTaskIdentityType === "select" ){
  717. if( !this.orgItems || this.orgItems.length === 0 ){
  718. //new mBox.Notice({
  719. // type: "error",
  720. // position: {"x": "center", "y": "top"},
  721. // move: false,
  722. // target: this.orgsArea,
  723. // delayClose: 6000,
  724. // content: MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig //"没有配置转交人,请联系管理员"
  725. //});
  726. MWF.xDesktop.notice(
  727. "error",
  728. {"x": "center", "y": "center"},
  729. MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig,
  730. this.node,
  731. null, //{"x": 0, "y": 30}
  732. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  733. );
  734. return false;
  735. }else{
  736. appendTaskOrgItem = this.orgItems[0]
  737. }
  738. }
  739. this.saveOrgsWithCheckEmpower( function(){
  740. var array = [routeName, opinion, medias];
  741. if( appendTaskOrgItem ){
  742. var appandTaskIdentityList = appendTaskOrgItem.getData();
  743. if( !appandTaskIdentityList || appandTaskIdentityList.length === 0){
  744. //new mBox.Notice({
  745. // type: "error",
  746. // position: {"x": "center", "y": "top"},
  747. // move: false,
  748. // target: this.orgsArea,
  749. // delayClose: 6000,
  750. // content: MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice //"请选择转交人"
  751. //});
  752. MWF.xDesktop.notice(
  753. "error",
  754. {"x": "center", "y": "center"},
  755. MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice,
  756. this.node,
  757. {"x": 0, "y": 30},
  758. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  759. );
  760. return;
  761. }else{
  762. array.push( appendTaskOrgItem.getData() );
  763. appendTaskOrgItem.setData([]);
  764. }
  765. }
  766. if( routeData.validationScriptText ){
  767. var validation = this.form.Macro.exec(routeData.validationScriptText, this);
  768. if( !validation || validation.toString() !== "true" ){
  769. if( typeOf(validation) === "string" ){
  770. MWF.xDesktop.notice(
  771. "error",
  772. {"x": "center", "y": "center"},
  773. validation,
  774. this.node,
  775. {"x": 0, "y": 30},
  776. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  777. );
  778. return false;
  779. }else{
  780. //"路由校验失败"
  781. MWF.xDesktop.notice(
  782. "error",
  783. {"x": "center", "y": "center"},
  784. MWF.xApplication.process.Work.LP.routeValidFailure,
  785. this.node,
  786. {"x": 0, "y": 30},
  787. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  788. );
  789. return false;
  790. }
  791. }
  792. }
  793. this.node.mask({
  794. "inject": {"where": "bottom", "target": this.node},
  795. "destroyOnHide": true,
  796. "style": {
  797. "background-color": "#999",
  798. "opacity": 0.3,
  799. "z-index":600
  800. }
  801. });
  802. this.fireEvent("submit", array );
  803. }.bind(this))
  804. },
  805. destroy: function(){
  806. this.node.empty();
  807. delete this.task;
  808. delete this.node;
  809. delete this.routeSelectorTile;
  810. delete this.routeSelectorArea;
  811. delete this.routeOpinionTile;
  812. delete this.routeOpinionArea;
  813. delete this.buttonsArea;
  814. delete this.inputOpinionNode;
  815. delete this.inputTextarea;
  816. delete this.cancelButton;
  817. delete this.okButton;
  818. },
  819. getRouteDataList : function(){
  820. if( !this.routeDataList ){
  821. o2.Actions.get("x_processplatform_assemble_surface").listRoute( {"valueList":this.task.routeList} , function( json ){
  822. json.data.each( function(d){
  823. d.selectConfigList = JSON.parse( d.selectConfig || "[]" );
  824. }.bind(this));
  825. this.routeDataList = json.data;
  826. }.bind(this), null, false );
  827. }
  828. return this.routeDataList;
  829. },
  830. getRouteData : function( routeId ){
  831. var routeList = this.getRouteDataList();
  832. for( var i=0; i<routeList.length; i++ ){
  833. if( routeList[i].id === routeId ){
  834. return routeList[i];
  835. }
  836. }
  837. },
  838. getMaxOrgLength : function(){
  839. var routeList = this.getRouteDataList();
  840. var length = 0;
  841. routeList.each( function(route){
  842. if( route.hiddenScriptText ){ //如果隐藏路由,返回
  843. if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
  844. }
  845. length = Math.max( length, route.selectConfigList.length);
  846. }.bind(this));
  847. return length;
  848. },
  849. getOrgData : function( routeId ){
  850. var routeList = this.getRouteDataList();
  851. for( var i=0; i<routeList.length; i++ ){
  852. if( routeList[i].id === routeId ){
  853. return routeList[i].selectConfigList;
  854. }
  855. }
  856. },
  857. loadOrgs_mobile : function( route ){
  858. if( !this.form || !route ){
  859. this.orgsArea.hide();
  860. return;
  861. }else{
  862. this.orgsArea.show();
  863. }
  864. if( !this.orgTableObject )this.orgTableObject = {};
  865. if( !this.orgItemsObject )this.orgItemsObject = {};
  866. var isLoaded = false;
  867. for( var key in this.orgTableObject ){
  868. if( route === key ){
  869. this.orgTableObject[key].show();
  870. this.orgItems = this.orgItemsObject[key] || [];
  871. var data = this.getOrgData( route );
  872. isLoaded = true;
  873. }else{
  874. this.orgTableObject[key].hide();
  875. }
  876. }
  877. if( isLoaded )return;
  878. this.orgItems = [];
  879. this.orgItemsObject[route] = this.orgItems;
  880. var data = this.getOrgData( route );
  881. if( data.length ){
  882. this.orgsArea.show();
  883. var routeOrgTable = new Element("div",{
  884. "styles" : this.css.routeOrgTable
  885. }).inject( this.orgsArea );
  886. this.orgTableObject[route] = routeOrgTable;
  887. data.each( function( config, i ){
  888. var sNode = new Element("div",{
  889. "styles" : this.css.routeOrgTr
  890. }).inject( routeOrgTable );
  891. this.loadOrg_mobile( sNode, config )
  892. }.bind(this))
  893. }else{
  894. this.orgsArea.hide();
  895. }
  896. },
  897. loadOrg_mobile : function( container, json ){
  898. var titleNode = new Element("div.selectorTitle", {
  899. "styles" : this.css.selectorTitle
  900. }).inject(container);
  901. var titleTextNode = new Element("div.selectorTitleText", {
  902. "text": json.title,
  903. "styles" : this.css.selectorTitleText
  904. }).inject(titleNode);
  905. var contentNode = new Element("div.selectorContent", {
  906. "styles" : this.css.selectorContent
  907. }).inject(container);
  908. var errorNode = new Element("div.selectorErrorNode", {
  909. "styles" : this.css.selectorErrorNode
  910. }).inject(container);
  911. var org = new MWF.xApplication.process.Work.Processor.Org( contentNode, this.form, json, this, {
  912. onSelect : function(items, data){
  913. if( !data || !data.length ){
  914. contentNode.setStyles( this.css.selectorContent_noItem );
  915. }else{
  916. contentNode.setStyles( this.css.selectorContent );
  917. }
  918. }.bind(this)
  919. });
  920. org.errContainer = errorNode;
  921. org.summitDlalog = this;
  922. this.orgItems.push( org );
  923. titleNode.addEvent("click", function(){
  924. this.load();
  925. }.bind(org));
  926. contentNode.addEvent("click", function(){
  927. this.load();
  928. }.bind(org));
  929. var defaultValue = org.getValue();
  930. org.loadOrgWidget( defaultValue, contentNode );
  931. if( !defaultValue || defaultValue.length == 0){{
  932. contentNode.setStyles( this.css.selectorContent_noItem );
  933. }}
  934. },
  935. loadOrgs : function( route ){
  936. if( !this.form || !route ){
  937. this.orgsArea.hide();
  938. this.setSize( 0 );
  939. return;
  940. }else{
  941. this.orgsArea.show();
  942. }
  943. if( !this.orgTableObject )this.orgTableObject = {};
  944. if( !this.orgItemsObject )this.orgItemsObject = {};
  945. var isLoaded = false;
  946. for( var key in this.orgTableObject ){
  947. if( route === key ){
  948. this.orgTableObject[key].show();
  949. this.orgItems = this.orgItemsObject[key] || [];
  950. var data = this.getOrgData( route );
  951. this.setSize( data.length );
  952. isLoaded = true;
  953. }else{
  954. this.orgTableObject[key].hide();
  955. }
  956. }
  957. if( isLoaded )return;
  958. this.orgItems = [];
  959. this.orgItemsObject[route] = this.orgItems;
  960. var data = this.getOrgData( route );
  961. this.setSize( data.length );
  962. if( data.length ){
  963. this.orgsArea.show();
  964. var len = data.length;
  965. var routeOrgTable = new Element("table",{
  966. "cellspacing" : 0, "cellpadding" : 0, "border" : 0, "width" : "100%",
  967. "styles" : this.css.routeOrgTable
  968. }).inject( this.orgsArea );
  969. this.orgTableObject[route] = routeOrgTable;
  970. //if( len <= this.options.maxOrgCountPerline ){
  971. // var width = 1 / len * 100;
  972. // var tr = new Element("tr").inject( routeOrgTable );
  973. // for (var n=0; n<len; n++){
  974. // new Element("td", { "width" : width+"%", "styles" : this.css.routeOrgOddTd }).inject( tr );
  975. // }
  976. //}else{
  977. // var lines = ((len+1)/this.options.maxOrgCountPerline).toInt();
  978. // var width = 1 / this.options.maxOrgCountPerline * 100;
  979. // for( var n=0; n<lines; n++ ){
  980. // var tr = new Element("tr").inject( routeOrgTable );
  981. // for( var i=0; i<this.options.maxOrgCountPerline; i++ ){
  982. // new Element("td", { "width" : width+"%", "styles" : this.css.routeOrgOddTd }).inject( tr );
  983. // }
  984. // }
  985. //}
  986. //
  987. //var tds = routeOrgTable.getElements("td");
  988. //data.each( function( config, i ){
  989. // this.loadOrg( tds[i], config )
  990. //}.bind(this))
  991. var lines = ((len+1)/2).toInt();
  992. for (var n=0; n<lines; n++){
  993. var tr = new Element("tr").inject( routeOrgTable );
  994. new Element("td", { "width" : "50%", "styles" : this.css.routeOrgOddTd }).inject( tr );
  995. new Element("td", { "width" : "50%", "styles" : this.css.routeOrgEvenTd }).inject( tr );
  996. }
  997. var trs = routeOrgTable.getElements("tr");
  998. data.each( function( config, i ){
  999. var sNode;
  1000. var width;
  1001. if (i+1==len && (len % 2===1)){
  1002. sNode = trs[trs.length-1].getFirst("td");
  1003. sNode.set("colspan", 2);
  1004. trs[trs.length-1].getLast("td").destroy();
  1005. sNode.setStyle("border","0px");
  1006. sNode.set("width","100%");
  1007. this.loadOrg( sNode, config, "all")
  1008. }else{
  1009. var row = ((i+2)/2).toInt();
  1010. var tr = trs[row-1];
  1011. sNode = (i % 2===0) ? tr.getFirst("td") : tr.getLast("td");
  1012. this.loadOrg( sNode, config, (i % 2===0) ? "left" : "right" )
  1013. }
  1014. }.bind(this))
  1015. }else{
  1016. this.orgsArea.hide();
  1017. }
  1018. },
  1019. loadOrg : function( container, json, position ){
  1020. var titleNode = new Element("div.selectorTitle", {
  1021. "styles" : this.css.selectorTitle
  1022. }).inject(container);
  1023. var titleTextNode = new Element("div.selectorTitleText", {
  1024. "text": json.title,
  1025. "styles" : this.css.selectorTitleText
  1026. }).inject(titleNode);
  1027. var errorNode = new Element("div.selectorErrorNode", {
  1028. "styles" : this.css.selectorErrorNode
  1029. }).inject(titleNode);
  1030. var contentNode = new Element("div.selectorContent", {
  1031. "styles" : this.css.selectorContent
  1032. }).inject(container);
  1033. var org = new MWF.xApplication.process.Work.Processor.Org( contentNode, this.form, json, this );
  1034. org.errContainer = errorNode;
  1035. org.summitDlalog = this;
  1036. org.load();
  1037. this.orgItems.push( org )
  1038. },
  1039. getCurrentRouteSelectorList : function(){
  1040. var selectorList = [];
  1041. var currentRoute = this.selectedRoute ? this.selectedRoute.retrieve("route") : "";
  1042. var orgList = this.orgItemsObject[currentRoute];
  1043. if( !orgList )return [];
  1044. orgList.each( function( org ){
  1045. if( org.selector && org.selector.selector ){
  1046. selectorList.push( org.selector.selector );
  1047. }
  1048. }.bind(this))
  1049. return selectorList;
  1050. },
  1051. getCurrentRouteOrgList : function(){
  1052. var currentRoute = this.selectedRoute ? this.selectedRoute.retrieve("route") : "";
  1053. var orgList = this.orgItemsObject[currentRoute];
  1054. return orgList || [];
  1055. },
  1056. getSelectorSelectedData : function( filedName ){
  1057. var data = [];
  1058. var orgList = this.getCurrentRouteOrgList();
  1059. for( var i=0; i<orgList.length; i++ ){
  1060. var org = orgList[i];
  1061. if( org.json.name === filedName ){
  1062. var selector = org.selector.selector;
  1063. selector.selectedItems.each( function(item){
  1064. data.push( item.data )
  1065. })
  1066. }
  1067. }
  1068. return data;
  1069. },
  1070. getOffsetY : function(node){
  1071. return (node.getStyle("margin-top").toInt() || 0 ) +
  1072. (node.getStyle("margin-bottom").toInt() || 0 ) +
  1073. (node.getStyle("padding-top").toInt() || 0 ) +
  1074. (node.getStyle("padding-bottom").toInt() || 0 )+
  1075. (node.getStyle("border-top-width").toInt() || 0 ) +
  1076. (node.getStyle("border-bottom-width").toInt() || 0 );
  1077. },
  1078. setSize : function( currentOrgLength ){
  1079. if( layout.mobile )return;
  1080. var lines = ((currentOrgLength+1)/2).toInt();
  1081. var flag = false;
  1082. var height = 0;
  1083. if( this.routeSelectorTile )height = height + this.getOffsetY(this.routeSelectorTile) + this.routeSelectorTile.getStyle("height").toInt();
  1084. if( this.routeSelectorArea )height = height + this.getOffsetY(this.routeSelectorArea) + this.routeSelectorArea.getStyle("height").toInt();
  1085. if( this.routeOpinionTile )height = height + this.getOffsetY(this.routeOpinionTile) + this.routeOpinionTile.getStyle("height").toInt();
  1086. if( this.routeOpinionArea )height = height + this.getOffsetY(this.routeOpinionArea) + this.routeOpinionArea.getStyle("height").toInt();
  1087. //if( this.buttonsArea )height = height + this.getOffsetY(this.buttonsArea) + this.buttonsArea.getStyle("height").toInt();
  1088. if( lines > 0 ){
  1089. if( this.orgsTile )height = height + this.getOffsetY(this.orgsTile) + this.orgsTile.getStyle("height").toInt();
  1090. height = height + lines*this.options.orgHeight + this.getOffsetY(this.orgsArea);
  1091. this.node.setStyle( "height", height );
  1092. //flag = (lines*this.options.orgHeight + 431) > Math.floor( this.form.app.content.getSize().y * 0.9);
  1093. //this.node.store("height", Math.min( Math.floor( this.form.app.content.getSize().y * 0.9) , lines*this.options.orgHeight + 431 ));
  1094. }else{
  1095. this.node.setStyle( "height", height );
  1096. //this.node.store("height", 401 );
  1097. }
  1098. if( this.getMaxOrgLength() > 1 ){
  1099. this.node.setStyles( this.css.node_wide );
  1100. this.inputOpinionNode.setStyles( this.css.inputOpinionNode_wide );
  1101. this.inputTextarea.setStyles( this.css.inputTextarea_wide );
  1102. this.inputTextareaStyle = this.css.inputTextarea_wide;
  1103. this.selectIdeaNode.setStyles( this.css.selectIdeaNode_wide );
  1104. }else{
  1105. this.node.setStyles( this.css.node );
  1106. this.inputOpinionNode.setStyles( this.css.inputOpinionNode );
  1107. this.inputTextarea.setStyles( this.css.inputTextarea );
  1108. this.inputTextareaStyle = this.css.inputTextarea;
  1109. this.selectIdeaNode.setStyles( this.css.selectIdeaNode );
  1110. }
  1111. //this.node.store("width", this.node.getStyle("width").toInt() + ( flag ? 20 : 0 ));
  1112. this.fireEvent("resize");
  1113. },
  1114. validationOrgs : function(){
  1115. if( !this.orgItems || !this.orgItems.length )return true;
  1116. var flag = true;
  1117. this.orgItems.each( function(item){
  1118. if( !item.validation() )flag = false;
  1119. }.bind(this));
  1120. return flag;
  1121. },
  1122. isOrgsHasEmpower: function(){
  1123. if( !this.orgItems || !this.orgItems.length )return true;
  1124. var flag = false;
  1125. this.needCheckEmpowerOrg = [];
  1126. this.orgItems.each( function(item){
  1127. if( item.hasEmpowerIdentity() ){
  1128. this.needCheckEmpowerOrg.push(item);
  1129. flag = true;
  1130. }
  1131. }.bind(this));
  1132. return flag;
  1133. },
  1134. saveOrgs : function( keepSilent ){
  1135. if( !this.orgItems || !this.orgItems.length )return true;
  1136. var flag = true;
  1137. this.orgItems.each( function(item){
  1138. if( !item.save( !keepSilent ) )flag = false;
  1139. }.bind(this));
  1140. return flag;
  1141. },
  1142. saveOrgsWithCheckEmpower : function( callback ){
  1143. if( !this.orgItems || !this.orgItems.length ){
  1144. if( callback )callback();
  1145. return true;
  1146. }
  1147. if( !this.validationOrgs() )return false;
  1148. if( !this.isOrgsHasEmpower() ){
  1149. if( callback )callback();
  1150. return true;
  1151. }
  1152. //this.checkEmpowerMode = true;
  1153. this.showEmpowerDlg( callback );
  1154. },
  1155. showEmpowerDlg : function( callback ){
  1156. //this.empowerMask = new Element("div", {"styles": this.css.handwritingMask}).inject(this.node);
  1157. //this.needCheckEmpowerOrg.each( function(org){
  1158. // org.saveCheckedEmpowerData();
  1159. //}.bind(this));
  1160. var empowerNode = new Element("div.empowerNode", {"styles": this.css.empowerNode});
  1161. var empowerTitleNode = new Element("div",{
  1162. text : MWF.xApplication.process.Xform.LP.empowerDlgText,
  1163. styles : this.css.empowerTitleNode
  1164. }).inject(empowerNode);
  1165. var orgs = this.needCheckEmpowerOrg;
  1166. var len = orgs.length;
  1167. var lines = ((len+1)/2).toInt();
  1168. var empowerTable = new Element("table",{
  1169. "cellspacing" : 0, "cellpadding" : 0, "border" : 0, "width" : "100%",
  1170. "styles" : this.css.empowerTable
  1171. }).inject( empowerNode );
  1172. for (var n=0; n<lines; n++){
  1173. var tr = new Element("tr").inject( empowerTable );
  1174. new Element("td", { "width" : "50%", "styles" : this.css.empowerOddTd }).inject( tr );
  1175. new Element("td", { "width" : "50%", "styles" : this.css.empowerEvenTd }).inject( tr );
  1176. }
  1177. var trs = empowerTable.getElements("tr");
  1178. orgs.each( function( org, i ){
  1179. var sNode;
  1180. var width;
  1181. if (i+1==len && (len % 2===1)){
  1182. sNode = trs[trs.length-1].getFirst("td");
  1183. sNode.set("colspan", 2);
  1184. trs[trs.length-1].getLast("td").destroy();
  1185. width = "50%";
  1186. }else{
  1187. var row = ((i+2)/2).toInt();
  1188. var tr = trs[row-1];
  1189. sNode = (i % 2===0) ? tr.getFirst("td") : tr.getLast("td");
  1190. }
  1191. var titleNode = new Element("div.empowerAreaTitle", {
  1192. "styles" : this.css.empowerAreaTitle
  1193. }).inject(sNode);
  1194. var titleTextNode = new Element("div.empowerAreaTitleText", {
  1195. "text": org.json.title,
  1196. "styles" : this.css.empowerAreaTitleText
  1197. }).inject(titleNode);
  1198. var selectAllNode = new Element("div",{
  1199. styles : {
  1200. float : "right"
  1201. }
  1202. }).inject(titleNode);
  1203. var contentNode = new Element("div.empowerAreaContent", {
  1204. "styles" : this.css.empowerAreaContent
  1205. }).inject(sNode);
  1206. org.loadCheckEmpower( null, contentNode, selectAllNode );
  1207. }.bind(this));
  1208. empowerNode.setStyle( "height", lines*this.options.orgHeight + 20 );
  1209. //var dlgHeight = Math.min( Math.floor( this.form.app.content.getSize().y * 0.9) , lines*this.options.orgHeight + 151 );
  1210. //var width = this.node.retrieve("width");
  1211. //empowerNode.setStyle( "width", width );
  1212. var width = "880";
  1213. //if( len > 1 ){
  1214. // width = "840"
  1215. //}else{
  1216. // width = "420"
  1217. //}
  1218. empowerNode.setStyle( "width", width+"px" );
  1219. this.node.getParent().mask( {
  1220. "style": this.css.mask
  1221. });
  1222. this.empowerDlg = o2.DL.open({
  1223. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  1224. "style": this.form.json.dialogStyle || "user",
  1225. "isResize": false,
  1226. "content": empowerNode,
  1227. //"container" : this.node,
  1228. "width": width, //600,
  1229. "height": "auto", //dlgHeight,
  1230. "mark" : false,
  1231. "buttonList": [
  1232. {
  1233. "type" : "ok",
  1234. "text": MWF.LP.process.button.ok,
  1235. "action": function(d, e){
  1236. //if (this.empowerDlg) this.empowerDlg.okButton.click();
  1237. orgs.each( function( org, i ){
  1238. org.saveCheckedEmpowerData( function(){
  1239. if( i === orgs.length-1 ){
  1240. if( callback )callback();
  1241. this.node.getParent().unmask();
  1242. this.empowerDlg.close();
  1243. }
  1244. }.bind(this))
  1245. }.bind(this))
  1246. }.bind(this)
  1247. },
  1248. {
  1249. "type" : "cancel",
  1250. "text": MWF.LP.process.button.cancel,
  1251. "action": function(){
  1252. this.node.getParent().unmask();
  1253. this.empowerDlg.close();
  1254. }.bind(this)
  1255. }
  1256. ]
  1257. });
  1258. }
  1259. });
  1260. MWF.xApplication.process.Work.Processor.Org = new Class({
  1261. Implements: [Options, Events],
  1262. options: {
  1263. moduleEvents : ["queryLoadSelector","postLoadSelector","queryLoadCategory","postLoadCategory","selectCategory", "unselectCategory","queryLoadItem","postLoadItem","selectItem", "unselectItem","change"]
  1264. },
  1265. initialize: function (container, form, json, processor, options) {
  1266. this.form = form;
  1267. this.json = json;
  1268. this.processor = processor;
  1269. this.container = $(container);
  1270. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1271. this.setOptions(options);
  1272. },
  1273. load : function(){
  1274. var options = this.getOptions();
  1275. if(options){
  1276. this.selector = new MWF.O2Selector(this.container, options);
  1277. }
  1278. },
  1279. _getOrgOptions: function(){
  1280. this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  1281. if( this.selectTypeList.contains( "identity" ) ) {
  1282. this.identityOptions = new MWF.xApplication.process.Work.Processor.IdentityOptions(this.form, this.json);
  1283. }
  1284. if( this.selectTypeList.contains( "unit" ) ) {
  1285. this.unitOptions = new MWF.xApplication.process.Work.Processor.UnitOptions(this.form, this.json);
  1286. }
  1287. //if( this.selectTypeList.contains( "group" ) ){
  1288. // this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
  1289. //}
  1290. },
  1291. getOptions: function(){
  1292. var _self = this;
  1293. this._getOrgOptions();
  1294. if( this.selectTypeList.length === 0 )return false;
  1295. var exclude = [];
  1296. if( this.json.exclude ){
  1297. var v = this.form.Macro.exec(this.json.exclude.code, this);
  1298. exclude = typeOf(v)==="array" ? v : [v];
  1299. }
  1300. var identityOpt;
  1301. if( this.identityOptions ){
  1302. identityOpt = this.identityOptions.getOptions();
  1303. if (this.json.identityRange!=="all"){
  1304. if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
  1305. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  1306. return false;
  1307. }
  1308. }
  1309. if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
  1310. if (!identityOpt.dutys || !identityOpt.dutys.length){
  1311. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  1312. return false;
  1313. }
  1314. }
  1315. identityOpt.values = this.getValue();
  1316. identityOpt.exclude = exclude;
  1317. }
  1318. var unitOpt;
  1319. if( this.unitOptions ){
  1320. unitOpt = this.unitOptions.getOptions();
  1321. if (this.json.unitRange!=="all"){
  1322. if ( !unitOpt.units || !unitOpt.units.length){
  1323. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  1324. return false;
  1325. }
  1326. }
  1327. unitOpt.values = this.getValue();
  1328. unitOpt.exclude = exclude;
  1329. }
  1330. //var groupOpt;
  1331. //if( this.groupOptions ){
  1332. // groupOpt = this.groupOptions.getOptions();
  1333. // groupOpt.values = (this.json.isInput) ? [] : values;
  1334. // groupOpt.exclude = exclude;
  1335. //}
  1336. var defaultOpt;
  1337. if( layout.mobile ){
  1338. defaultOpt = {
  1339. "style" : "default",
  1340. "zIndex" : 3000
  1341. };
  1342. }else{
  1343. defaultOpt = {
  1344. "style" : "process",
  1345. "width" : "auto",
  1346. "height" : "240",
  1347. "embedded" : true,
  1348. "hasLetter" : false, //字母
  1349. "hasTop" : true //可选、已选的标题
  1350. };
  1351. }
  1352. if( this.json.events && typeOf(this.json.events) === "object" ){
  1353. Object.each(this.json.events, function(e, key){
  1354. if (e.code){
  1355. if (this.options.moduleEvents.indexOf(key)!==-1){
  1356. //this.addEvent(key, function(event){
  1357. // return this.form.Macro.fire(e.code, this, event);
  1358. //}.bind(this));
  1359. if( key === "postLoadSelector" ) {
  1360. this.addEvent("loadSelector", function (selector) {
  1361. return this.form.Macro.fire(e.code, selector);
  1362. }.bind(this))
  1363. }else if( key === "queryLoadSelector"){
  1364. defaultOpt["onQueryLoad"] = function(target){
  1365. return this.form.Macro.fire(e.code, target);
  1366. }.bind(this)
  1367. }else{
  1368. defaultOpt["on"+key.capitalize()] = function(target){
  1369. return this.form.Macro.fire(e.code, target);
  1370. }.bind(this)
  1371. }
  1372. }
  1373. }
  1374. }.bind(this));
  1375. }
  1376. if( this.form.json.selectorStyle ){
  1377. defaultOpt = Object.merge( Object.clone(this.form.json.selectorStyle), defaultOpt );
  1378. if( this.form.json.selectorStyle.style )defaultOpt.style = this.form.json.selectorStyle.style;
  1379. }
  1380. var mobileEvents = {
  1381. "onComplete": function(items){
  1382. this.selectOnComplete(items);
  1383. }.bind(this),
  1384. "onCancel": this.selectOnCancel.bind(this),
  1385. "onClose": this.selectOnClose.bind(this)
  1386. };
  1387. if( this.selectTypeList.length === 1 ){
  1388. return Object.merge(
  1389. defaultOpt,
  1390. {
  1391. "type": this.selectTypeList[0],
  1392. "onLoad": function(){
  1393. //this 为 selector
  1394. _self.selectOnLoad(this, this.selector )
  1395. }
  1396. //"onComplete": function(items){
  1397. // this.selectOnComplete(items);
  1398. //}.bind(this),
  1399. //"onCancel": this.selectOnCancel.bind(this),
  1400. //"onClose": this.selectOnClose.bind(this)
  1401. },
  1402. layout.mobile ? mobileEvents : {} ,
  1403. identityOpt || unitOpt
  1404. )
  1405. }else if( this.selectTypeList.length > 1 ){
  1406. var options = {
  1407. "type" : "",
  1408. "types" : this.selectTypeList,
  1409. "onLoad": function(){
  1410. //this 为 selector
  1411. _self.selectOnLoad(this)
  1412. }
  1413. //"onComplete": function(items){
  1414. // this.selectOnComplete(items);
  1415. //}.bind(this),
  1416. //"onCancel": this.selectOnCancel.bind(this),
  1417. //"onClose": this.selectOnClose.bind(this)
  1418. };
  1419. if( identityOpt ){
  1420. options.identityOptions = Object.merge(
  1421. defaultOpt,
  1422. layout.mobile ? mobileEvents : {},
  1423. identityOpt
  1424. );
  1425. }
  1426. if( unitOpt ){
  1427. options.unitOptions = Object.merge(
  1428. defaultOpt,
  1429. layout.mobile ? mobileEvents : {},
  1430. unitOpt
  1431. );
  1432. }
  1433. //if( groupOpt )options.groupOptions = groupOpt;
  1434. return options;
  1435. }
  1436. },
  1437. selectOnComplete: function(items){ //移动端才执行
  1438. var array = [];
  1439. items.each(function(item){
  1440. array.push(item.data);
  1441. }.bind(this));
  1442. this.checkEmpower( array, function( data ){
  1443. var values = [];
  1444. data.each(function(d){
  1445. values.push(MWF.org.parseOrgData(d, true));
  1446. }.bind(this));
  1447. this.setData(values);
  1448. //this.validationMode();
  1449. //this.validation();
  1450. this.container.empty();
  1451. this.loadOrgWidget(values, this.container);
  1452. this.selector = null;
  1453. this.fireEvent("select", [items, values]);
  1454. }.bind(this))
  1455. },
  1456. selectOnCancel: function(){ //移动端才执行
  1457. //this.validation();
  1458. },
  1459. selectOnLoad: function( selector ){
  1460. //if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  1461. this.fireEvent("loadSelector", [selector])
  1462. },
  1463. selectOnClose: function(){
  1464. var v = this._getBusinessData();
  1465. //if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  1466. },
  1467. loadOrgWidget: function(value, node){
  1468. var height = node.getStyle("height").toInt();
  1469. if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
  1470. if (value && value.length){
  1471. value.each(function(data){
  1472. var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
  1473. var copyData = Object.clone(data);
  1474. if( this.json.displayTextScript && this.json.displayTextScript.code ){
  1475. this.currentData = copyData;
  1476. var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
  1477. if( displayName ){
  1478. copyData.displayName = displayName;
  1479. }
  1480. this.currentData = null;
  1481. }
  1482. var widget;
  1483. switch (flag.toLowerCase()){
  1484. case "i":
  1485. widget = new MWF.widget.O2Identity(copyData, node, {"style": "xform","lazy":true});
  1486. break;
  1487. case "p":
  1488. widget = new MWF.widget.O2Person(copyData, node, {"style": "xform","lazy":true});
  1489. break;
  1490. case "u":
  1491. widget = new MWF.widget.O2Unit(copyData, node, {"style": "xform","lazy":true});
  1492. break;
  1493. case "g":
  1494. widget = new MWF.widget.O2Group(copyData, node, {"style": "xform","lazy":true});
  1495. break;
  1496. default:
  1497. widget = new MWF.widget.O2Other(copyData, node, {"style": "xform","lazy":true});
  1498. }
  1499. widget.field = this;
  1500. if( layout.mobile ){
  1501. //widget.node.setStyles({
  1502. // "float" : "none"
  1503. //})
  1504. }
  1505. }.bind(this));
  1506. }
  1507. },
  1508. hasEmpowerIdentity : function(){
  1509. var data = this.getData();
  1510. if(!this.empowerChecker )this.empowerChecker = new MWF.xApplication.process.Work.Processor.EmpowerChecker(this.form, this.json, this.processor);
  1511. return this.empowerChecker.hasEmpowerIdentity( data );
  1512. },
  1513. checkEmpower : function( data, callback, container, selectAllNode ){
  1514. if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  1515. if(!this.empowerChecker )this.empowerChecker = new MWF.xApplication.process.Work.Processor.EmpowerChecker(this.form, this.json, this.processor);
  1516. this.empowerChecker.selectAllNode = selectAllNode;
  1517. this.empowerChecker.load(data, callback, container);
  1518. }else{
  1519. if( callback )callback( data );
  1520. }
  1521. },
  1522. loadCheckEmpower : function( callback, container, selectAllNode ){
  1523. this.checkEmpower( this.getData(), callback, container, selectAllNode)
  1524. },
  1525. saveCheckedEmpowerData:function( callback ){
  1526. var data = this.getData();
  1527. //this.empowerChecker.replaceEmpowerIdentity(data, function( newData ){
  1528. this.empowerChecker.setIgnoreEmpowerFlag(data, function( newData ){
  1529. var values = [];
  1530. newData.each(function(d){
  1531. values.push(MWF.org.parseOrgData(d, true));
  1532. }.bind(this));
  1533. this.setData( values );
  1534. if( callback )callback(values)
  1535. }.bind(this))
  1536. },
  1537. //saveWithCheckEmpower: function( isValid, callback ){
  1538. // var checkEmpowerData = function(){
  1539. // var array = this.getData();
  1540. // this.checkEmpower( array, function( data ){
  1541. // var values = [];
  1542. // data.each(function(d){
  1543. // values.push(MWF.org.parseOrgData(d, true));
  1544. // }.bind(this));
  1545. // this.setData( values );
  1546. // if( callback )callback(values)
  1547. // }.bind(this), container, selectAllNode)
  1548. // }.bind(this)
  1549. // if( isValid ){
  1550. // if( this.validation() ){
  1551. // checkEmpowerData( function(){
  1552. // if(callback)callback();
  1553. // }.bind(this));
  1554. // return true;
  1555. // }else{
  1556. // return false;
  1557. // }
  1558. // }else{
  1559. // //this.setData( this.getData() );
  1560. // checkEmpowerData( function(){
  1561. // if(callback)callback();
  1562. // }.bind(this));
  1563. // return true;
  1564. // }
  1565. //},
  1566. save: function( isValid ){
  1567. if( isValid ){
  1568. if( this.validation() ){
  1569. return true;
  1570. }else{
  1571. return false;
  1572. }
  1573. }else{
  1574. this.setData( this.getData() );
  1575. return true;
  1576. }
  1577. },
  1578. resetSelectorData : function(){
  1579. if( this.selector && this.selector.selector ){
  1580. this.selector.selector.emptySelectedItems();
  1581. this.selector.selector.options.values = this.getValue();
  1582. this.selector.selector.setSelectedItem();
  1583. }
  1584. },
  1585. resetData: function(){
  1586. var v = this.getValue();
  1587. //this.setData((v) ? v.join(", ") : "");
  1588. this.setData(v);
  1589. },
  1590. getData: function(){
  1591. if( this.selector && !layout.mobile ){
  1592. return this.getSelectedData();
  1593. }else{
  1594. return this.getValue();
  1595. }
  1596. },
  1597. getSelectedData : function(){
  1598. if( layout.mobile ){
  1599. return this.getValue();
  1600. }else{
  1601. var data = [];
  1602. if( this.selector && this.selector.selector){
  1603. this.selector.selector.selectedItems.each( function( item ){
  1604. data.push( MWF.org.parseOrgData(item.data, true) );
  1605. })
  1606. }
  1607. return data;
  1608. }
  1609. },
  1610. getValue: function(){
  1611. var value = this._getBusinessData();
  1612. if (!value) value = this._computeValue();
  1613. return value || "";
  1614. },
  1615. _computeValue: function(){
  1616. var values = [];
  1617. if (this.json.identityValue) {
  1618. this.json.identityValue.each(function(v){ if (v) values.push(v)});
  1619. }
  1620. if (this.json.unitValue) {
  1621. this.json.unitValue.each(function(v){ if (v) values.push(v)});
  1622. }
  1623. if (this.json.dutyValue) {
  1624. var dutys = JSON.decode(this.json.dutyValue);
  1625. var par;
  1626. if (dutys.length){
  1627. dutys.each(function(duty){
  1628. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  1629. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
  1630. var d = this.form.Macro.exec(code, this);
  1631. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  1632. d.each(function(dd){if (dd) values.push(dd);});
  1633. }.bind(this));
  1634. }
  1635. }
  1636. if (this.json.defaultValue && this.json.defaultValue.code){
  1637. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  1638. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  1639. fd.each(function(fdd){
  1640. if (fdd){
  1641. if (typeOf(fdd)==="string"){
  1642. var data;
  1643. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = json.data }.bind(this), null, fdd, false);
  1644. values.push(data);
  1645. }else{
  1646. values.push(fdd);
  1647. }
  1648. }
  1649. }.bind(this));
  1650. }
  1651. if (this.json.count>0){
  1652. return values.slice(0, this.json.count);
  1653. }
  1654. return values;
  1655. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  1656. },
  1657. getOrgAction: function(){
  1658. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1659. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  1660. return this.orgAction;
  1661. },
  1662. setData: function(value){
  1663. if (!value) return false;
  1664. var oldValues = this.getValue();
  1665. var values = [];
  1666. var type = typeOf(value);
  1667. if (type==="array"){
  1668. value.each(function(v){
  1669. var vtype = typeOf(v);
  1670. var data = null;
  1671. if (vtype==="string"){
  1672. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true); }.bind(this), error, v, false);
  1673. }
  1674. if (vtype==="object") data = v;
  1675. if (data)values.push(data);
  1676. }.bind(this));
  1677. }
  1678. if (type==="string"){
  1679. var vData;
  1680. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true); }.bind(this), error, value, false);
  1681. if (vData)values.push(vData);
  1682. }
  1683. if (type==="object")values.push(value);
  1684. var change = false;
  1685. if (oldValues.length && values.length){
  1686. if (oldValues.length === values.length){
  1687. for (var i=0; i<oldValues.length; i++){
  1688. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  1689. change = true;
  1690. break;
  1691. }
  1692. }
  1693. }else{
  1694. change = true;
  1695. }
  1696. }else if (values.length || oldValues.length) {
  1697. change = true;
  1698. }
  1699. this._setBusinessData(values);
  1700. if (change) this.fireEvent("change");
  1701. },
  1702. getValueMethod: function(value){
  1703. if (value){
  1704. var flag = value.substr(value.length-1, 1);
  1705. switch (flag.toLowerCase()){
  1706. case "i":
  1707. return "getIdentity";
  1708. case "p":
  1709. return "getPerson";
  1710. case "u":
  1711. return "getUnit";
  1712. case "g":
  1713. return "getGroup";
  1714. default:
  1715. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1716. }
  1717. }
  1718. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1719. },
  1720. _getBusinessData: function(){
  1721. if (this.json.section=="yes"){
  1722. return this._getBusinessSectionData();
  1723. }else {
  1724. if (this.json.type==="Opinion"){
  1725. return this._getBusinessSectionDataByPerson();
  1726. }else{
  1727. return this.form.businessData.data[this.json.name] || "";
  1728. }
  1729. }
  1730. },
  1731. _getBusinessSectionData: function(){
  1732. switch (this.json.sectionBy){
  1733. case "person":
  1734. return this._getBusinessSectionDataByPerson();
  1735. case "unit":
  1736. return this._getBusinessSectionDataByUnit();
  1737. case "activity":
  1738. return this._getBusinessSectionDataByActivity();
  1739. case "splitValue":
  1740. return this._getBusinessSectionDataBySplitValue();
  1741. case "script":
  1742. return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
  1743. default:
  1744. return this.form.businessData.data[this.json.name] || "";
  1745. }
  1746. },
  1747. _getBusinessSectionDataByPerson: function(){
  1748. this.form.sectionListObj[this.json.name] = layout.desktop.session.user.id;
  1749. var dataObj = this.form.businessData.data[this.json.name];
  1750. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  1751. },
  1752. _getBusinessSectionDataByUnit: function(){
  1753. this.form.sectionListObj[this.json.name] = "";
  1754. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  1755. if (key) this.form.sectionListObj[this.json.name] = key;
  1756. var dataObj = this.form.businessData.data[this.json.name];
  1757. if (!dataObj) return "";
  1758. return (key) ? (dataObj[key] || "") : "";
  1759. },
  1760. _getBusinessSectionDataByActivity: function(){
  1761. this.form.sectionListObj[this.json.name] = "";
  1762. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  1763. if (key) this.form.sectionListObj[this.json.name] = key;
  1764. var dataObj = this.form.businessData.data[this.json.name];
  1765. if (!dataObj) return "";
  1766. return (key) ? (dataObj[key] || "") : "";
  1767. },
  1768. _getBusinessSectionDataBySplitValue: function(){
  1769. this.form.sectionListObj[this.json.name] = "";
  1770. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  1771. if (key) this.form.sectionListObj[this.json.name] = key;
  1772. var dataObj = this.form.businessData.data[this.json.name];
  1773. if (!dataObj) return "";
  1774. return (key) ? (dataObj[key] || "") : "";
  1775. },
  1776. _getBusinessSectionDataByScript: function(code){
  1777. this.form.sectionListObj[this.json.name] = "";
  1778. var dataObj = this.form.businessData.data[this.json.name];
  1779. if (!dataObj) return "";
  1780. var key = this.form.Macro.exec(code, this);
  1781. if (key) this.form.sectionListObj[this.json.name] = key;
  1782. return (key) ? (dataObj[key] || "") : "";
  1783. },
  1784. loadPathData: function(path){
  1785. var data = null;
  1786. this.form.workAction.getJobDataByPath(this.form.businessData.work.job, path, function(json){
  1787. data = json.data || null;
  1788. }, null, false);
  1789. return data;
  1790. },
  1791. _setBusinessData: function(v){
  1792. if (this.json.section=="yes"){
  1793. // var d = this.loadPathData(this.json.name);
  1794. // if (d) this.form.businessData.data[this.json.name] = d;
  1795. this._setBusinessSectionData(v);
  1796. }else {
  1797. if (this.json.type==="Opinion"){
  1798. // var d = this.loadPathData(this.json.name);
  1799. // if (d) this.form.businessData.data[this.json.name] = d;
  1800. this._setBusinessSectionDataByPerson(v);
  1801. }else{
  1802. if (this.form.businessData.data[this.json.name]){
  1803. this.form.businessData.data[this.json.name] = v;
  1804. }else{
  1805. this.form.businessData.data[this.json.name] = v;
  1806. this.form.Macro.environment.setData(this.form.businessData.data);
  1807. }
  1808. if (this.json.isTitle) this.form.businessData.work.title = v;
  1809. }
  1810. }
  1811. },
  1812. _setBusinessSectionData: function(v){
  1813. switch (this.json.sectionBy){
  1814. case "person":
  1815. this._setBusinessSectionDataByPerson(v);
  1816. break;
  1817. case "unit":
  1818. this._setBusinessSectionDataByUnit(v);
  1819. break;
  1820. case "activity":
  1821. this._setBusinessSectionDataByActivity(v);
  1822. break;
  1823. case "splitValue":
  1824. this._setBusinessSectionDataBySplitValue(v);
  1825. break;
  1826. case "script":
  1827. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  1828. break;
  1829. default:
  1830. if (this.form.businessData.data[this.json.name]){
  1831. this.form.businessData.data[this.json.name] = v;
  1832. }else{
  1833. this.form.businessData.data[this.json.name] = v;
  1834. this.form.Macro.environment.setData(this.form.businessData.data);
  1835. }
  1836. }
  1837. },
  1838. _setBusinessSectionDataByPerson: function(v){
  1839. var resetData = false;
  1840. var key = layout.desktop.session.user.id;
  1841. this.form.sectionListObj[this.json.name] = key;
  1842. var dataObj = this.form.businessData.data[this.json.name];
  1843. if (!dataObj){
  1844. dataObj = {};
  1845. this.form.businessData.data[this.json.name] = dataObj;
  1846. resetData = true;
  1847. }
  1848. if (!dataObj[key]) resetData = true;
  1849. dataObj[key] = v;
  1850. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1851. },
  1852. _setBusinessSectionDataByUnit: function(v){
  1853. var resetData = false;
  1854. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  1855. if (key){
  1856. this.form.sectionListObj[this.json.name] = key;
  1857. var dataObj = this.form.businessData.data[this.json.name];
  1858. if (!dataObj){
  1859. dataObj = {};
  1860. this.form.businessData.data[this.json.name] = dataObj;
  1861. resetData = true;
  1862. }
  1863. if (!dataObj[key]) resetData = true;
  1864. dataObj[key] = v;
  1865. }
  1866. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1867. },
  1868. _setBusinessSectionDataByActivity: function(v){
  1869. var resetData = false;
  1870. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  1871. if (key){
  1872. this.form.sectionListObj[this.json.name] = key;
  1873. var dataObj = this.form.businessData.data[this.json.name];
  1874. if (!dataObj){
  1875. dataObj = {};
  1876. this.form.businessData.data[this.json.name] = dataObj;
  1877. resetData = true;
  1878. }
  1879. if (!dataObj[key]) resetData = true;
  1880. dataObj[key] = v;
  1881. }
  1882. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1883. },
  1884. _setBusinessSectionDataBySplitValue: function(v){
  1885. var resetData = false;
  1886. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  1887. if (key){
  1888. this.form.sectionListObj[this.json.name] = key;
  1889. var dataObj = this.form.businessData.data[this.json.name];
  1890. if (!dataObj){
  1891. dataObj = {};
  1892. this.form.businessData.data[this.json.name] = dataObj;
  1893. resetData = true;
  1894. }
  1895. if (!dataObj[key]) resetData = true;
  1896. dataObj[key] = v;
  1897. }
  1898. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1899. },
  1900. _setBusinessSectionDataByScript: function(code, v){
  1901. var resetData = false;
  1902. var key = this.form.Macro.exec(code, this);
  1903. if (key){
  1904. this.form.sectionListObj[this.json.name] = key;
  1905. var dataObj = this.form.businessData.data[this.json.name];
  1906. if (!dataObj){
  1907. dataObj = {};
  1908. this.form.businessData.data[this.json.name] = dataObj;
  1909. resetData = true;
  1910. }
  1911. if (!dataObj[key]) resetData = true;
  1912. dataObj[key] = v;
  1913. }
  1914. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1915. },
  1916. createErrorNode: function(text){
  1917. var node;
  1918. if( this.processor.css.errorContentNode ){
  1919. node = new Element("div",{
  1920. "styles" : this.processor.css.errorContentNode,
  1921. "text": text
  1922. });
  1923. if( this.processor.css.errorCloseNode ){
  1924. var closeNode = new Element("div",{
  1925. "styles" : this.processor.css.errorCloseNode ,
  1926. "events": {
  1927. "click" : function(){
  1928. this.destroy();
  1929. }.bind(node)
  1930. }
  1931. }).inject(node);
  1932. }
  1933. }else {
  1934. node = new Element("div");
  1935. var iconNode = new Element("div", {
  1936. "styles": {
  1937. "width": "20px",
  1938. "height": "20px",
  1939. "float": "left",
  1940. "background": "url(" + "/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1941. }
  1942. }).inject(node);
  1943. var textNode = new Element("div", {
  1944. "styles": {
  1945. "height": "20px",
  1946. "line-height": "20px",
  1947. "margin-left": "20px",
  1948. "color": "red",
  1949. "word-break": "keep-all"
  1950. },
  1951. "text": text
  1952. }).inject(node);
  1953. }
  1954. return node;
  1955. },
  1956. notValidationMode: function(text){
  1957. if (!this.isNotValidationMode){
  1958. //this.isNotValidationMode = true;
  1959. //this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1960. //this.node.setStyle("border-color", "red");
  1961. this.errNode = this.createErrorNode(text);
  1962. if( this.errContainer ){
  1963. this.errContainer.empty();
  1964. this.errNode.inject(this.errContainer);
  1965. }else{
  1966. this.errNode.inject(this.container, "after");
  1967. }
  1968. //this.showNotValidationMode(this.node);
  1969. //if (!this.node.isIntoView()) this.node.scrollIntoView();
  1970. }
  1971. },
  1972. validation: function(){
  1973. var data = this.getData();
  1974. this.setData( data );
  1975. var flag=true;
  1976. if( this.json.validationCount && typeOf( this.json.validationCount.toInt() ) === "number" ){
  1977. if( data.length < this.json.validationCount.toInt() ){
  1978. //if( this.json.validationCount.toInt() === 1 ){
  1979. // flag = "请选择"
  1980. //}else{
  1981. // flag = "请至少选择"+this.json.validationCount+"项"
  1982. //}
  1983. flag = "请至少选择"+this.json.validationCount+"项"
  1984. }
  1985. }
  1986. if( flag === true ){
  1987. if ( this.json.validation && this.json.validation.code){
  1988. flag = this.form.Macro.exec(this.json.validation.code, this);
  1989. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1990. }
  1991. }
  1992. if (flag.toString()!="true"){
  1993. this.notValidationMode(flag);
  1994. return false;
  1995. }else if(this.errNode){
  1996. this.errNode.destroy()
  1997. }
  1998. return true;
  1999. }
  2000. });
  2001. MWF.xApplication.process.Work.Processor.EmpowerChecker = new Class({
  2002. Extends : MWF.APPOrg.EmpowerChecker,
  2003. initialize: function (form, json, processor) {
  2004. this.form = form;
  2005. this.json = json;
  2006. this.processor = processor;
  2007. this.css = this.processor.css;
  2008. this.checkedAllItems = true;
  2009. },
  2010. hasEmpowerIdentity: function( data ){
  2011. var flag = false;
  2012. if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  2013. var array = [];
  2014. data.each(function (d) {
  2015. if (d.distinguishedName) {
  2016. var flag = d.distinguishedName.substr(d.distinguishedName.length - 1, 1).toLowerCase();
  2017. if (flag === "i")array.push(d.distinguishedName)
  2018. }
  2019. }.bind(this));
  2020. if (array.length > 0) {
  2021. o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  2022. "application": (this.form.businessData.work || this.form.businessData.workCompleted).application,
  2023. "process": (this.form.businessData.work || this.form.businessData.workCompleted).process,
  2024. "work" : (this.form.businessData.work || this.form.businessData.workCompleted).id,
  2025. "identityList": array
  2026. }, function (json) {
  2027. var arr = [];
  2028. json.data.each(function (d) {
  2029. if (d.fromIdentity !== d.toIdentity)
  2030. arr.push(d);
  2031. });
  2032. if (arr.length > 0) {
  2033. flag = true;
  2034. }
  2035. }.bind(this), null, false)
  2036. }
  2037. }
  2038. return flag;
  2039. },
  2040. openSelectEmpowerDlg : function( data, orgData, callback, container ){
  2041. var node = new Element("div", {"styles": this.css.empowerAreaNode});
  2042. //var html = "<div style=\"line-height: 30px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
  2043. var html = "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  2044. node.set("html", html);
  2045. var itemNode = node.getLast();
  2046. this.getEmpowerItems(itemNode, data);
  2047. node.inject( container || this.container );
  2048. if( this.selectAllNode ){
  2049. var selectNode = this.createSelectAllEmpowerNode();
  2050. selectNode.inject( this.selectAllNode );
  2051. if( this.checkedAllItems ){
  2052. selectNode.store("isSelected", true);
  2053. selectNode.setStyles( this.css.empowerSelectAllItemNode_selected );
  2054. }
  2055. }
  2056. },
  2057. getSelectedData : function( callback ){
  2058. var json = {};
  2059. this.empowerSelectNodes.each(function(node){
  2060. if( node.retrieve("isSelected") ){
  2061. var d = node.retrieve("data");
  2062. json[ d.fromIdentity ] = d;
  2063. }
  2064. }.bind(this));
  2065. if( callback )callback( json );
  2066. }
  2067. });
  2068. MWF.xApplication.process.Work.Processor.UnitOptions = new Class({
  2069. Extends : MWF.APPOrg.UnitOptions
  2070. });
  2071. MWF.xApplication.process.Work.Processor.IdentityOptions = new Class({
  2072. Extends : MWF.APPOrg.IdentityOptions
  2073. });