Processor.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  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.routeSelectorTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute}).inject(this.node);
  30. this.routeSelectorArea = new Element("div", {"styles": this.css.routeSelectorArea}).inject(this.node);
  31. this.routeOpinionTile = new Element("div", {"styles": this.css.routeOpinionTile, "text": MWF.xApplication.process.Work.LP.inputOpinion}).inject(this.node);
  32. this.routeOpinionArea = new Element("div", {"styles": this.css.routeOpinionArea}).inject(this.node);
  33. this.setOpinion();
  34. this.orgsArea = new Element("div", {"styles": this.css.orgsArea}).inject(this.node);
  35. this.orgsTile = new Element("div", {"styles": this.css.orgsTitle, "text": MWF.xApplication.process.Work.LP.selectPerson}).inject(this.orgsArea);
  36. this.buttonsArea = new Element("div", {"styles": this.css.buttonsArea}).inject(this.node);
  37. this.setButtons();
  38. this.setRouteList();
  39. this.fireEvent("postLoad");
  40. },
  41. setRouteList: function(){
  42. var _self = this;
  43. //this.task.routeNameList = ["送审核", "送办理", "送公司领导阅"];
  44. var routeList = this.getRouteDataList();
  45. //this.task.routeNameList.each(function(route, i){
  46. routeList.each(function(route, i){
  47. if( route.hiddenScriptText ){
  48. if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
  49. }
  50. var routeName = route.name;
  51. if( route.displayNameScriptText ){
  52. routeName = this.form.Macro.exec(route.displayNameScriptText, this);
  53. }
  54. var routeNode = new Element("div", {"styles": this.css.routeNode}).inject(this.routeSelectorArea);
  55. var routeIconNode = new Element("div", {"styles": this.css.routeIconNode}).inject(routeNode);
  56. var routeTextNode = new Element("div", {"styles": this.css.routeTextNode, "text": routeName}).inject(routeNode);
  57. routeNode.store( "route", this.task.routeList[i] );
  58. routeNode.store( "routeName", route.name );
  59. routeNode.addEvents({
  60. "mouseover": function(e){_self.overRoute(this);},
  61. "mouseout": function(e){_self.outRoute(this);},
  62. "click": function(e){_self.selectRoute(this);}
  63. });
  64. if (routeList.length==1){
  65. this.selectRoute(routeNode);
  66. }else{
  67. this.setSize(0);
  68. }
  69. }.bind(this));
  70. },
  71. overRoute: function(node){
  72. if (this.selectedRoute){
  73. if (this.selectedRoute.get("text") != node.get("text")){
  74. node.setStyle("background-color", "#f7e1d0");
  75. }
  76. }else{
  77. node.setStyle("background-color", "#f7e1d0");
  78. }
  79. },
  80. outRoute: function(node){
  81. if (this.selectedRoute){
  82. if (this.selectedRoute.get("text") != node.get("text")){
  83. node.setStyles(this.css.routeNode);
  84. }
  85. }else{
  86. node.setStyles(this.css.routeNode);
  87. }
  88. },
  89. selectRoute: function(node){
  90. if (this.selectedRoute){
  91. if (this.selectedRoute.get("text") != node.get("text")){
  92. this.selectedRoute.setStyles(this.css.routeNode);
  93. this.selectedRoute.getFirst().setStyles(this.css.routeIconNode);
  94. this.selectedRoute.getLast().setStyles(this.css.routeTextNode);
  95. this.selectedRoute = node;
  96. node.setStyle("background-color", "#da7429");
  97. node.getFirst().setStyle("background-image", "url("+"/x_component_process_Work/$Processor/default/checked.png)");
  98. node.getLast().setStyle("color", "#FFF");
  99. }else{
  100. this.selectedRoute.setStyles(this.css.routeNode);
  101. this.selectedRoute.getFirst().setStyles(this.css.routeIconNode);
  102. this.selectedRoute.getLast().setStyles(this.css.routeTextNode);
  103. this.selectedRoute = null;
  104. }
  105. }else{
  106. this.selectedRoute = node;
  107. node.setStyle("background-color", "#da7429");
  108. node.getFirst().setStyle("background-image", "url("+"/x_component_process_Work/$Processor/default/checked.png)");
  109. node.getLast().setStyle("color", "#FFF");
  110. }
  111. this.routeSelectorArea.setStyle("background-color", "#FFF");
  112. this.loadOrgs( this.selectedRoute ? this.selectedRoute.retrieve("route") : "" );
  113. },
  114. setOpinion: function(){
  115. this.selectIdeaNode = new Element("div", {"styles": this.css.selectIdeaNode}).inject(this.routeOpinionArea);
  116. this.selectIdeaScrollNode = new Element("div", {"styles": this.css.selectIdeaScrollNode}).inject(this.selectIdeaNode);
  117. this.selectIdeaAreaNode = new Element("div", {"styles": {
  118. "overflow": "hidden"
  119. }}).inject(this.selectIdeaScrollNode);
  120. this.inputOpinionNode = new Element("div", {"styles": this.css.inputOpinionNode}).inject(this.routeOpinionArea);
  121. this.inputTextarea = new Element("textarea", {"styles": this.css.inputTextarea, "value": this.options.opinion || MWF.xApplication.process.Work.LP.inputText}).inject(this.inputOpinionNode);
  122. this.inputTextarea.addEvents({
  123. "focus": function(){if (this.get("value")==MWF.xApplication.process.Work.LP.inputText) this.set("value", "");},
  124. "blur": function(){if (!this.get("value")) this.set("value", MWF.xApplication.process.Work.LP.inputText);},
  125. "keydown": function(){this.inputTextarea.setStyles( this.inputTextareaStyle || this.css.inputTextarea);}.bind(this)
  126. });
  127. this.mediaActionArea = new Element("div", {"styles": this.css.inputOpinionMediaActionArea}).inject(this.inputOpinionNode);
  128. this.handwritingAction = new Element("div", {"styles": this.css.inputOpinionHandwritingAction, "text": MWF.xApplication.process.Work.LP.handwriting}).inject(this.mediaActionArea);
  129. this.handwritingAction.addEvent("click", function(){
  130. this.handwriting();
  131. }.bind(this));
  132. // if (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia){
  133. // this.audioRecordAction = new Element("div", {"styles": this.css.inputOpinionAudioRecordAction, "text": MWF.xApplication.process.Work.LP.audioRecord}).inject(this.mediaActionArea);
  134. // this.audioRecordAction.addEvent("click", function(){
  135. // this.audioRecord();
  136. // }.bind(this));
  137. // }
  138. if (layout.mobile){
  139. this.selectIdeaNode.inject(this.routeOpinionArea, "after");
  140. }
  141. MWF.require("MWF.widget.ScrollBar", function(){
  142. new MWF.widget.ScrollBar(this.selectIdeaScrollNode, {
  143. "style":"small", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  144. });
  145. }.bind(this));
  146. MWF.require("MWF.widget.UUID", function(){
  147. MWF.UD.getDataJson("idea", function(json){
  148. if (json){
  149. if (json.ideas){
  150. this.setIdeaList(json.ideas);
  151. }
  152. }else{
  153. MWF.UD.getPublicData("idea", function(pjson){
  154. if (pjson){
  155. if (pjson.ideas){
  156. this.setIdeaList(pjson.ideas);
  157. }
  158. }
  159. }.bind(this));
  160. }
  161. }.bind(this));
  162. }.bind(this));
  163. },
  164. audioRecord: function(){
  165. if (!this.audioRecordNode) this.createAudioRecord();
  166. this.audioRecordNode.show();
  167. this.audioRecordNode.position({
  168. "relativeTo": this.options.mediaNode || this.node,
  169. "position": "center",
  170. "edge": "center"
  171. });
  172. MWF.require("MWF.widget.AudioRecorder", function () {
  173. this.audioRecorder = new MWF.widget.AudioRecorder(this.audioRecordNode, {
  174. "onSave" : function( blobFile ){
  175. this.soundFile = blobFile;
  176. this.audioRecordNode.hide();
  177. // this.page.get("div_image").node.set("src",base64Image);
  178. }.bind(this),
  179. "onCancel": function(){
  180. this.soundFile = null;
  181. this.audioRecordNode.hide();
  182. }.bind(this)
  183. }, null );
  184. }.bind(this));
  185. },
  186. createAudioRecord: function(){
  187. this.audioRecordNode = new Element("div", {"styles": this.css.handwritingNode}).inject(this.node, "after");
  188. var size = (this.options.mediaNode || this.node).getSize();
  189. // var y = Math.max(size.y, 320);
  190. // var x = Math.max(size.x, 400);
  191. // for (k in this.node.style){
  192. // if (this.node.style[k]) this.audioRecordNode.style[k] = this.node.style[k];
  193. // }
  194. var zidx = this.node.getStyle("z-index");
  195. this.audioRecordNode.setStyles({
  196. "height": ""+size.y+"px",
  197. "width": ""+size.x+"px",
  198. "z-index": zidx+1
  199. });
  200. },
  201. handwriting: function(){
  202. if (!this.handwritingNode) this.createHandwriting();
  203. if(this.handwritingNodeMask)this.handwritingNodeMask.show();
  204. this.handwritingNode.show();
  205. this.handwritingNode.position({
  206. "relativeTo": this.options.mediaNode || this.node,
  207. "position": "center",
  208. "edge": "center"
  209. });
  210. },
  211. createHandwriting: function(){
  212. this.handwritingNodeMask = new Element("div", {"styles": this.css.handwritingMask}).inject(this.node);
  213. this.handwritingNode = new Element("div", {"styles": this.css.handwritingNode}).inject(this.node, "after");
  214. //var size = (this.options.mediaNode || this.node).getSize();
  215. //var y = size.y;
  216. //var x = size.x;
  217. //兼容以前的默认高宽
  218. var x = 600;
  219. var y = 320;
  220. if (!layout.mobile){
  221. x = Math.max( this.options.tabletWidth || x , 500);
  222. y = Math.max(this.options.tabletHeight ? (parseInt(this.options.tabletHeight) + 110) : y, 320);
  223. //y = Math.max(size.y, 320);
  224. //x = Math.max(size.x, 480);
  225. }
  226. // for (k in this.node.style){
  227. // if (this.node.style[k]) this.handwritingNode.style[k] = this.node.style[k];
  228. // }
  229. var zidx = this.node.getStyle("z-index");
  230. this.handwritingNode.setStyles({
  231. "height": ""+y+"px",
  232. "width": ""+x+"px",
  233. "z-index": zidx+1
  234. });
  235. if( layout.mobile ){
  236. this.handwritingNode.addEvent('touchmove' , function(e){
  237. e.preventDefault();
  238. })
  239. }
  240. this.handwritingNode.position({
  241. "relativeTo": this.options.mediaNode || this.node,
  242. "position": "center",
  243. "edge": "center"
  244. });
  245. this.handwritingAreaNode = new Element("div", {"styles": this.css.handwritingAreaNode}).inject(this.handwritingNode);
  246. this.handwritingActionNode = new Element("div", {"styles": this.css.handwritingActionNode, "text": MWF.xApplication.process.Work.LP.saveWrite}).inject(this.handwritingNode);
  247. var h = this.handwritingActionNode.getSize().y+this.handwritingActionNode.getStyle("margin-top").toInt()+this.handwritingActionNode.getStyle("margin-bottom").toInt();
  248. h = y - h;
  249. this.handwritingAreaNode.setStyle("height", ""+h+"px");
  250. MWF.require("MWF.widget.Tablet", function () {
  251. this.tablet = new MWF.widget.Tablet(this.handwritingAreaNode, {
  252. "style": "default",
  253. "contentWidth" : this.options.tabletWidth || 0,
  254. "contentHeight" : this.options.tabletHeight || 0,
  255. "onSave" : function( base64code, base64Image, imageFile ){
  256. this.handwritingFile = imageFile;
  257. this.handwritingNode.hide();
  258. this.handwritingNodeMask.hide();
  259. // this.page.get("div_image").node.set("src",base64Image);
  260. }.bind(this),
  261. "onCancel": function(){
  262. this.handwritingFile = null;
  263. this.handwritingNode.hide();
  264. this.handwritingNodeMask.hide();
  265. }.bind(this)
  266. }, null );
  267. this.tablet.load();
  268. }.bind(this));
  269. this.handwritingActionNode.addEvent("click", function(){
  270. //this.handwritingNode.hide();
  271. if (this.tablet) this.tablet.save();
  272. }.bind(this));
  273. },
  274. setIdeaList: function(ideas){
  275. var _self = this;
  276. ideas.each(function(idea){
  277. new Element("div", {
  278. "styles": this.css.selectIdeaItemNode,
  279. "text": idea,
  280. "events": {
  281. "click": function(){
  282. if (_self.inputTextarea.get("value")==MWF.xApplication.process.Work.LP.inputText){
  283. _self.inputTextarea.set("value", this.get("text"));
  284. }else{
  285. _self.inputTextarea.set("value", _self.inputTextarea.get("value")+", "+this.get("text"));
  286. }
  287. },
  288. "dblclick": function(){
  289. if (_self.inputTextarea.get("value")==MWF.xApplication.process.Work.LP.inputText){
  290. _self.inputTextarea.set("value", this.get("text"));
  291. }else{
  292. _self.inputTextarea.set("value", _self.inputTextarea.get("value")+", "+this.get("text"));
  293. }
  294. },
  295. "mouseover": function(){this.setStyles(_self.css.selectIdeaItemNode_over);},
  296. "mouseout": function(){this.setStyles(_self.css.selectIdeaItemNode);}
  297. }
  298. }).inject(this.selectIdeaAreaNode);
  299. }.bind(this));
  300. },
  301. setButtons: function(){
  302. this.cancelButton = new Element("div", {"styles": this.css.cancelButton}).inject(this.buttonsArea);
  303. var iconNode = new Element("div", {"styles": this.css.cancelIconNode}).inject(this.cancelButton);
  304. var textNode = new Element("div", {"styles": this.css.cancelTextNode, "text": MWF.xApplication.process.Work.LP.cancel}).inject(this.cancelButton);
  305. this.okButton = new Element("div", {"styles": this.css.okButton}).inject(this.buttonsArea);
  306. var iconNode = new Element("div", {"styles": this.css.okIconNode}).inject(this.okButton);
  307. var textNode = new Element("div", {"styles": this.css.okTextNode, "text": MWF.xApplication.process.Work.LP.ok}).inject(this.okButton);
  308. this.cancelButton.addEvent("click", function(){
  309. this.destroy();
  310. this.fireEvent("cancel");
  311. }.bind(this));
  312. this.okButton.addEvent("click", function( ev ){
  313. if (!this.selectedRoute) {
  314. this.routeSelectorArea.setStyle("background-color", "#ffe9e9");
  315. //new mBox.Notice({
  316. // type: "error",
  317. // position: {"x": "center", "y": "top"},
  318. // move: false,
  319. // target: this.routeSelectorArea,
  320. // delayClose: 6000,
  321. // content: MWF.xApplication.process.Work.LP.mustSelectRoute
  322. //});
  323. MWF.xDesktop.notice(
  324. "error",
  325. {"x": "center", "y": "top"},
  326. MWF.xApplication.process.Work.LP.mustSelectRoute,
  327. this.routeSelectorArea,
  328. null, //{"x": 0, "y": 30}
  329. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  330. );
  331. return false;
  332. }
  333. debugger;
  334. var routeName = this.selectedRoute.retrieve("routeName") || this.selectedRoute.get("text");
  335. var opinion = this.inputTextarea.get("value");
  336. if (opinion === MWF.xApplication.process.Work.LP.inputText) opinion = "";
  337. var medias = [];
  338. if (this.handwritingFile) medias.push(this.handwritingFile);
  339. if (this.soundFile) medias.push(this.soundFile);
  340. if (this.videoFile) medias.push(this.videoFile);
  341. var currentRouteId = this.selectedRoute.retrieve("route");
  342. var routeData = this.getRouteData( currentRouteId );
  343. if( !opinion && medias.length === 0 ){
  344. if( routeData.opinionRequired == true ){
  345. this.inputTextarea.setStyle("background-color", "#ffe9e9");
  346. //new mBox.Notice({
  347. // type: "error",
  348. // position: {"x": "center", "y": "top"},
  349. // move: false,
  350. // target: this.inputTextarea,
  351. // delayClose: 6000,
  352. // content: MWF.xApplication.process.Work.LP.opinionRequired
  353. //});
  354. MWF.xDesktop.notice(
  355. "error",
  356. {"x": "center", "y": "top"},
  357. MWF.xApplication.process.Work.LP.opinionRequired,
  358. this.inputTextarea,
  359. null, //{"x": 0, "y": 30}
  360. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  361. );
  362. return false;
  363. }
  364. }
  365. var appendTaskOrgItem = "";
  366. if( routeData.type === "appendTask" && routeData.appendTaskIdentityType === "select" ){
  367. if( !this.orgItems || this.orgItems.length === 0 ){
  368. //new mBox.Notice({
  369. // type: "error",
  370. // position: {"x": "center", "y": "top"},
  371. // move: false,
  372. // target: this.orgsArea,
  373. // delayClose: 6000,
  374. // content: MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig //"没有配置转交人,请联系管理员"
  375. //});
  376. MWF.xDesktop.notice(
  377. "error",
  378. {"x": "center", "y": "center"},
  379. MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig,
  380. this.node,
  381. null, //{"x": 0, "y": 30}
  382. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  383. );
  384. return false;
  385. }else{
  386. appendTaskOrgItem = this.orgItems[0]
  387. }
  388. }
  389. this.saveOrgsWithCheckEmpower( function(){
  390. var array = [routeName, opinion, medias];
  391. if( appendTaskOrgItem ){
  392. var appandTaskIdentityList = appendTaskOrgItem.getData();
  393. if( !appandTaskIdentityList || appandTaskIdentityList.length === 0){
  394. //new mBox.Notice({
  395. // type: "error",
  396. // position: {"x": "center", "y": "top"},
  397. // move: false,
  398. // target: this.orgsArea,
  399. // delayClose: 6000,
  400. // content: MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice //"请选择转交人"
  401. //});
  402. MWF.xDesktop.notice(
  403. "error",
  404. {"x": "center", "y": "center"},
  405. MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice,
  406. this.node,
  407. {"x": 0, "y": 30},
  408. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  409. );
  410. return;
  411. }else{
  412. array.push( appendTaskOrgItem.getData() );
  413. appendTaskOrgItem.setData([]);
  414. }
  415. }
  416. debugger;
  417. if( routeData.validationScriptText ){
  418. var validation = this.form.Macro.exec(routeData.validationScriptText, this);
  419. if( !validation || validation.toString() !== "true" ){
  420. if( typeOf(validation) === "string" ){
  421. MWF.xDesktop.notice(
  422. "error",
  423. {"x": "center", "y": "center"},
  424. validation,
  425. this.node,
  426. {"x": 0, "y": 30},
  427. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  428. );
  429. return false;
  430. }else{
  431. //"路由校验失败"
  432. MWF.xDesktop.notice(
  433. "error",
  434. {"x": "center", "y": "center"},
  435. MWF.xApplication.process.Work.LP.routeValidFailure,
  436. this.node,
  437. {"x": 0, "y": 30},
  438. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  439. );
  440. return false;
  441. }
  442. }
  443. }
  444. this.node.mask({
  445. "inject": {"where": "bottom", "target": this.node},
  446. "destroyOnHide": true,
  447. "style": {
  448. "background-color": "#999",
  449. "opacity": 0.3,
  450. "z-index":600
  451. }
  452. });
  453. this.fireEvent("submit", array );
  454. }.bind(this))
  455. }.bind(this));
  456. },
  457. destroy: function(){
  458. this.node.empty();
  459. delete this.task;
  460. delete this.node;
  461. delete this.routeSelectorTile;
  462. delete this.routeSelectorArea;
  463. delete this.routeOpinionTile;
  464. delete this.routeOpinionArea;
  465. delete this.buttonsArea;
  466. delete this.inputOpinionNode;
  467. delete this.inputTextarea;
  468. delete this.cancelButton;
  469. delete this.okButton;
  470. },
  471. getRouteDataList : function(){
  472. if( !this.routeDataList ){
  473. o2.Actions.get("x_processplatform_assemble_surface").listRoute( {"valueList":this.task.routeList} , function( json ){
  474. json.data.each( function(d){
  475. d.selectConfigList = JSON.parse( d.selectConfig || "[]" );
  476. }.bind(this));
  477. this.routeDataList = json.data;
  478. }.bind(this), null, false );
  479. }
  480. return this.routeDataList;
  481. },
  482. getRouteData : function( routeId ){
  483. var routeList = this.getRouteDataList();
  484. for( var i=0; i<routeList.length; i++ ){
  485. if( routeList[i].id === routeId ){
  486. return routeList[i];
  487. }
  488. }
  489. },
  490. getMaxOrgLength : function(){
  491. var routeList = this.getRouteDataList();
  492. var length = 0;
  493. routeList.each( function(route){
  494. length = Math.max( length, route.selectConfigList.length);
  495. });
  496. return length;
  497. },
  498. getOrgData : function( routeId ){
  499. var routeList = this.getRouteDataList();
  500. for( var i=0; i<routeList.length; i++ ){
  501. if( routeList[i].id === routeId ){
  502. return routeList[i].selectConfigList;
  503. }
  504. }
  505. },
  506. loadOrgs : function( route ){
  507. if( !this.form || !route ){
  508. this.orgsArea.hide();
  509. this.setSize( 0 );
  510. return;
  511. }else{
  512. this.orgsArea.show();
  513. }
  514. if( !this.orgTableObject )this.orgTableObject = {};
  515. if( !this.orgItemsObject )this.orgItemsObject = {};
  516. var isLoaded = false;
  517. for( var key in this.orgTableObject ){
  518. if( route === key ){
  519. this.orgTableObject[key].show();
  520. this.orgItems = this.orgItemsObject[key] || [];
  521. var data = this.getOrgData( route );
  522. this.setSize( data.length );
  523. isLoaded = true;
  524. }else{
  525. this.orgTableObject[key].hide();
  526. }
  527. }
  528. if( isLoaded )return;
  529. this.orgItems = [];
  530. this.orgItemsObject[route] = this.orgItems;
  531. var data = this.getOrgData( route );
  532. this.setSize( data.length );
  533. if( data.length ){
  534. this.orgsArea.show();
  535. var len = data.length;
  536. var routeOrgTable = new Element("table",{
  537. "cellspacing" : 0, "cellpadding" : 0, "border" : 0, "width" : "100%",
  538. "styles" : this.css.routeOrgTable
  539. }).inject( this.orgsArea );
  540. this.orgTableObject[route] = routeOrgTable;
  541. //if( len <= this.options.maxOrgCountPerline ){
  542. // var width = 1 / len * 100;
  543. // var tr = new Element("tr").inject( routeOrgTable );
  544. // for (var n=0; n<len; n++){
  545. // new Element("td", { "width" : width+"%", "styles" : this.css.routeOrgOddTd }).inject( tr );
  546. // }
  547. //}else{
  548. // var lines = ((len+1)/this.options.maxOrgCountPerline).toInt();
  549. // var width = 1 / this.options.maxOrgCountPerline * 100;
  550. // for( var n=0; n<lines; n++ ){
  551. // var tr = new Element("tr").inject( routeOrgTable );
  552. // for( var i=0; i<this.options.maxOrgCountPerline; i++ ){
  553. // new Element("td", { "width" : width+"%", "styles" : this.css.routeOrgOddTd }).inject( tr );
  554. // }
  555. // }
  556. //}
  557. //
  558. //var tds = routeOrgTable.getElements("td");
  559. //data.each( function( config, i ){
  560. // this.loadOrg( tds[i], config )
  561. //}.bind(this))
  562. var lines = ((len+1)/2).toInt();
  563. for (var n=0; n<lines; n++){
  564. var tr = new Element("tr").inject( routeOrgTable );
  565. new Element("td", { "width" : "50%", "styles" : this.css.routeOrgOddTd }).inject( tr );
  566. new Element("td", { "width" : "50%", "styles" : this.css.routeOrgEvenTd }).inject( tr );
  567. }
  568. var trs = routeOrgTable.getElements("tr");
  569. data.each( function( config, i ){
  570. var sNode;
  571. var width;
  572. if (i+1==len && (len % 2===1)){
  573. sNode = trs[trs.length-1].getFirst("td");
  574. sNode.set("colspan", 2);
  575. trs[trs.length-1].getLast("td").destroy();
  576. sNode.setStyle("border","0px");
  577. sNode.set("width","100%");
  578. this.loadOrg( sNode, config, "all")
  579. }else{
  580. var row = ((i+2)/2).toInt();
  581. var tr = trs[row-1];
  582. sNode = (i % 2===0) ? tr.getFirst("td") : tr.getLast("td");
  583. this.loadOrg( sNode, config, (i % 2===0) ? "left" : "right" )
  584. }
  585. }.bind(this))
  586. }else{
  587. this.orgsArea.hide();
  588. }
  589. },
  590. loadOrg : function( container, json, position ){
  591. var titleNode = new Element("div.selectorTitle", {
  592. "styles" : this.css.selectorTitle
  593. }).inject(container);
  594. var titleTextNode = new Element("div.selectorTitleText", {
  595. "text": json.title,
  596. "styles" : this.css.selectorTitleText
  597. }).inject(titleNode);
  598. var errorNode = new Element("div.selectorErrorNode", {
  599. "styles" : this.css.selectorErrorNode
  600. }).inject(titleNode);
  601. var contentNode = new Element("div.selectorContent", {
  602. "styles" : this.css.selectorContent
  603. }).inject(container);
  604. var org = new MWF.xApplication.process.Work.Processor.Org( contentNode, this.form, json, this );
  605. org.errContainer = errorNode;
  606. org.summitDlalog = this;
  607. org.load();
  608. this.orgItems.push( org )
  609. },
  610. getCurrentRouteSelectorList : function(){
  611. var selectorList = [];
  612. var currentRoute = this.selectedRoute ? this.selectedRoute.retrieve("route") : "";
  613. var orgList = this.orgItemsObject[currentRoute];
  614. if( !orgList )return [];
  615. orgList.each( function( org ){
  616. if( org.selector && org.selector.selector ){
  617. selectorList.push( org.selector.selector );
  618. }
  619. }.bind(this))
  620. return selectorList;
  621. },
  622. getOffsetY : function(node){
  623. return (node.getStyle("margin-top").toInt() || 0 ) +
  624. (node.getStyle("margin-bottom").toInt() || 0 ) +
  625. (node.getStyle("padding-top").toInt() || 0 ) +
  626. (node.getStyle("padding-bottom").toInt() || 0 )+
  627. (node.getStyle("border-top-width").toInt() || 0 ) +
  628. (node.getStyle("border-bottom-width").toInt() || 0 );
  629. },
  630. setSize : function( currentOrgLength ){
  631. if( layout.mobile )return;
  632. var lines = ((currentOrgLength+1)/2).toInt();
  633. var flag = false;
  634. var height = 0;
  635. if( this.routeSelectorTile )height = height + this.getOffsetY(this.routeSelectorTile) + this.routeSelectorTile.getStyle("height").toInt();
  636. if( this.routeSelectorArea )height = height + this.getOffsetY(this.routeSelectorArea) + this.routeSelectorArea.getStyle("height").toInt();
  637. if( this.routeOpinionTile )height = height + this.getOffsetY(this.routeOpinionTile) + this.routeOpinionTile.getStyle("height").toInt();
  638. if( this.routeOpinionArea )height = height + this.getOffsetY(this.routeOpinionArea) + this.routeOpinionArea.getStyle("height").toInt();
  639. //if( this.buttonsArea )height = height + this.getOffsetY(this.buttonsArea) + this.buttonsArea.getStyle("height").toInt();
  640. if( lines > 0 ){
  641. if( this.orgsTile )height = height + this.getOffsetY(this.orgsTile) + this.orgsTile.getStyle("height").toInt();
  642. height = height + lines*this.options.orgHeight + this.getOffsetY(this.orgsArea);
  643. this.node.setStyle( "height", height );
  644. //flag = (lines*this.options.orgHeight + 431) > Math.floor( this.form.app.content.getSize().y * 0.9);
  645. //this.node.store("height", Math.min( Math.floor( this.form.app.content.getSize().y * 0.9) , lines*this.options.orgHeight + 431 ));
  646. }else{
  647. this.node.setStyle( "height", height );
  648. //this.node.store("height", 401 );
  649. }
  650. if( this.getMaxOrgLength() > 1 ){
  651. this.node.setStyles( this.css.node_wide );
  652. this.inputOpinionNode.setStyles( this.css.inputOpinionNode_wide );
  653. this.inputTextarea.setStyles( this.css.inputTextarea_wide );
  654. this.inputTextareaStyle = this.css.inputTextarea_wide;
  655. this.selectIdeaNode.setStyles( this.css.selectIdeaNode_wide );
  656. }else{
  657. this.node.setStyles( this.css.node );
  658. this.inputOpinionNode.setStyles( this.css.inputOpinionNode );
  659. this.inputTextarea.setStyles( this.css.inputTextarea );
  660. this.inputTextareaStyle = this.css.inputTextarea;
  661. this.selectIdeaNode.setStyles( this.css.selectIdeaNode );
  662. }
  663. //this.node.store("width", this.node.getStyle("width").toInt() + ( flag ? 20 : 0 ));
  664. this.fireEvent("resize");
  665. },
  666. validationOrgs : function(){
  667. if( !this.orgItems || !this.orgItems.length )return true;
  668. var flag = true;
  669. this.orgItems.each( function(item){
  670. if( !item.validation() )flag = false;
  671. }.bind(this));
  672. return flag;
  673. },
  674. isOrgsHasEmpower: function(){
  675. if( !this.orgItems || !this.orgItems.length )return true;
  676. var flag = false;
  677. this.needCheckEmpowerOrg = [];
  678. this.orgItems.each( function(item){
  679. if( item.hasEmpowerIdentity() ){
  680. this.needCheckEmpowerOrg.push(item);
  681. flag = true;
  682. }
  683. }.bind(this));
  684. return flag;
  685. },
  686. saveOrgs : function( keepSilent ){
  687. if( !this.orgItems || !this.orgItems.length )return true;
  688. var flag = true;
  689. this.orgItems.each( function(item){
  690. if( !item.save( !keepSilent ) )flag = false;
  691. }.bind(this));
  692. return flag;
  693. },
  694. saveOrgsWithCheckEmpower : function( callback ){
  695. if( !this.orgItems || !this.orgItems.length ){
  696. if( callback )callback();
  697. return true;
  698. }
  699. if( !this.validationOrgs() )return false;
  700. if( !this.isOrgsHasEmpower() ){
  701. if( callback )callback();
  702. return true;
  703. }
  704. //this.checkEmpowerMode = true;
  705. this.showEmpowerDlg( callback );
  706. },
  707. showEmpowerDlg : function( callback ){
  708. //this.empowerMask = new Element("div", {"styles": this.css.handwritingMask}).inject(this.node);
  709. //this.needCheckEmpowerOrg.each( function(org){
  710. // org.saveCheckedEmpowerData();
  711. //}.bind(this));
  712. var empowerNode = new Element("div.empowerNode", {"styles": this.css.empowerNode});
  713. var empowerTitleNode = new Element("div",{
  714. text : MWF.xApplication.process.Xform.LP.empowerDlgText,
  715. styles : this.css.empowerTitleNode
  716. }).inject(empowerNode);
  717. var orgs = this.needCheckEmpowerOrg;
  718. var len = orgs.length;
  719. var lines = ((len+1)/2).toInt();
  720. var empowerTable = new Element("table",{
  721. "cellspacing" : 0, "cellpadding" : 0, "border" : 0, "width" : "100%",
  722. "styles" : this.css.empowerTable
  723. }).inject( empowerNode );
  724. for (var n=0; n<lines; n++){
  725. var tr = new Element("tr").inject( empowerTable );
  726. new Element("td", { "width" : "50%", "styles" : this.css.empowerOddTd }).inject( tr );
  727. new Element("td", { "width" : "50%", "styles" : this.css.empowerEvenTd }).inject( tr );
  728. }
  729. var trs = empowerTable.getElements("tr");
  730. orgs.each( function( org, i ){
  731. var sNode;
  732. var width;
  733. if (i+1==len && (len % 2===1)){
  734. sNode = trs[trs.length-1].getFirst("td");
  735. sNode.set("colspan", 2);
  736. trs[trs.length-1].getLast("td").destroy();
  737. width = "50%";
  738. }else{
  739. var row = ((i+2)/2).toInt();
  740. var tr = trs[row-1];
  741. sNode = (i % 2===0) ? tr.getFirst("td") : tr.getLast("td");
  742. }
  743. var titleNode = new Element("div.empowerAreaTitle", {
  744. "styles" : this.css.empowerAreaTitle
  745. }).inject(sNode);
  746. var titleTextNode = new Element("div.empowerAreaTitleText", {
  747. "text": org.json.title,
  748. "styles" : this.css.empowerAreaTitleText
  749. }).inject(titleNode);
  750. var selectAllNode = new Element("div",{
  751. styles : {
  752. float : "right"
  753. }
  754. }).inject(titleNode);
  755. var contentNode = new Element("div.empowerAreaContent", {
  756. "styles" : this.css.empowerAreaContent
  757. }).inject(sNode);
  758. org.loadCheckEmpower( null, contentNode, selectAllNode );
  759. }.bind(this));
  760. empowerNode.setStyle( "height", lines*this.options.orgHeight + 20 );
  761. //var dlgHeight = Math.min( Math.floor( this.form.app.content.getSize().y * 0.9) , lines*this.options.orgHeight + 151 );
  762. //var width = this.node.retrieve("width");
  763. //empowerNode.setStyle( "width", width );
  764. var width = "880";
  765. //if( len > 1 ){
  766. // width = "840"
  767. //}else{
  768. // width = "420"
  769. //}
  770. empowerNode.setStyle( "width", width+"px" );
  771. this.node.getParent().mask( {
  772. "style": this.css.mask
  773. });
  774. this.empowerDlg = o2.DL.open({
  775. "title": MWF.xApplication.process.Xform.LP.selectEmpower,
  776. "style": this.form.json.dialogStyle || "user",
  777. "isResize": false,
  778. "content": empowerNode,
  779. //"container" : this.node,
  780. "width": width, //600,
  781. "height": "auto", //dlgHeight,
  782. "mark" : false,
  783. "buttonList": [
  784. {
  785. "type" : "ok",
  786. "text": MWF.LP.process.button.ok,
  787. "action": function(d, e){
  788. //if (this.empowerDlg) this.empowerDlg.okButton.click();
  789. orgs.each( function( org, i ){
  790. org.saveCheckedEmpowerData( function(){
  791. if( i === orgs.length-1 ){
  792. if( callback )callback();
  793. this.node.getParent().unmask();
  794. this.empowerDlg.close();
  795. }
  796. }.bind(this))
  797. }.bind(this))
  798. }.bind(this)
  799. },
  800. {
  801. "type" : "cancel",
  802. "text": MWF.LP.process.button.cancel,
  803. "action": function(){
  804. this.node.getParent().unmask();
  805. this.empowerDlg.close();
  806. }.bind(this)
  807. }
  808. ]
  809. });
  810. }
  811. });
  812. MWF.xApplication.process.Work.Processor.Org = new Class({
  813. Implements: [Options, Events],
  814. options: {
  815. moduleEvents : ["queryLoadSelector","postLoadSelector","queryLoadCategory","postLoadCategory","selectCategory", "unselectCategory","queryLoadItem","postLoadItem","selectItem", "unselectItem","change"]
  816. },
  817. initialize: function (container, form, json, processor, options) {
  818. this.form = form;
  819. this.json = json;
  820. this.processor = processor;
  821. this.container = $(container);
  822. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  823. this.setOptions(options);
  824. },
  825. load : function(){
  826. var options = this.getOptions();
  827. if(options){
  828. this.selector = new MWF.O2Selector(this.container, options);
  829. }
  830. },
  831. _getOrgOptions: function(){
  832. this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
  833. if( this.selectTypeList.contains( "identity" ) ) {
  834. this.identityOptions = new MWF.xApplication.process.Work.Processor.IdentityOptions(this.form, this.json);
  835. }
  836. if( this.selectTypeList.contains( "unit" ) ) {
  837. this.unitOptions = new MWF.xApplication.process.Work.Processor.UnitOptions(this.form, this.json);
  838. }
  839. //if( this.selectTypeList.contains( "group" ) ){
  840. // this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
  841. //}
  842. },
  843. getOptions: function(){
  844. var _self = this;
  845. this._getOrgOptions();
  846. if( this.selectTypeList.length === 0 )return false;
  847. var exclude = [];
  848. if( this.json.exclude ){
  849. var v = this.form.Macro.exec(this.json.exclude.code, this);
  850. exclude = typeOf(v)==="array" ? v : [v];
  851. }
  852. var identityOpt;
  853. if( this.identityOptions ){
  854. identityOpt = this.identityOptions.getOptions();
  855. if (this.json.identityRange!=="all"){
  856. if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
  857. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
  858. return false;
  859. }
  860. }
  861. if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
  862. if (!identityOpt.dutys || !identityOpt.dutys.length){
  863. this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
  864. return false;
  865. }
  866. }
  867. identityOpt.values = this.getValue();
  868. identityOpt.exclude = exclude;
  869. }
  870. var unitOpt;
  871. if( this.unitOptions ){
  872. unitOpt = this.unitOptions.getOptions();
  873. if (this.json.unitRange!=="all"){
  874. if ( !unitOpt.units || !unitOpt.units.length){
  875. this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
  876. return false;
  877. }
  878. }
  879. unitOpt.values = this.getValue();
  880. unitOpt.exclude = exclude;
  881. }
  882. //var groupOpt;
  883. //if( this.groupOptions ){
  884. // groupOpt = this.groupOptions.getOptions();
  885. // groupOpt.values = (this.json.isInput) ? [] : values;
  886. // groupOpt.exclude = exclude;
  887. //}
  888. var defaultOpt = {
  889. "style" : "process",
  890. "width" : "auto",
  891. "height" : "240",
  892. "embedded" : true,
  893. "hasLetter" : false, //字母
  894. "hasTop" : true, //可选、已选的标题
  895. "hasShuttle" : true //穿梭按钮
  896. };
  897. debugger;
  898. if( this.json.events && typeOf(this.json.events) === "object" ){
  899. Object.each(this.json.events, function(e, key){
  900. if (e.code){
  901. if (this.options.moduleEvents.indexOf(key)!==-1){
  902. //this.addEvent(key, function(event){
  903. // return this.form.Macro.fire(e.code, this, event);
  904. //}.bind(this));
  905. if( key === "postLoadSelector" ) {
  906. this.addEvent("loadSelector", function (selector) {
  907. return this.form.Macro.fire(e.code, selector);
  908. }.bind(this))
  909. }else if( key === "queryLoadSelector"){
  910. defaultOpt["onQueryLoad"] = function(target){
  911. return this.form.Macro.fire(e.code, target);
  912. }.bind(this)
  913. }else{
  914. defaultOpt["on"+key.capitalize()] = function(target){
  915. return this.form.Macro.fire(e.code, target);
  916. }.bind(this)
  917. }
  918. }
  919. }
  920. }.bind(this));
  921. }
  922. if( this.form.json.selectorStyle ){
  923. defaultOpt = Object.merge( Object.clone(this.form.json.selectorStyle), defaultOpt );
  924. if( this.form.json.selectorStyle.style )defaultOpt.style = this.form.json.selectorStyle.style;
  925. }
  926. if( this.selectTypeList.length === 1 ){
  927. return Object.merge( defaultOpt, {
  928. "type": this.selectTypeList[0],
  929. "onLoad": function(){
  930. //this 为 selector
  931. _self.selectOnLoad(this, this.selector )
  932. }
  933. //"onComplete": function(items){
  934. // this.selectOnComplete(items);
  935. //}.bind(this),
  936. //"onCancel": this.selectOnCancel.bind(this),
  937. //"onClose": this.selectOnClose.bind(this)
  938. }, identityOpt || unitOpt )
  939. }else if( this.selectTypeList.length > 1 ){
  940. var options = {
  941. "type" : "",
  942. "types" : this.selectTypeList,
  943. "onLoad": function(){
  944. //this 为 selector
  945. _self.selectOnLoad(this)
  946. }
  947. //"onComplete": function(items){
  948. // this.selectOnComplete(items);
  949. //}.bind(this),
  950. //"onCancel": this.selectOnCancel.bind(this),
  951. //"onClose": this.selectOnClose.bind(this)
  952. };
  953. if( identityOpt ){
  954. options.identityOptions = Object.merge( defaultOpt, identityOpt);
  955. }
  956. if( unitOpt ){
  957. options.unitOptions = Object.merge( defaultOpt, unitOpt);
  958. }
  959. //if( groupOpt )options.groupOptions = groupOpt;
  960. return options;
  961. }
  962. },
  963. //selectOnComplete: function(items){
  964. // var array = [];
  965. // items.each(function(item){
  966. // array.push(item.data);
  967. // }.bind(this));
  968. // this.checkEmpower( array, function( data ){
  969. // var values = [];
  970. // data.each(function(d){
  971. // values.push(MWF.org.parseOrgData(d, true));
  972. // }.bind(this));
  973. //
  974. // this.setData(values);
  975. // //this.validationMode();
  976. // //this.validation();
  977. // this.fireEvent("select");
  978. // }.bind(this))
  979. //},
  980. //selectOnCancel: function(){
  981. // //this.validation();
  982. //},
  983. selectOnLoad: function( selector ){
  984. //if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  985. this.fireEvent("loadSelector", [selector])
  986. },
  987. //selectOnClose: function(){
  988. // //v = this._getBusinessData();
  989. // //if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  990. //},
  991. hasEmpowerIdentity : function(){
  992. var data = this.getData();
  993. if(!this.empowerChecker )this.empowerChecker = new MWF.xApplication.process.Work.Processor.EmpowerChecker(this.form, this.json, this.processor);
  994. return this.empowerChecker.hasEmpowerIdentity( data );
  995. },
  996. checkEmpower : function( data, callback, container, selectAllNode ){
  997. if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  998. if(!this.empowerChecker )this.empowerChecker = new MWF.xApplication.process.Work.Processor.EmpowerChecker(this.form, this.json, this.processor);
  999. this.empowerChecker.selectAllNode = selectAllNode;
  1000. this.empowerChecker.load(data, callback, container);
  1001. }else{
  1002. if( callback )callback( data );
  1003. }
  1004. },
  1005. loadCheckEmpower : function( callback, container, selectAllNode ){
  1006. this.checkEmpower( this.getData(), callback, container, selectAllNode)
  1007. },
  1008. saveCheckedEmpowerData:function( callback ){
  1009. var data = this.getData();
  1010. this.empowerChecker.replaceEmpowerIdentity(data, function( newData ){
  1011. var values = [];
  1012. newData.each(function(d){
  1013. values.push(MWF.org.parseOrgData(d, true));
  1014. }.bind(this));
  1015. this.setData( values );
  1016. if( callback )callback(values)
  1017. }.bind(this))
  1018. },
  1019. //saveWithCheckEmpower: function( isValid, callback ){
  1020. // var checkEmpowerData = function(){
  1021. // var array = this.getData();
  1022. // this.checkEmpower( array, function( data ){
  1023. // var values = [];
  1024. // data.each(function(d){
  1025. // values.push(MWF.org.parseOrgData(d, true));
  1026. // }.bind(this));
  1027. // this.setData( values );
  1028. // if( callback )callback(values)
  1029. // }.bind(this), container, selectAllNode)
  1030. // }.bind(this)
  1031. // if( isValid ){
  1032. // if( this.validation() ){
  1033. // checkEmpowerData( function(){
  1034. // if(callback)callback();
  1035. // }.bind(this));
  1036. // return true;
  1037. // }else{
  1038. // return false;
  1039. // }
  1040. // }else{
  1041. // //this.setData( this.getData() );
  1042. // checkEmpowerData( function(){
  1043. // if(callback)callback();
  1044. // }.bind(this));
  1045. // return true;
  1046. // }
  1047. //},
  1048. save: function( isValid ){
  1049. if( isValid ){
  1050. if( this.validation() ){
  1051. return true;
  1052. }else{
  1053. return false;
  1054. }
  1055. }else{
  1056. this.setData( this.getData() );
  1057. return true;
  1058. }
  1059. },
  1060. resetSelectorData : function(){
  1061. if( this.selector && this.selector.selector ){
  1062. this.selector.selector.emptySelectedItems();
  1063. this.selector.selector.options.values = this.getValue();
  1064. this.selector.selector.setSelectedItem();
  1065. }
  1066. },
  1067. resetData: function(){
  1068. var v = this.getValue();
  1069. //this.setData((v) ? v.join(", ") : "");
  1070. this.setData(v);
  1071. },
  1072. getData: function(){
  1073. if( this.selector ){
  1074. return this.getSelectedData();
  1075. }else{
  1076. return this.getValue();
  1077. }
  1078. },
  1079. getSelectedData : function(){
  1080. var data = [];
  1081. if( this.selector && this.selector.selector){
  1082. this.selector.selector.selectedItems.each( function( item ){
  1083. data.push( MWF.org.parseOrgData(item.data) );
  1084. })
  1085. }
  1086. return data;
  1087. },
  1088. getValue: function(){
  1089. var value = this._getBusinessData();
  1090. if (!value) value = this._computeValue();
  1091. return value || "";
  1092. },
  1093. _computeValue: function(){
  1094. var values = [];
  1095. if (this.json.identityValue) {
  1096. this.json.identityValue.each(function(v){ if (v) values.push(v)});
  1097. }
  1098. if (this.json.unitValue) {
  1099. this.json.unitValue.each(function(v){ if (v) values.push(v)});
  1100. }
  1101. if (this.json.dutyValue) {
  1102. var dutys = JSON.decode(this.json.dutyValue);
  1103. var par;
  1104. if (dutys.length){
  1105. dutys.each(function(duty){
  1106. if (duty.code) par = this.form.Macro.exec(duty.code, this);
  1107. var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
  1108. var d = this.form.Macro.exec(code, this);
  1109. if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
  1110. d.each(function(dd){if (dd) values.push(dd);});
  1111. }.bind(this));
  1112. }
  1113. }
  1114. if (this.json.defaultValue && this.json.defaultValue.code){
  1115. var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
  1116. if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
  1117. fd.each(function(fdd){
  1118. if (fdd){
  1119. if (typeOf(fdd)==="string"){
  1120. var data;
  1121. this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = json.data }.bind(this), null, fdd, false);
  1122. values.push(data);
  1123. }else{
  1124. values.push(fdd);
  1125. }
  1126. }
  1127. }.bind(this));
  1128. }
  1129. if (this.json.count>0){
  1130. return values.slice(0, this.json.count);
  1131. }
  1132. return values;
  1133. //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  1134. },
  1135. getOrgAction: function(){
  1136. if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1137. //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  1138. return this.orgAction;
  1139. },
  1140. setData: function(value){
  1141. if (!value) return false;
  1142. var oldValues = this.getValue();
  1143. var values = [];
  1144. var type = typeOf(value);
  1145. if (type==="array"){
  1146. value.each(function(v){
  1147. var vtype = typeOf(v);
  1148. var data = null;
  1149. if (vtype==="string"){
  1150. this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data); }.bind(this), error, v, false);
  1151. }
  1152. if (vtype==="object") data = v;
  1153. if (data)values.push(data);
  1154. }.bind(this));
  1155. }
  1156. if (type==="string"){
  1157. var vData;
  1158. this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data); }.bind(this), error, value, false);
  1159. if (vData)values.push(vData);
  1160. }
  1161. if (type==="object")values.push(value);
  1162. var change = false;
  1163. if (oldValues.length && values.length){
  1164. if (oldValues.length === values.length){
  1165. for (var i=0; i<oldValues.length; i++){
  1166. if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
  1167. change = true;
  1168. break;
  1169. }
  1170. }
  1171. }else{
  1172. change = true;
  1173. }
  1174. }else if (values.length || oldValues.length) {
  1175. change = true;
  1176. }
  1177. this._setBusinessData(values);
  1178. if (change) this.fireEvent("change");
  1179. },
  1180. getValueMethod: function(value){
  1181. if (value){
  1182. var flag = value.substr(value.length-1, 1);
  1183. switch (flag.toLowerCase()){
  1184. case "i":
  1185. return "getIdentity";
  1186. case "p":
  1187. return "getPerson";
  1188. case "u":
  1189. return "getUnit";
  1190. case "g":
  1191. return "getGroup";
  1192. default:
  1193. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1194. }
  1195. }
  1196. return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
  1197. },
  1198. _getBusinessData: function(){
  1199. if (this.json.section=="yes"){
  1200. return this._getBusinessSectionData();
  1201. }else {
  1202. if (this.json.type==="Opinion"){
  1203. return this._getBusinessSectionDataByPerson();
  1204. }else{
  1205. return this.form.businessData.data[this.json.name] || "";
  1206. }
  1207. }
  1208. },
  1209. _getBusinessSectionData: function(){
  1210. switch (this.json.sectionBy){
  1211. case "person":
  1212. return this._getBusinessSectionDataByPerson();
  1213. break;
  1214. case "unit":
  1215. return this._getBusinessSectionDataByUnit();
  1216. break;
  1217. case "activity":
  1218. return this._getBusinessSectionDataByActivity();
  1219. break;
  1220. case "script":
  1221. return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
  1222. break;
  1223. default:
  1224. return this.form.businessData.data[this.json.name] || "";
  1225. }
  1226. },
  1227. _getBusinessSectionDataByPerson: function(){
  1228. var dataObj = this.form.businessData.data[this.json.name];
  1229. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  1230. },
  1231. _getBusinessSectionDataByUnit: function(){
  1232. var dataObj = this.form.businessData.data[this.json.name];
  1233. if (!dataObj) return "";
  1234. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  1235. return (key) ? (dataObj[key] || "") : "";
  1236. },
  1237. _getBusinessSectionDataByActivity: function(){
  1238. var dataObj = this.form.businessData.data[this.json.name];
  1239. if (!dataObj) return "";
  1240. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  1241. return (key) ? (dataObj[key] || "") : "";
  1242. },
  1243. _getBusinessSectionDataByScript: function(code){
  1244. var dataObj = this.form.businessData.data[this.json.name];
  1245. if (!dataObj) return "";
  1246. var key = this.form.Macro.exec(code, this);
  1247. return (key) ? (dataObj[key] || "") : "";
  1248. },
  1249. _setBusinessData: function(v){
  1250. if (this.json.section=="yes"){
  1251. this._setBusinessSectionData(v);
  1252. }else {
  1253. if (this.json.type==="Opinion"){
  1254. this._setBusinessSectionDataByPerson(v);
  1255. }else{
  1256. if (this.form.businessData.data[this.json.name]){
  1257. this.form.businessData.data[this.json.name] = v;
  1258. }else{
  1259. this.form.businessData.data[this.json.name] = v;
  1260. this.form.Macro.environment.setData(this.form.businessData.data);
  1261. }
  1262. if (this.json.isTitle) this.form.businessData.work.title = v;
  1263. }
  1264. }
  1265. },
  1266. _setBusinessSectionData: function(v){
  1267. switch (this.json.sectionBy){
  1268. case "person":
  1269. this._setBusinessSectionDataByPerson(v);
  1270. break;
  1271. case "unit":
  1272. this._setBusinessSectionDataByUnit(v);
  1273. break;
  1274. case "activity":
  1275. this._setBusinessSectionDataByActivity(v);
  1276. break;
  1277. case "script":
  1278. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  1279. break;
  1280. default:
  1281. if (this.form.businessData.data[this.json.name]){
  1282. this.form.businessData.data[this.json.name] = v;
  1283. }else{
  1284. this.form.businessData.data[this.json.name] = v;
  1285. this.form.Macro.environment.setData(this.form.businessData.data);
  1286. }
  1287. }
  1288. },
  1289. _setBusinessSectionDataByPerson: function(v){
  1290. var resetData = false;
  1291. var key = layout.desktop.session.user.id;
  1292. var dataObj = this.form.businessData.data[this.json.name];
  1293. if (!dataObj){
  1294. dataObj = {};
  1295. this.form.businessData.data[this.json.name] = dataObj;
  1296. resetData = true;
  1297. }
  1298. if (!dataObj[key]) resetData = true;
  1299. dataObj[key] = v;
  1300. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1301. },
  1302. _setBusinessSectionDataByUnit: function(v){
  1303. var resetData = false;
  1304. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  1305. if (key){
  1306. var dataObj = this.form.businessData.data[this.json.name];
  1307. if (!dataObj){
  1308. dataObj = {};
  1309. this.form.businessData.data[this.json.name] = dataObj;
  1310. resetData = true;
  1311. }
  1312. if (!dataObj[key]) resetData = true;
  1313. dataObj[key] = v;
  1314. }
  1315. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1316. },
  1317. _setBusinessSectionDataByActivity: function(v){
  1318. var resetData = false;
  1319. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  1320. if (key){
  1321. var dataObj = this.form.businessData.data[this.json.name];
  1322. if (!dataObj){
  1323. dataObj = {};
  1324. this.form.businessData.data[this.json.name] = dataObj;
  1325. resetData = true;
  1326. }
  1327. if (!dataObj[key]) resetData = true;
  1328. dataObj[key] = v;
  1329. }
  1330. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1331. },
  1332. _setBusinessSectionDataByScript: function(code, v){
  1333. var resetData = false;
  1334. var key = this.form.Macro.exec(code, this);
  1335. if (key){
  1336. var dataObj = this.form.businessData.data[this.json.name];
  1337. if (!dataObj){
  1338. dataObj = {};
  1339. this.form.businessData.data[this.json.name] = dataObj;
  1340. resetData = true;
  1341. }
  1342. if (!dataObj[key]) resetData = true;
  1343. dataObj[key] = v;
  1344. }
  1345. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  1346. },
  1347. createErrorNode: function(text){
  1348. var node;
  1349. if( this.processor.css.errorContentNode ){
  1350. node = new Element("div",{
  1351. "styles" : this.processor.css.errorContentNode,
  1352. "text": text
  1353. });
  1354. if( this.processor.css.errorCloseNode ){
  1355. var closeNode = new Element("div",{
  1356. "styles" : this.processor.css.errorCloseNode ,
  1357. "events": {
  1358. "click" : function(){
  1359. this.destroy();
  1360. }.bind(node)
  1361. }
  1362. }).inject(node);
  1363. }
  1364. }else {
  1365. node = new Element("div");
  1366. var iconNode = new Element("div", {
  1367. "styles": {
  1368. "width": "20px",
  1369. "height": "20px",
  1370. "float": "left",
  1371. "background": "url(" + "/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1372. }
  1373. }).inject(node);
  1374. var textNode = new Element("div", {
  1375. "styles": {
  1376. "height": "20px",
  1377. "line-height": "20px",
  1378. "margin-left": "20px",
  1379. "color": "red",
  1380. "word-break": "keep-all"
  1381. },
  1382. "text": text
  1383. }).inject(node);
  1384. }
  1385. return node;
  1386. },
  1387. notValidationMode: function(text){
  1388. if (!this.isNotValidationMode){
  1389. //this.isNotValidationMode = true;
  1390. //this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1391. //this.node.setStyle("border-color", "red");
  1392. this.errNode = this.createErrorNode(text);
  1393. if( this.errContainer ){
  1394. this.errContainer.empty();
  1395. this.errNode.inject(this.errContainer);
  1396. }else{
  1397. this.errNode.inject(this.container, "after");
  1398. }
  1399. //this.showNotValidationMode(this.node);
  1400. //if (!this.node.isIntoView()) this.node.scrollIntoView();
  1401. }
  1402. },
  1403. validation: function(){
  1404. var data = this.getData();
  1405. this.setData( data );
  1406. var flag=true;
  1407. if( this.json.validationCount && typeOf( this.json.validationCount.toInt() ) === "number" ){
  1408. if( data.length < this.json.validationCount.toInt() ){
  1409. //if( this.json.validationCount.toInt() === 1 ){
  1410. // flag = "请选择"
  1411. //}else{
  1412. // flag = "请至少选择"+this.json.validationCount+"项"
  1413. //}
  1414. flag = "请至少选择"+this.json.validationCount+"项"
  1415. }
  1416. }
  1417. if( flag === true ){
  1418. if ( this.json.validation && this.json.validation.code){
  1419. flag = this.form.Macro.exec(this.json.validation.code, this);
  1420. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1421. }
  1422. }
  1423. if (flag.toString()!="true"){
  1424. this.notValidationMode(flag);
  1425. return false;
  1426. }else if(this.errNode){
  1427. this.errNode.destroy()
  1428. }
  1429. return true;
  1430. }
  1431. });
  1432. MWF.xApplication.process.Work.Processor.EmpowerChecker = new Class({
  1433. Extends : MWF.APPOrg.EmpowerChecker,
  1434. initialize: function (form, json, processor) {
  1435. this.form = form;
  1436. this.json = json;
  1437. this.processor = processor;
  1438. this.css = this.processor.css;
  1439. this.checkedAllItems = true;
  1440. },
  1441. hasEmpowerIdentity: function( data ){
  1442. var flag = false;
  1443. if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
  1444. var array = [];
  1445. data.each(function (d) {
  1446. if (d.distinguishedName) {
  1447. var flag = d.distinguishedName.substr(d.distinguishedName.length - 1, 1).toLowerCase();
  1448. if (flag === "i")array.push(d.distinguishedName)
  1449. }
  1450. }.bind(this));
  1451. if (array.length > 0) {
  1452. o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
  1453. "application": (this.form.businessData.work || this.form.businessData.workCompleted).application,
  1454. "process": (this.form.businessData.work || this.form.businessData.workCompleted).process,
  1455. "identityList": array
  1456. }, function (json) {
  1457. var arr = [];
  1458. json.data.each(function (d) {
  1459. if (d.fromIdentity !== d.toIdentity)
  1460. arr.push(d);
  1461. });
  1462. if (arr.length > 0) {
  1463. flag = true;
  1464. }
  1465. }.bind(this), null, false)
  1466. }
  1467. }
  1468. return flag;
  1469. },
  1470. openSelectEmpowerDlg : function( data, orgData, callback, container ){
  1471. var node = new Element("div", {"styles": this.css.empowerAreaNode});
  1472. //var html = "<div style=\"line-height: 30px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
  1473. var html = "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  1474. node.set("html", html);
  1475. var itemNode = node.getLast();
  1476. this.getEmpowerItems(itemNode, data);
  1477. node.inject( container || this.container );
  1478. if( this.selectAllNode ){
  1479. var selectNode = this.createSelectAllEmpowerNode();
  1480. selectNode.inject( this.selectAllNode );
  1481. if( this.checkedAllItems ){
  1482. selectNode.store("isSelected", true);
  1483. selectNode.setStyles( this.css.empowerSelectAllItemNode_selected );
  1484. }
  1485. }
  1486. },
  1487. getSelectedData : function( callback ){
  1488. var json = {};
  1489. this.empowerSelectNodes.each(function(node){
  1490. if( node.retrieve("isSelected") ){
  1491. var d = node.retrieve("data");
  1492. json[ d.fromIdentity ] = d;
  1493. }
  1494. }.bind(this));
  1495. if( callback )callback( json );
  1496. }
  1497. });
  1498. MWF.xApplication.process.Work.Processor.UnitOptions = new Class({
  1499. Extends : MWF.APPOrg.UnitOptions
  1500. });
  1501. MWF.xApplication.process.Work.Processor.IdentityOptions = new Class({
  1502. Extends : MWF.APPOrg.IdentityOptions
  1503. });