Form.js 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669
  1. MWF.require(["MWF.widget.Common", "MWF.widget.Identity"], null, false);
  2. MWF.xApplication.process = MWF.xApplication.process || {};
  3. MWF.xApplication.process.Xform = MWF.xApplication.process.Xform || {};
  4. MWF.xDesktop.requireApp("process.Xform", "Package", null, false);
  5. MWF.xApplication.process.Xform.Form = MWF.APPForm = new Class({
  6. Implements: [Options, Events],
  7. Extends: MWF.widget.Common,
  8. options: {
  9. "style": "default",
  10. "readonly": false,
  11. "cssPath": "",
  12. "macro": "FormContext",
  13. "parameters": null,
  14. "moduleEvents": ["queryLoad",
  15. "beforeLoad",
  16. "postLoad",
  17. "afterLoad",
  18. "beforeSave",
  19. "afterSave",
  20. "beforeClose",
  21. "beforeProcess",
  22. "beforeProcessWork",
  23. "afterProcess",
  24. "beforeReset",
  25. "afterReset",
  26. "beforeRetract",
  27. "afterRetract",
  28. "beforeReroute",
  29. "afterReroute",
  30. "beforeDelete",
  31. "afterDelete",
  32. "beforeModulesLoad",
  33. "resize",
  34. "afterModulesLoad"]
  35. },
  36. initialize: function(node, data, options){
  37. this.setOptions(options);
  38. this.container = $(node);
  39. this.container.setStyle("-webkit-user-select", "text");
  40. this.data = data;
  41. this.json = data.json;
  42. this.html = data.html;
  43. this.path = "/x_component_process_Xform/$Form/";
  44. this.cssPath = this.options.cssPath || "/x_component_process_Xform/$Form/"+this.options.style+"/css.wcss";
  45. this._loadCss();
  46. this.modules = [];
  47. this.all = {};
  48. this.forms = {};
  49. //if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  50. },
  51. parseCSS: function(css){
  52. var rex = /(url\(.*\))/g;
  53. var match;
  54. while ((match = rex.exec(css)) !== null) {
  55. var pic = match[0];
  56. var len = pic.length;
  57. var s = pic.substring(pic.length-2, pic.length-1);
  58. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  59. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  60. pic = pic.substring(n0, pic.length-n1);
  61. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  62. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  63. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  64. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  65. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  66. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  67. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  68. }
  69. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  70. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  71. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  72. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  73. }
  74. }
  75. pic = "url('"+pic+"')";
  76. var len2 = pic.length;
  77. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  78. rex.lastIndex = rex.lastIndex + (len2-len);
  79. }
  80. return css;
  81. },
  82. loadCss: function(){
  83. cssText = this.json.css.code;
  84. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  85. var styleNode = $("style"+this.json.id);
  86. if (styleNode) styleNode.destroy();
  87. if (cssText){
  88. cssText = this.parseCSS(cssText);
  89. var rex = new RegExp("(.+)(?=\\{)", "g");
  90. var match;
  91. var id = this.json.id.replace(/\-/g, "");
  92. var prefix = ".css" + id + " ";
  93. while ((match = rex.exec(cssText)) !== null) {
  94. var rulesStr = match[0];
  95. if (rulesStr.indexOf(",")!=-1){
  96. var rules = rulesStr.split(/\s*,\s*/g);
  97. rules = rules.map(function(r){
  98. return prefix + r;
  99. });
  100. var rule = rules.join(", ");
  101. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  102. rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  103. }else{
  104. var rule = prefix + match[0];
  105. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  106. rex.lastIndex = rex.lastIndex + prefix.length;
  107. }
  108. }
  109. var styleNode = document.createElement("style");
  110. styleNode.setAttribute("type", "text/css");
  111. styleNode.id="style"+this.json.id;
  112. styleNode.inject(this.container, "before");
  113. if(styleNode.styleSheet){
  114. var setFunc = function(){
  115. styleNode.styleSheet.cssText = cssText;
  116. };
  117. if(styleNode.styleSheet.disabled){
  118. setTimeout(setFunc, 10);
  119. }else{
  120. setFunc();
  121. }
  122. }else{
  123. var cssTextNode = document.createTextNode(cssText);
  124. styleNode.appendChild(cssTextNode);
  125. }
  126. return "css" + id;
  127. }
  128. return "";
  129. },
  130. load: function(callback){
  131. this.loadExtendStyle( function(){
  132. if (this.app){
  133. if (this.app.formNode) this.app.formNode.setStyles(this.json.styles);
  134. if (this.app.addEvent){
  135. this.app.addEvent("resize", function(){
  136. this.fireEvent("resize");
  137. }.bind(this));
  138. this.app.addEvent("queryClose", function(){
  139. this.beforeCloseWork();
  140. }.bind(this))
  141. }
  142. }
  143. if (!this.businessData.control.allowSave) this.setOptions({"readonly": true});
  144. var cssClass = "";
  145. if (this.json.css && this.json.css.code) cssClass = this.loadCss();
  146. this.loadMacro(function(){
  147. this.container.set("html", this.html);
  148. this.node = this.container.getFirst();
  149. if (cssClass) this.node.addClass(cssClass);
  150. this._loadEvents();
  151. if (this.fireEvent("queryLoad")){
  152. if (this.app) if (this.app.fireEvent) this.app.fireEvent("queryLoad");
  153. MWF.xDesktop.requireApp("process.Xform", "lp."+MWF.language, null, false);
  154. this._loadBusinessData();
  155. this.fireEvent("beforeLoad");
  156. if (this.app) if (this.app.fireEvent) this.app.fireEvent("beforeLoad");
  157. this.loadContent(callback);
  158. }
  159. }.bind(this));
  160. }.bind(this))
  161. },
  162. loadExtendStyle : function(callback ){
  163. if( !this.json.styleConfig || !this.json.styleConfig.extendFile ){
  164. if (callback) callback();
  165. return;
  166. }
  167. var stylesUrl = "/x_component_process_FormDesigner/Module/Form/skin/"+this.json.styleConfig.extendFile;
  168. MWF.getJSON(stylesUrl,{
  169. "onSuccess": function(responseJSON){
  170. if( responseJSON && responseJSON.form ){
  171. this.json = Object.merge( this.json, responseJSON.form );
  172. }
  173. if (callback) callback();
  174. }.bind(this),
  175. "onRequestFailure": function(){
  176. if (callback) callback();
  177. }.bind(this),
  178. "onError": function(){
  179. if (callback) callback();
  180. }.bind(this)
  181. }
  182. );
  183. },
  184. loadMacro: function(callback){
  185. //if (!MWF.Macro[this.options.macro || "FormContext"]){
  186. MWF.require("MWF.xScript.Macro", function(){
  187. this.Macro = new MWF.Macro[this.options.macro || "FormContext"](this);
  188. if (callback) callback();
  189. }.bind(this));
  190. // }else{
  191. // this.Macro = new MWF.Macro[this.options.macro || "FormContext"](this);
  192. // if (callback) callback();
  193. // }
  194. },
  195. loadContent: function(callback){
  196. this.subformCount = 0;
  197. this.subformLoadedCount = 0;
  198. this.subformLoaded = [ this.json.id ];
  199. this.subpageCount = 0;
  200. this.subpageLoadedCount = 0;
  201. this.subpageLoaded = [];
  202. this.widgetCount = 0;
  203. this.widgetLoadedCount = 0;
  204. this.widgetLoaded = [];
  205. this._loadHtml();
  206. this._loadForm();
  207. this.fireEvent("beforeModulesLoad");
  208. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeModulesLoad");
  209. this._loadModules(this.node);
  210. if (this.json.mode === "Mobile"){
  211. var node = document.body.getElement(".o2_form_mobile_actions");
  212. //if (node)
  213. this._loadMobileActions(node, callback);
  214. }else{
  215. if (callback) callback();
  216. }
  217. this.fireEvent("postLoad");
  218. if (this.app && this.app.fireEvent)this.app.fireEvent("postLoad");
  219. this.checkSubformLoaded( true );
  220. },
  221. checkSubformLoaded : function( isAllSubformLoaded ){
  222. if( isAllSubformLoaded ){
  223. this.isAllSubformLoaded = true;
  224. }
  225. if( !this.isAllSubformLoaded )return;
  226. //console.log( "checkSubformLoaded this.subformCount="+ this.subformCount + " this.subformLoadedCount="+this.subformLoadedCount );
  227. if( (!this.subformCount || this.subformCount === this.subformLoadedCount) &&
  228. (!this.subpageCount || this.subpageCount === this.subpageLoadedCount) &&
  229. (!this.widgetCount || this.widgetCount === this.widgetLoadedCount)
  230. ){
  231. this.fireEvent("afterModulesLoad");
  232. if (this.app && this.app.fireEvent)this.app.fireEvent("afterModulesLoad");
  233. this.fireEvent("afterLoad");
  234. if (this.app && this.app.fireEvent)this.app.fireEvent("afterLoad");
  235. this.isLoaded = true;
  236. }
  237. },
  238. _loadMobileDefaultTools: function(callback){
  239. if (this.json.defaultTools){
  240. if (callback) callback();
  241. }else{
  242. this.json.defaultTools = o2.JSON.get("/x_component_process_FormDesigner/Module/Form/toolbars.json", function(json){
  243. this.json.defaultTools = json;
  244. if (callback) callback();
  245. }.bind(this));
  246. }
  247. },
  248. _loadMobileActions: function(node, callback){
  249. var tools = [];
  250. this._loadMobileDefaultTools(function(){
  251. if (this.json.defaultTools){
  252. this.json.defaultTools.each(function(tool){
  253. var flag = this._checkDefaultMobileActionItem(tool, this.options.readonly);
  254. if (flag) tools.push(tool);
  255. }.bind(this));
  256. }
  257. if (this.json.tools){
  258. this.json.tools.each(function(tool){
  259. var flag = this._checkCustomMobileActionItem(tool, this.options.readonly);
  260. if (flag) tools.push(tool);
  261. }.bind(this));
  262. }
  263. this.mobileTools = tools;
  264. if (tools.length) if (node) this._createMobileActions(node, tools);
  265. if (callback) callback();
  266. }.bind(this));
  267. },
  268. _createMobileActions:function(node, tools){
  269. node.show();
  270. var count = tools.length;
  271. if (count<=2){
  272. this.css.html5ActionButton.width = "100%";
  273. if (count==2) this.css.html5ActionButton.width = "49%";
  274. tools.each(function(tool){
  275. var action = new Element("div", {"styles": this.css.html5ActionButton, "text": tool.text}).inject(node);
  276. action.store("tool", tool);
  277. action.addEvent("click", function(e){
  278. var t = e.target.retrieve("tool");
  279. e.setDisable = function(){}
  280. if (t.actionScript){
  281. this._runCustomAction(t.actionScript);
  282. }else{
  283. if (this[t.action]) this[t.action](e);
  284. }
  285. }.bind(this));
  286. this._setMobileBottonStyle(action);
  287. }.bind(this));
  288. if (count==2) new Element("div", {"styles": this.css.html5ActionButtonSplit}).inject(node.getLast(), "before");
  289. }else{
  290. this.css.html5ActionButton.width = "38%"
  291. for (var i=0; i<2; i++){
  292. tool = tools[i];
  293. var action = new Element("div", {"styles": this.css.html5ActionButton, "text": tool.text}).inject(node);
  294. action.store("tool", tool);
  295. action.addEvent("click", function(e){
  296. var t = e.target.retrieve("tool");
  297. e.setDisable = function(){}
  298. if (t.actionScript){
  299. this._runCustomAction(t.actionScript);
  300. }else{
  301. if (this[t.action]) this[t.action](e);
  302. }
  303. }.bind(this));
  304. this._setMobileBottonStyle(action);
  305. }
  306. new Element("div", {"styles": this.css.html5ActionButtonSplit}).inject(node.getLast(), "before");
  307. new Element("div", {"styles": this.css.html5ActionButtonSplit}).inject(node);
  308. this.css.html5ActionButton.width = "23%"
  309. var action = new Element("div", {"styles": this.css.html5ActionButton, "text": "…"}).inject(node);
  310. action.addEvent("click", function(e){
  311. this._loadMoreMobileActions(tools, 2, node);
  312. }.bind(this));
  313. this._setMobileBottonStyle(action);
  314. }
  315. },
  316. _loadMoreMobileActions: function(tools, n, node){
  317. document.body.mask({
  318. "style": {
  319. "background-color": "#cccccc",
  320. "opacity": 0.6
  321. },
  322. "hideOnClick": true,
  323. "onHide": function(){
  324. this.actionMoreArea.setStyle("display", "none");
  325. }.bind(this)
  326. });
  327. if (this.actionMoreArea){
  328. this.actionMoreArea.setStyle("display", "block");
  329. }else{
  330. var size = document.body.getSize();
  331. this.actionMoreArea = new Element("div", {"styles": this.css.html5ActionOtherArea}).inject(document.body);
  332. var pl = this.actionMoreArea.getStyle("padding-left").toInt();
  333. var pr = this.actionMoreArea.getStyle("padding-right").toInt();
  334. var w = size.x-pl-pr;
  335. this.actionMoreArea.setStyle("width", ""+w+"px");
  336. for (var i=n; i<tools.length; i++){
  337. tool = tools[i];
  338. var action = new Element("div", {"styles": this.css.html5ActionOtherButton, "text": tool.text}).inject(this.actionMoreArea);
  339. action.store("tool", tool);
  340. action.addEvent("click", function(e){
  341. var t = e.target.retrieve("tool");
  342. e.setDisable = function(){}
  343. if (t.actionScript){
  344. this._runCustomAction(t.actionScript);
  345. }else{
  346. if (this[t.action]) this[t.action](e);
  347. }
  348. }.bind(this));
  349. this._setMobileBottonStyle(action);
  350. }
  351. }
  352. // actionArea.position({
  353. // relativeTo: node,
  354. // position: 'topCenter',
  355. // edge: 'bottomCenter'
  356. // });
  357. },
  358. _setMobileBottonStyle:function(action){
  359. var _self = this;
  360. action.addEvents({
  361. "mouseover": function(e){ this.setStyles(_self.css.html5ActionButton_over)},
  362. "mouseout": function(e){this.setStyles(_self.css.html5ActionButton_up)},
  363. "mousedown": function(e){this.setStyles(_self.css.html5ActionButton_over)},
  364. "mouseup": function(e){this.setStyles(_self.css.html5ActionButton_up)},
  365. "touchstart": function(e){this.setStyles(_self.css.html5ActionButton_over)},
  366. "touchcancel": function(e){this.setStyles(_self.css.html5ActionButton_up)},
  367. "touchend": function(e){this.setStyles(_self.css.html5ActionButton_up)},
  368. "touchmove": function(e){this.setStyles(_self.css.html5ActionButton_over)}
  369. });
  370. },
  371. _runCustomAction: function(actionScript){
  372. //var script = bt.node.retrieve("script");
  373. this.Macro.exec(actionScript, this);
  374. },
  375. _checkCustomMobileActionItem: function(tool,readonly){
  376. var flag = true;
  377. if (readonly){
  378. flag = tool.readShow;
  379. }else{
  380. flag = tool.editShow;
  381. }
  382. if (flag){
  383. flag = true;
  384. if (tool.control){
  385. flag = this.form.businessData.control[tool.control]
  386. }
  387. if (tool.condition){
  388. var hideFlag = this.Macro.exec(tool.condition, this);
  389. flag = !hideFlag;
  390. }
  391. }
  392. return flag;
  393. },
  394. _checkDefaultMobileActionItem: function(tool, readonly, noCondition){
  395. var flag = true;
  396. if (tool.control){
  397. flag = this.businessData.control[tool.control]
  398. }
  399. if (!noCondition) if (tool.condition){
  400. var hideFlag = this.Macro.exec(tool.condition, this);
  401. flag = flag && (!hideFlag);
  402. }
  403. if (tool.id == "action_processWork"){
  404. if (!this.businessData.task){
  405. flag = false;
  406. }
  407. }
  408. if (tool.id == "action_rollback") tool.read = true;
  409. if (readonly) if (!tool.read) flag = false;
  410. return flag;
  411. },
  412. _loadBusinessData: function(){
  413. if (!this.businessData){
  414. this.businessData = {};
  415. // this.businessData = {
  416. // "data": {
  417. // "select": "222",
  418. // "radio": "bbb",
  419. // "checkbox": ["check1", "check3"],
  420. // "orderData": [
  421. // {
  422. // "orderName": {"namefield": "电脑"},
  423. // "orderCount": {"countField": "3"},
  424. // "priceCount": {"priceField": "9000"}
  425. // },
  426. // {
  427. // "orderName": {"namefield": "路由器"},
  428. // "orderCount": {"countField": "2"},
  429. // "priceCount": {"priceField": "1000"}
  430. // },
  431. // {
  432. // "orderName": {"namefield": "网线"},
  433. // "orderCount": {"countField": "10"},
  434. // "priceCount": {"priceField": "200"}
  435. // }
  436. // ]
  437. //
  438. // }
  439. // };
  440. }
  441. },
  442. _loadHtml: function(){
  443. // this.container.set("html", this.html);
  444. // this.node = this.container.getFirst();
  445. //this.node.setStyle("overflow", "hidden");
  446. this.node.addEvent("selectstart", function(e){
  447. var select = "text";
  448. if (e.target.getStyle("-webkit-user-select")){
  449. select = e.target.getStyle("-webkit-user-select").toString().toLowerCase();
  450. }
  451. if (select!=="text" && select!=="auto") e.preventDefault();
  452. });
  453. },
  454. _loadForm: function(){
  455. this._loadStyles();
  456. this._loadCssLinks();
  457. this._loadScriptSrc();
  458. this._loadJsheader();
  459. //this._loadEvents();
  460. },
  461. _loadStyles: function(){
  462. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  463. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  464. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  465. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  466. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  467. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  468. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  469. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  470. }
  471. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  472. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  473. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  474. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  475. }
  476. }
  477. this.node.setStyle(key, value);
  478. }.bind(this));
  479. //this.node.setStyles(this.json.styles);
  480. },
  481. _loadCssLinks: function(){
  482. var urls = this.json.cssLinks;
  483. urls.each(function(url){
  484. new Element("link", {
  485. "rel": "stylesheet",
  486. "type": "text/css",
  487. "href": url
  488. }).inject($(document.head));
  489. });
  490. },
  491. _loadScriptSrc: function(){
  492. var urls = this.json.scriptSrc;
  493. urls.each(function(url){
  494. new Element("script", {
  495. "src": url
  496. }).inject($(document.head));
  497. });
  498. },
  499. _loadJsheader: function(){
  500. var code = this.json.jsheader.code;
  501. if (code) Browser.exec(code);
  502. },
  503. _loadEvents: function(){
  504. Object.each(this.json.events, function(e, key){
  505. if (e.code){
  506. if (this.options.moduleEvents.indexOf(key)!==-1){
  507. this.addEvent(key, function(event){
  508. return this.Macro.fire(e.code, this, event);
  509. }.bind(this));
  510. }else{
  511. if (key==="load"){
  512. this.addEvent("postLoad", function(){
  513. return this.Macro.fire(e.code, this);
  514. }.bind(this));
  515. }else if (key==="submit"){
  516. this.addEvent("beforeProcess", function(){
  517. return this.Macro.fire(e.code, this);
  518. }.bind(this));
  519. }else{
  520. this.node.addEvent(key, function(event){
  521. return this.Macro.fire(e.code, this, event);
  522. }.bind(this));
  523. }
  524. }
  525. }
  526. }.bind(this));
  527. },
  528. addModuleEvent: function(key, fun){
  529. if (this.options.moduleEvents.indexOf(key)!==-1){
  530. this.addEvent(key, function(event){
  531. return (fun) ? fun(this, event) : null;
  532. }.bind(this));
  533. }else{
  534. if (key==="load"){
  535. this.addEvent("postLoad", function(event){
  536. return (fun) ? fun(this, event) : null;
  537. }.bind(this));
  538. }else if (key==="submit"){
  539. this.addEvent("beforeProcess", function(event){
  540. return (fun) ? fun(this, event) : null;
  541. }.bind(this));
  542. }else{
  543. this.node.addEvent(key, function(event){
  544. return (fun) ? fun(this, event) : null;
  545. }.bind(this));
  546. }
  547. }
  548. },
  549. _getDomjson: function(dom){
  550. var mwfType = dom.get("MWFtype") || dom.get("mwftype");
  551. switch (mwfType) {
  552. case "form":
  553. return this.json;
  554. case "":
  555. return null;
  556. default:
  557. var id = dom.get("id");
  558. if (!id) id = dom.get("MWFId");
  559. if (id){
  560. return this.json.moduleList[id];
  561. }else{
  562. return null;
  563. }
  564. }
  565. },
  566. _getModuleNodes: function(dom){
  567. var moduleNodes = [];
  568. var subDom = dom.getFirst();
  569. while (subDom){
  570. var mwftype = subDom.get("MWFtype") || subDom.get("mwftype");
  571. if (mwftype){
  572. var type = mwftype;
  573. if (type.indexOf("$")===-1){
  574. moduleNodes.push(subDom);
  575. }
  576. // && mwftype !== "tab$Content"
  577. if (mwftype !== "datagrid" && mwftype !== "subSource" && mwftype !== "tab$Content"){
  578. moduleNodes = moduleNodes.concat(this._getModuleNodes(subDom));
  579. }
  580. }else{
  581. moduleNodes = moduleNodes.concat(this._getModuleNodes(subDom));
  582. }
  583. subDom = subDom.getNext();
  584. }
  585. return moduleNodes;
  586. },
  587. _loadModules: function(dom){
  588. //var subDom = this.node.getFirst();
  589. //while (subDom){
  590. // if (subDom.get("MWFtype")){
  591. // var json = this._getDomjson(subDom);
  592. // var module = this._loadModule(json, subDom);
  593. // this.modules.push(module);
  594. // }
  595. // subDom = subDom.getNext();
  596. //}
  597. var moduleNodes = this._getModuleNodes(dom);
  598. //alert(moduleNodes.length);
  599. moduleNodes.each(function(node){
  600. var json = this._getDomjson(node);
  601. //if( json.type === "Subform" || json.moduleName === "subform" )this.subformCount++;
  602. //if( json.type === "Subpage" || json.moduleName === "subpage" )this.subpageCount++;
  603. var module = this._loadModule(json, node);
  604. this.modules.push(module);
  605. }.bind(this));
  606. },
  607. _loadModule: function(json, node, beforeLoad){
  608. //console.log( json.id );
  609. if( json.type === "Subform" || json.moduleName === "subform" )this.subformCount++;
  610. //if( json.type === "Subform" || json.moduleName === "subform" ){
  611. // console.log( "add subformcount , this.subformCount = " + this.subformCount );
  612. //}
  613. if( json.type === "Subpage" || json.moduleName === "subpage" )this.subpageCount++;
  614. if( json.type === "Widget" || json.moduleName === "widget" )this.widgetCount++;
  615. if (!MWF["APP"+json.type]){
  616. MWF.xDesktop.requireApp("process.Xform", json.type, null, false);
  617. }
  618. var module = new MWF["APP"+json.type](node, json, this);
  619. if (beforeLoad) beforeLoad.apply(module);
  620. if (!this.all[json.id]) this.all[json.id] = module;
  621. if (module.field){
  622. if (!this.forms[json.id]) this.forms[json.id] = module;
  623. }
  624. module.readonly = this.options.readonly;
  625. module.load();
  626. return module;
  627. },
  628. saveOpinion: function(module){
  629. var op = module._getBusinessSectionDataByPerson();
  630. MWF.UD.getDataJson("userOpinion", function(json){
  631. if (!json) json = [];
  632. var idx = json.indexOf(op);
  633. if (idx==-1){
  634. if (json.length>=50) json.shift();
  635. }else{
  636. json.splice(idx, 1);
  637. }
  638. json.push(op);
  639. MWF.UD.putData("userOpinion", json);
  640. }.bind(this), false);
  641. },
  642. getData: function(issubmit){
  643. var data= Object.clone(this.businessData.data);
  644. Object.each(this.forms, function(module, id){
  645. if (module.json.type==="Opinion"){
  646. debugger;
  647. if (issubmit){
  648. this.saveOpinion(module);
  649. delete data[id];
  650. }else{
  651. var v = module.getData();
  652. data[id] = this.getSectionDataByPerson(v, data[id]);
  653. }
  654. }else{
  655. if (module.json.section==="yes"){
  656. data[id] = this.getSectionData(module, data[id]);
  657. }else{
  658. data[id] = module.getData();
  659. }
  660. }
  661. }.bind(this));
  662. this.businessData.data = data;
  663. this.Macro.environment.setData(this.businessData.data);
  664. return data;
  665. },
  666. getSectionData: function(module, obj){
  667. var v = module.getData();
  668. switch (module.json.sectionBy){
  669. case "person":
  670. return this.getSectionDataByPerson(v, obj);
  671. break;
  672. case "unit":
  673. return this.getSectionDataByUnit(v, obj);
  674. break;
  675. case "activity":
  676. return this.getSectionDataByPActivity(v, obj);
  677. break;
  678. case "script":
  679. return this.getSectionDataByScript(module.json.sectionByScript.code, v, obj);
  680. break;
  681. default:
  682. return v;
  683. }
  684. },
  685. getSectionDataByPerson: function(v, obj) {
  686. var key = layout.desktop.session.user.id;
  687. if (!obj || (typeOf(obj)!=="object")) obj={};
  688. obj[key] = v;
  689. return obj;
  690. },
  691. getSectionDataByUnit: function(v, obj) {
  692. var key = (this.businessData.task) ? this.businessData.task.unit : "";
  693. if (!obj || (typeOf(obj)!=="object")) obj={};
  694. if (key) obj[key] = v;
  695. return obj;
  696. },
  697. getSectionDataByPActivity: function(v, obj) {
  698. var key = (this.businessData.work) ? this.businessData.work.activity : "";
  699. if (!obj || (typeOf(obj)!=="object")) obj={};
  700. if (key) obj[key] = v;
  701. return obj;
  702. },
  703. getSectionDataByScript: function(code, v, obj) {
  704. var key = this.Macro.exec(code, this);
  705. if (!obj || (typeOf(obj)!=="object")) obj={};
  706. if (key) obj[key] = v;
  707. return obj;
  708. },
  709. saveWork: function(callback){
  710. if (this.businessData.control["allowSave"]){
  711. this.fireEvent("beforeSave");
  712. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeSave");
  713. this.saveFormData(function(json){
  714. if (this.app) this.app.notice(MWF.xApplication.process.Xform.LP.dataSaved, "success");
  715. if (callback) callback();
  716. this.fireEvent("afterSave");
  717. if (this.app && this.app.fireEvent) this.app.fireEvent("afterSave");
  718. }.bind(this));
  719. }else{
  720. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "Permission Denied");
  721. //if (failure) failure(null, "Permission Denied", "");
  722. }
  723. },
  724. saveFormData: function(callback, failure, history ,data, issubmit){
  725. if (this.officeList){
  726. this.officeList.each(function(module){
  727. module.save(history);
  728. });
  729. }
  730. this.workAction.saveData(callback, failure, this.businessData.work.id, data || this.getData(issubmit));
  731. },
  732. beforeCloseWork: function(){
  733. this.fireEvent("beforeClose");
  734. if (this.app && this.app.fireEvent){
  735. this.app.fireEvent("beforeClose");
  736. // this.fireEvent("afterClose");
  737. }
  738. if (!this.options.readonly){
  739. if (this.businessData.work) this.workAction.checkDraft(this.businessData.work.id, function(){
  740. if (layout.desktop.apps){
  741. if (layout.desktop.apps["TaskCenter"]){
  742. layout.desktop.apps["TaskCenter"].content.unmask();
  743. layout.desktop.apps["TaskCenter"].refreshAll();
  744. }
  745. }
  746. }.bind(this), null, false);
  747. }else{
  748. this.app.refreshTaskCenter();
  749. }
  750. },
  751. closeWork: function(){
  752. // this.fireEvent("beforeClose");
  753. // if (this.app && this.app.fireEvent){
  754. // this.app.fireEvent("beforeClose");
  755. // // this.fireEvent("afterClose");
  756. // }
  757. // debugger;
  758. // if (!this.options.readonly)
  759. // if (this.businessData.work) this.workAction.checkDraft(this.businessData.work.id);
  760. this.app.close();
  761. },
  762. getMessageContent: function(data){
  763. var content = "";
  764. if (data.length){
  765. data.each(function(work){
  766. var users = [];
  767. work.taskList.each(function(task){
  768. users.push(MWF.name.cn(task.person)+"("+MWF.name.cn(task.unit)+")");
  769. }.bind(this));
  770. content += "<div><b>"+MWF.xApplication.process.Xform.LP.nextActivity+"<font style=\"color: #ea621f\">"+work.activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  771. }.bind(this));
  772. }else{
  773. content += MWF.xApplication.process.Xform.LP.workCompleted;
  774. }
  775. return "<div>"+MWF.xApplication.process.Xform.LP.taskProcessedMessage+"“"+this.businessData.work.title+"”</div>"+content;
  776. },
  777. addMessage: function(data){
  778. // var content = "";
  779. // if (data.length){
  780. // data.each(function(work){
  781. // var users = [];
  782. // work.taskList.each(function(task){
  783. // users.push(MWF.name.cn(task.person)+"("+MWF.name.cn(task.unit)+")");
  784. // }.bind(this));
  785. //
  786. // content += "<div><b>"+MWF.xApplication.process.Xform.LP.nextActivity+"<font style=\"color: #ea621f\">"+work.fromActivityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  787. // }.bind(this));
  788. // }else{
  789. // content += MWF.xApplication.process.Xform.LP.workCompleted;
  790. // }
  791. //data.workList.each(function(list){
  792. // content += "<div><b>"+MWF.xApplication.process.Xform.LP.nextActivity+"<font style=\"color: #ea621f\">"+list.activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+list.personList.join(", ")+"</font></b></div>"
  793. //}.bind(this));
  794. var msg = {
  795. "subject": MWF.xApplication.process.Xform.LP.taskProcessed,
  796. "content": this.getMessageContent(data)
  797. };
  798. layout.desktop.message.addTooltip(msg);
  799. return layout.desktop.message.addMessage(msg);
  800. },
  801. formValidation: function(routeName, opinion, medias){
  802. if (this.options.readonly) return true;
  803. this.Macro.environment.form.currentRouteName = routeName;
  804. this.Macro.environment.form.opinion = opinion;
  805. this.Macro.environment.form.medias = medias;
  806. var flag = true;
  807. //flag = this.validation();
  808. Object.each(this.forms, function(field, key){
  809. field.validationMode();
  810. if (!field.validation(routeName, opinion, medias)) flag = false;
  811. }.bind(this));
  812. return flag;
  813. },
  814. validation: function(routeName, opinion, processor, medias){
  815. this.Macro.environment.form.currentRouteName = routeName;
  816. this.Macro.environment.form.opinion = opinion;
  817. this.Macro.environment.form.medias = medias;
  818. var routeFlag = this.validationRoute(processor);
  819. var opinionFlag = this.validationOpinion(processor);
  820. return routeFlag && opinionFlag;
  821. },
  822. validationRoute: function(processor){
  823. if (!this.json.validationRoute) return true;
  824. if (!this.json.validationRoute.code) return true;
  825. var flag = this.Macro.exec(this.json.validationRoute.code, this);
  826. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  827. if (flag.toString()!="true"){
  828. this.notValidationRouteMode(flag, processor);
  829. return false;
  830. }
  831. return true;
  832. },
  833. validationOpinion: function(processor){
  834. if (!this.json.validationOpinion) return true;
  835. if (!this.json.validationOpinion.code) return true;
  836. var flag = this.Macro.exec(this.json.validationOpinion.code, this);
  837. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  838. if (flag.toString()!="true"){
  839. this.notValidationOpinionMode(flag, processor);
  840. return false;
  841. }
  842. return true;
  843. },
  844. formCustomValidation: function(){
  845. if (!this.json.validationFormCustom) return true;
  846. if (!this.json.validationFormCustom.code) return true;
  847. var flag = this.Macro.exec(this.json.validationFormCustom.code, this);
  848. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  849. if (flag.toString()!="true"){
  850. this.notValidationOpinionMode(flag);
  851. return false;
  852. }
  853. return true;
  854. },
  855. notValidationRouteMode: function(flag, processor){
  856. if(processor)processor.routeSelectorArea.setStyle("background-color", "#ffe9e9");
  857. MWF.xDesktop.notice(
  858. "error",
  859. {"x": "center", "y": "top"},
  860. flag,
  861. (processor) ? processor.routeSelectorArea : this.app.content,
  862. null, //{"x": 0, "y": 30}
  863. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  864. );
  865. //new mBox.Notice({
  866. // type: "error",
  867. // position: {"x": "center", "y": "top"},
  868. // move: false,
  869. // target: (processor) ? processor.routeSelectorArea : this.app.content,
  870. // delayClose: 6000,
  871. // content: flag
  872. //});
  873. },
  874. notValidationOpinionMode: function(flag, processor){
  875. if (processor) processor.inputTextarea.setStyle("background-color", "#ffe9e9");
  876. MWF.xDesktop.notice(
  877. "error",
  878. (processor) ? {"x": "center", "y": "top"} : {"x": "right", "y": "top"},
  879. flag,
  880. (processor) ? processor.inputTextarea : this.app.content,
  881. null, //{"x": 0, "y": 30}
  882. { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
  883. );
  884. //new mBox.Notice({
  885. // type: "error",
  886. // position: (processor) ? {"x": "center", "y": "top"} : {"x": "right", "y": "top"},
  887. // move: false,
  888. // target: (processor) ? processor.inputTextarea : this.app.content,
  889. // delayClose: 6000,
  890. // content: flag
  891. //});
  892. },
  893. //fireRtEvent: function(type, args, delay){
  894. // type = removeOn(type);
  895. // var events = this.$events[type];
  896. // if (!events) return this;
  897. // if (!events.length) return this;
  898. // var event = events[events.length-1];
  899. // args = Array.from(args);
  900. // if (delay) fn.delay(delay, this, args);
  901. // else return fn.apply(this, args);
  902. // return this;
  903. //},
  904. submitWork: function(routeName, opinion, medias, callback, processor, data, appendTaskIdentityList){
  905. if (!this.businessData.control["allowProcessing"]){
  906. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "Permission Denied");
  907. this.app.content.unmask();
  908. if( processor && processor.node )processor.node.unmask();
  909. return false;
  910. }
  911. debugger;
  912. if (!this.formValidation(routeName, opinion, medias)){
  913. this.app.content.unmask();
  914. //this.app.notice("", "error", target, where, offset);
  915. if (callback) callback();
  916. return false;
  917. }
  918. if (!this.validation(routeName, opinion, processor, medias)){
  919. //this.app.content.unmask();
  920. if( processor && processor.node )processor.node.unmask();
  921. //if (callback) callback();
  922. return false;
  923. }
  924. if (!opinion){
  925. var idx = this.businessData.task.routeNameList.indexOf(routeName);
  926. if (this.businessData.task.routeOpinionList[idx]){
  927. opinion = this.businessData.task.routeOpinionList[idx];
  928. }
  929. // else{
  930. // opinion = routeName;
  931. // }
  932. }
  933. this.fireEvent("beforeProcess");
  934. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeProcess");
  935. MWF.require("MWF.widget.Mask", function(){
  936. this.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  937. this.mask.loadNode(this.app.content);
  938. this.fireEvent("beforeSave");
  939. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeSave");
  940. this.saveFormData(function(json){
  941. this.businessData.task.routeName = routeName;
  942. this.businessData.task.opinion = opinion;
  943. var mediaIds = [];
  944. if (medias && medias.length){
  945. medias.each(function(file){
  946. var formData = new FormData();
  947. formData.append("file", file);
  948. formData.append("site", "$mediaOpinion");
  949. this.workAction.uploadAttachment(this.businessData.work.id, formData, file, function(json){
  950. mediaIds.push(json.data.id);
  951. }.bind(this), null, false);
  952. }.bind(this));
  953. }
  954. if (mediaIds.length) this.businessData.task.mediaOpinion = mediaIds.join(",");
  955. if( appendTaskIdentityList && appendTaskIdentityList.length ){
  956. var list = [];
  957. appendTaskIdentityList.each( function(identity){
  958. if( typeOf(identity) === "object" ){
  959. list.push( identity.distinguishedName || identity.unique || identity.id )
  960. }else{
  961. list.push( identity );
  962. }
  963. }.bind(this));
  964. this.businessData.task.appendTaskIdentityList = list;
  965. }
  966. this.fireEvent("afterSave");
  967. if (this.app && this.app.fireEvent) this.app.fireEvent("afterSave");
  968. this.workAction.processTask(function(json){
  969. //if (processor) processor.destroy();
  970. //if (processNode) processNode.destroy();
  971. if (callback) callback(json);
  972. this.taskList = json.data;
  973. this.fireEvent("afterProcess");
  974. if (this.app && this.app.fireEvent) this.app.fireEvent("afterProcess");
  975. // this.notice(MWF.xApplication.process.Xform.LP.taskProcessed, "success");
  976. this.addMessage(json.data);
  977. if (this.app.taskObject) this.app.taskObject.destroy();
  978. if (layout.mobile){
  979. var uri = new URI(window.location.href);
  980. var redirectlink = uri.getData("redirectlink");
  981. if( redirectlink ){
  982. window.location = decodeURIComponent(redirectlink);
  983. }else{
  984. window.location = "appMobile.html?app=process.TaskCenter";
  985. }
  986. }else{
  987. if (this.app.inBrowser){
  988. if (this.mask) this.mask.hide();
  989. var content = this.getMessageContent(json.data);
  990. if( this.json.submitedDlgUseNotice ){
  991. MWF.xDesktop.notice("success", {x: "right", y:"top"}, content);
  992. if (this.json.isPrompt!==false){
  993. if (this.json.promptCloseTime!=0){
  994. var t = this.json.promptCloseTime || 2;
  995. t = t.toInt()*1000;
  996. var _work = this;
  997. window.setTimeout(function(){ _work.app.close();}, t);
  998. }
  999. }else{
  1000. this.app.close();
  1001. }
  1002. }else{
  1003. var div = new Element("div", {"styles": {"margin": "10px 10px 0px 10px", "padding": "5px", "overflow": "hidden"}}).inject(this.app.content);
  1004. div.set("html", content);
  1005. if (this.json.isPrompt!==false){
  1006. var options ={
  1007. "content": div,
  1008. "isTitle": false,
  1009. "width": 350,
  1010. "height": 180,
  1011. "buttonList": [
  1012. {
  1013. "text": MWF.xApplication.process.Xform.LP.ok,
  1014. "action": function(){dlg.close(); this.app.close();}.bind(this)
  1015. }
  1016. ]
  1017. }
  1018. var size = this.app.content.getSize();
  1019. switch (this.json.promptPosition || "righttop"){
  1020. case "lefttop":
  1021. options.top = 10;
  1022. options.left = 10;
  1023. options.fromTop = 10;
  1024. options.fromLeft = 10;
  1025. break;
  1026. case "righttop":
  1027. options.top = 10;
  1028. options.left = size.x-360;
  1029. options.fromTop = 10;
  1030. options.fromLeft = size.x-10;
  1031. break;
  1032. case "leftbottom":
  1033. options.top = size.y-190;
  1034. options.left = 10;
  1035. options.fromTop = size.y-10;
  1036. options.fromLeft = 10;
  1037. break;
  1038. case "rightbottom":
  1039. options.top = size.y-190;
  1040. options.left = size.x-360;
  1041. options.fromTop = size.y-10;
  1042. options.fromLeft = size.x-10;
  1043. break;
  1044. default:
  1045. delete options.top;
  1046. delete options.left;
  1047. delete options.fromTop;
  1048. delete options.fromLeft;
  1049. }
  1050. var dlg = o2.DL.open(options);
  1051. if (this.json.promptCloseTime!=0){
  1052. var t = this.json.promptCloseTime || 2;
  1053. t = t.toInt()*1000;
  1054. var _work = this;
  1055. window.setTimeout(function(){dlg.close(); _work.app.close();}, t);
  1056. }
  1057. }else{
  1058. this.app.close();
  1059. }
  1060. }
  1061. }else{
  1062. this.app.close();
  1063. }
  1064. }
  1065. //window.setTimeout(function(){this.app.close();}.bind(this), 2000);
  1066. }.bind(this), null, this.businessData.task.id, this.businessData.task);
  1067. }.bind(this), null, true, data, true);
  1068. }.bind(this));
  1069. },
  1070. processWork: function(){
  1071. if (this.json.mode=="Mobile"){
  1072. this.processWork_mobile();
  1073. }else{
  1074. this.fireEvent("beforeProcessWork");
  1075. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeProcessWork");
  1076. if (!this.formCustomValidation("", "")){
  1077. this.app.content.unmask();
  1078. // if (callback) callback();
  1079. return false;
  1080. }
  1081. // MWF.require("MWF.widget.Mask", function() {
  1082. // this.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  1083. // this.mask.loadNode(this.app.content);
  1084. if (!this.formValidation("", "")){
  1085. this.app.content.unmask();
  1086. // if (callback) callback();
  1087. return false;
  1088. }
  1089. var setSize = function(){
  1090. var dlg = this;
  1091. if( !dlg || !dlg.node )return;
  1092. var size = processNode.getSize();
  1093. dlg.content.setStyles({
  1094. "height" : size.y,
  1095. "width" : size.x
  1096. });
  1097. var s = dlg.setContentSize();
  1098. if( dlg.content.getStyle("overflow-y") === "auto" && dlg.content.getStyle("overflow-x") !== "auto" ){
  1099. dlg.node.setStyle( "width", dlg.node.getStyle("width").toInt() + 20 + "px" );
  1100. dlg.content.setStyle( "width", dlg.content.getStyle("width").toInt() + 20 + "px" );
  1101. }
  1102. dlg.reCenter();
  1103. }
  1104. //var node = new Element("div", {"styles": this.css.rollbackAreaNode});
  1105. var processNode = new Element("div", {"styles": this.app.css.processNode_Area}).inject(this.app.content);
  1106. this.setProcessNode(processNode, "process", function(){
  1107. this.processDlg = o2.DL.open({
  1108. "title": this.app.lp.process,
  1109. "style": this.json.dialogStyle || "user",
  1110. "isResize": false,
  1111. "content": processNode,
  1112. "width": "auto", //processNode.retrieve("width") || 1000, //600,
  1113. "height": "auto", //processNode.retrieve("height") || 401,
  1114. "buttonList": [
  1115. {
  1116. "type" : "ok",
  1117. "text": MWF.LP.process.button.ok,
  1118. "action": function(d, e){
  1119. if (this.processor) this.processor.okButton.click();
  1120. }.bind(this)
  1121. },
  1122. {
  1123. "type" : "cancel",
  1124. "text": MWF.LP.process.button.cancel,
  1125. "action": function(){this.processDlg.close();}.bind(this)
  1126. }
  1127. ],
  1128. "onPostLoad" : function(){
  1129. setSize.call( this )
  1130. }
  1131. });
  1132. }.bind(this), function(){
  1133. setSize.call( this.processDlg )
  1134. }.bind(this));
  1135. }
  1136. },
  1137. processWork_mobile: function(){
  1138. if (this.app.inBrowser){
  1139. this.app.content.setStyle("height", document.body.getSize().y);
  1140. }
  1141. this.fireEvent("beforeProcessWork");
  1142. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeProcessWork");
  1143. var position = this.app.content.getPosition(this.app.content.getOffsetParent());
  1144. if (this.json.mode!="Mobile"){
  1145. this.app.content.mask({
  1146. "destroyOnHide": true,
  1147. "style": this.app.css.maskNode,
  1148. "useIframeShim": true,
  1149. "iframeShimOptions": {"browsers": true},
  1150. "onShow": function(){
  1151. this.shim.shim.setStyles({
  1152. "opacity": 0,
  1153. "top": ""+position.y+"px",
  1154. "left": ""+position.x+"px"
  1155. });
  1156. }
  1157. });
  1158. }
  1159. if (!this.formCustomValidation("", "")){
  1160. this.app.content.unmask();
  1161. // if (callback) callback();
  1162. return false;
  1163. }
  1164. // MWF.require("MWF.widget.Mask", function() {
  1165. // this.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  1166. // this.mask.loadNode(this.app.content);
  1167. if (!this.formValidation("", "")){
  1168. this.app.content.unmask();
  1169. // if (callback) callback();
  1170. return false;
  1171. }
  1172. var processNode = this.createProcessNode();
  1173. this.setProcessNode(processNode);
  1174. this.showProcessNode(processNode);
  1175. //}.bind(this));
  1176. },
  1177. createProcessNode: function(){
  1178. var fromCss = this.app.css.processNode_from;
  1179. var css = this.app.css.processNode;
  1180. if (layout.mobile){
  1181. fromCss = this.app.css.processNodeMobile_from;
  1182. css = this.app.css.processNodeMobile;
  1183. var contentSize = this.app.content.getSize();
  1184. fromCss.width = "100%";
  1185. css.width = "100%";
  1186. fromCss.height = contentSize.y+"px";
  1187. css.height = contentSize.y+"px";
  1188. }
  1189. if (this.json.mode=="Mobile"){
  1190. var processNode = new Element("div", {"styles": fromCss}).inject(document.body);
  1191. }else{
  1192. var processNode = new Element("div", {"styles": fromCss}).inject(this.app.content);
  1193. }
  1194. processNode.position({
  1195. relativeTo: this.app.content,
  1196. position: "topcenter",
  1197. edge: "topcenter"
  1198. });
  1199. return processNode;
  1200. },
  1201. getOpinion: function(){
  1202. var opinion = "";
  1203. var medias = [];
  1204. Object.each(this.forms, function(m, id){
  1205. if (m.json.type==="Opinion") if (this.businessData.data[id]) opinion += " "+m._getBusinessSectionDataByPerson();
  1206. if (m.handwritingFile) if (m.handwritingFile[layout.session.user.distinguishedName]) medias.push(m.handwritingFile[layout.session.user.distinguishedName]);
  1207. if (m.soundFile) if (m.soundFile[layout.session.user.distinguishedName]) medias.push(m.soundFile[layout.session.user.distinguishedName]);
  1208. if (m.videoFile) if (m.videoFile[layout.session.user.distinguishedName]) medias.push(m.videoFile[layout.session.user.distinguishedName]);
  1209. }.bind(this));
  1210. return {"opinion": opinion.trim(), "medias": medias};
  1211. },
  1212. setProcessNode: function(processNode, style, postLoadFun, resizeFun){
  1213. var _self = this;
  1214. MWF.xDesktop.requireApp("process.Work", "Processor", function(){
  1215. var op = this.getOpinion();
  1216. var mds = op.medias;
  1217. this.processor = new MWF.xApplication.process.Work.Processor(processNode, this.businessData.task, {
  1218. "style": (layout.mobile) ? "mobile" : (style || "default"),
  1219. "opinion": op.opinion,
  1220. "tabletWidth" : this.json.tabletWidth || 0,
  1221. "tabletHeight" : this.json.tabletHeight || 0,
  1222. "onPostLoad" : function(){
  1223. if(postLoadFun)postLoadFun();
  1224. }.bind(this),
  1225. "onResize" : function(){
  1226. if( resizeFun )resizeFun();
  1227. },
  1228. "onCancel": function(){
  1229. processNode.destroy();
  1230. _self.app.content.unmask();
  1231. delete this;
  1232. },
  1233. "onSubmit": function(routeName, opinion, medias, appendTaskIdentityList){
  1234. if (!medias || !medias.length){
  1235. medias = mds;
  1236. }else{
  1237. medias = medias.concat(mds)
  1238. }
  1239. _self.submitWork(routeName, opinion, medias, function(){
  1240. this.destroy();
  1241. processNode.destroy();
  1242. if (_self.processDlg) _self.processDlg.close();
  1243. delete this;
  1244. }.bind(this), this, null, appendTaskIdentityList);
  1245. }
  1246. }, this);
  1247. }.bind(this));
  1248. },
  1249. showProcessNode: function(processNode){
  1250. if (layout.mobile){
  1251. processNode.setStyles(this.app.css.processNodeMobile)
  1252. }else{
  1253. var size = this.app.content.getSize();
  1254. var nodeSize = processNode.getSize();
  1255. var top = size.y/2-nodeSize.y/2-20;
  1256. var left = size.x/2-nodeSize.x/2;
  1257. if (top<0) top = 0;
  1258. this.app.css.processNode.top = ""+top+"px";
  1259. this.app.css.processNode.left = ""+left+"px";
  1260. var morph = new Fx.Morph(processNode, {
  1261. "duration": 300,
  1262. "transition": Fx.Transitions.Expo.easeOut
  1263. });
  1264. morph.start(this.app.css.processNode);
  1265. }
  1266. },
  1267. confirm: function(type, e, title, text, width, height, ok, cancel, callback, mask, style){
  1268. MWF.require("MWF.xDesktop.Dialog", function(){
  1269. var size = this.container.getSize();
  1270. var x = 0;
  1271. var y = 0;
  1272. if (typeOf(e)==="element"){
  1273. var position = e.getPosition(this.app.content);
  1274. x = position.x;
  1275. y = position.y;
  1276. }else{
  1277. if (Browser.name=="firefox"){
  1278. x = parseFloat(e.event.clientX || e.event.x);
  1279. y = parseFloat(e.event.clientY || e.event.y);
  1280. }else{
  1281. x = parseFloat(e.event.x);
  1282. y = parseFloat(e.event.y);
  1283. }
  1284. if (e.target){
  1285. var position = e.target.getPosition(this.app.content);
  1286. //var position = e.target.getPosition();
  1287. x = position.x;
  1288. y = position.y;
  1289. }
  1290. }
  1291. // if (Browser.Platform.ios){
  1292. // $("textdiv").set("text", "$(document.body).getScroll().y: "+$(document.body).getScroll().y);
  1293. // y = y-$(document.body).getScroll().y;
  1294. // }
  1295. if (x+parseFloat(width)>size.x){
  1296. x = x-parseFloat(width);
  1297. }
  1298. if (x<0) x = 10;
  1299. if (y+parseFloat(height)>size.y){
  1300. y = y-parseFloat(height);
  1301. }
  1302. if (y<0) y = 10;
  1303. //var x = parseFloat((Browser.name==="firefox") ? e.event.clientX : e.event.x);
  1304. //var y = parseFloat((Browser.name==="firefox") ? e.event.clientY : e.event.y);
  1305. // if (x+parseFloat(width)>size.x){
  1306. // x = x-parseFloat(width);
  1307. // }
  1308. if (x<0) x = 20;
  1309. var dlg = new MWF.xDesktop.Dialog({
  1310. "title": title,
  1311. "style": style || "o2",
  1312. "top": y,
  1313. "left": x-20,
  1314. "fromTop":e.event.y,
  1315. "fromLeft": (Browser.name==="firefox") ? e.event.clientX-20 : e.event.x-20,
  1316. "width": width,
  1317. "height": height,
  1318. "text": text,
  1319. "container": this.app.content,
  1320. "maskNode": mask || this.app.content,
  1321. "buttonList": [
  1322. {
  1323. "type" : "ok",
  1324. "text": MWF.LP.process.button.ok,
  1325. "action": ok
  1326. },
  1327. {
  1328. "type" : "cancel",
  1329. "text": MWF.LP.process.button.cancel,
  1330. "action": cancel
  1331. }
  1332. ]
  1333. });
  1334. switch (type.toLowerCase()) {
  1335. case "success":
  1336. if (this.json.confirmIcon && this.json.confirmIcon.success) {
  1337. dlg.content.setStyle("background-image", "url(" + this.json.confirmIcon.success + ")");
  1338. } else {
  1339. dlg.content.setStyle("background-image", "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAjCAYAAAAe2bNZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAB1hJREFUeNqsWGtsVEUUPnMf+y6rLcW2tDxUKARaikqgiWh8BlH8IwYkaozhh4nhB1FMTKkxQtQYQzRGE2JEfMRHYhQSVChgFYIGqLSUtoKUQmlp2b53u233de94zuzcZbfdbhdwkpPZmbl3zjffnHPuOcue/WgxZNnc3OT3cQ4rGIMlwNg8BjATGEwDDgHOeZdpQis3eKMR5Sd62kaO/PHp5QDub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0raEQf7a2r04GtICU4FT/QmTDPJOGTqAcMnl2yrFNJkZWMIhJ7yAZk5E1JMfm+EI/naLraQRKlQBUKUoSGFNWh4YEZowv7jO1/wQYAIxJoZGb/Cz/AAAAAElFTkSuQmCC)");
  1340. }
  1341. break;
  1342. case "error":
  1343. if( this.json.confirmIcon && this.json.confirmIcon.error ){
  1344. dlg.content.setStyle("background-image", "url("+this.json.confirmIcon.error+")");
  1345. }else{
  1346. dlg.content.setStyle("background-image", "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAjCAYAAAAe2bNZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABsVJREFUeNqkWFtsFGUU/nZn2r21IqX3llp6AQmkWDVGAgIlGI0EeMAHffAFa998MCQaE8JDxZCgSHzQKIm3qPHFGC7GW0xqkIgIKhhEwFJaKSDQUtplu73s7vidmX/q32F2uw2TnOzMv2fO+f5z/8fci7yvWAZYRXo4CCwLAM1cq+HvXRYwQrrM/7rTwB+TwC/dwKG3uU75mVxCO7T7wExgKHiBATzJ2411wMoy3pSQ5gg6UiFpgpQgDZNukK6TLgBHuf7lAPD5q8DfXMpQl5U3mA4P4ztAO3+2tADLCQSV+VsR/5L+If0G/EqgH78EvKtwT1lqr0en6SfoLaCe1niB7nj+CQIuV+uZWYApV8RNPPAVcP/rQMtF4I03gbNcpjdvt5KxQXs4SKKflxBI54PAs20EElNvZTQJucjLFyUtpZwioJVurFtMD/4MXBXWDUqnL5jHHYt0PgQ8da/4UFMwThpTz0HF7wfEj0/kSKwVAwsZU5U1wKkTwOBBj7GD08xE17QSSJPanVCKlCSNkM5s2mT/JtV6epZ8InclsH4R9TjYRKWPZQixnch2POJsZNpOb5HOb9yIi5s3I5XJIHb2rL2LoBZL+fBZKhOZaS3LgPgh4HcnYZ34scFI+goQxsj8iA+QHipItrejrKwMiaVLMZJIIEpFAaUkH76AFrEVfLxEzzEej/0FXFOGc8CQ8bmFTOE6DciEUn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EhZq9lIyfgY3RXwzrY3lKKytWtxhgp6fHaaL5+AoU8stulPvgB+UFZJuPOMPaF/D5wgoGq6q9XMosianER3FiD58iWcDNr/GvCegwtDbjeywShAGQ5Y3aYzZC00PELsDkxFmOGokosv6cy/XV8DHyr3XFfL1rSBnL/WNqKUcw3rQWWhD6A7oaSTPV1dwEecX07CmX1v6W3Re4iz5IAl5xqCiTIMW0zJ5DsAkXKOLxbHy/1iEQ3IiHdYmAbGdZccsBhDXXKcoMAyWqjCynJwywVCqjgbz2kJVokR5RoXyKRkctYTpQ5Iepica+Q4QesMU0GUoCozPjGS0QZ5t9uzJ51ioO6T9FVZc1XFiLgm5X6ROJjvJ5EOZ4iXwaeIs2Elz1WreExtlVFRJjQZjGQekTFAuq80PRazbp6JTtOyxy87FX9EkYCY8H6v6fDMNzNdagayQYXVZ5mIei7UmrHrnQlFSZXJY9qnECuXIjMPMJZ2lHIPj6aaGg0FNOD5CJHWjtl5f0n5T4ABAFHaXG6UVjGNAAAAAElFTkSuQmCC)");
  1347. }
  1348. break;
  1349. case "info":
  1350. if( this.json.confirmIcon && this.json.confirmIcon.info ){
  1351. dlg.content.setStyle("background-image", "url("+this.json.confirmIcon.info+")");
  1352. }else {
  1353. dlg.content.setStyle("background-image", "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAjCAYAAAAe2bNZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABvBJREFUeNqsWF1sFFUUPndm9n+3W5aWLi2VGgJtgy3UEn6MQGI0GgmC0UgfTEjEBxPDA29qYqLGGOODifGBGGOUYOKDPIg2QgykWgUtP1WgLT+lFKFCf9l2uz+z83c9Z3p3u1u6u4Pxpqczd+7MPd8999xzvrPskb2fgsMW4NzaBpxvBsbWMWCrgUEdAKsA4HHO+R2wrOucmxe5qZ9Jjt3ovtX1eRznt0pN2ndof+5eKYcAJ34YJPlFvH3OFV7+uOyPgOQLg+wJAXP5gMkueifM9XTY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357. if( this.json.confirmIcon && this.json.confirmIcon.warn ){
  1358. dlg.content.setStyle("background-image", "url("+this.json.confirmIcon.warn+")");
  1359. }else {
  1360. dlg.content.setStyle("background-image", "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAjCAYAAAAe2bNZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABgtJREFUeNqsWG2IlFUUft6vmdlZd539GFdTY5VMomy1oBJUSPLXkmQt5I8gCIMK+iH0K4ooEvtTRP7JX9JKWCC1mUUkIkQKSoaZH60t2pboOK37Mc6Ozsw779t57t5xx5ndnTvhC4d373nnnnPuOeee85y1Jr+G6dNcCrBB6AnbQo9tY4UFLLYstIYhMsK/IjRULOF0voATx87jp60fICPygzmFbpn+26pnzK0ilrk2+kTp5kgC6+w4YDfJxpiQJ+QAYUmoKHQLCG4K5YDsCI7fzOPgcBr7172BP0VUILrC/22MnHSbvF6KLcRap1WMmGfsRQRZ2Z8BJv7BybEs9t6/DbuFXaj2VKUx7ize6BZvbHcdvB67D5bdrD/ocwUiruiLZPFGSbziiHci4iVPpEn41MM9pPZWPBofwiOX9uDh05fwkSgf5Dln8lKNZwo+HnRsvBVbjK1eJ39RdWIxJCfhGB0HxjNTBtGQhHiuPQHEY9MG3X5EbXEESA3i4KmL2Ln5Xfwi3CINmjVM9IjnYGeTGOJ2zOx+SU5cE8Hp/DMIopvgxFejlDsFO38IC6ID6JIDRCMz7/WvA1cG8d2PJ/H2y5/gLA2a9ndVmBia2CIxpL3yJ1XG5MUzTh8S3e/B9Zo09x74xSeRS7vyfT+i3sx7KXfRCvSuz2NUltuFJmhj+btdmazMEa+NsZidfIYlsQXzE51oa2tDV1eXenNNPr/PtZ/ylybxwtEP8Ypw4pU22OXrq27NvZIh4dzCeI07lvQiHo8jFovBdV315pp8fp9rP+VTT/cCPL/jRawSTqScma4OT1+sA2vtqN4w552V03meMsKyprLblowlj2s/qC+DepJLsWpjD56T5aDOnRI908yC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MxK6EiERqBEfEIYQC7L5seew1LPCurLmgZTdl6/4UwaWmWzq2IRvHNGrNGNLmYdpCvb0dBl/hJXdAKJrOF1eClsHX4XP12NM+qGFJKmnz9NgYV/wkwAMYATK0QLuhAAAAAAElFTkSuQmCC)");
  1361. }
  1362. break;
  1363. default:
  1364. if( this.json.confirmIcon && this.json.confirmIcon.warn ){
  1365. dlg.content.setStyle("background-image", "url("+this.json.confirmIcon.warn+")");
  1366. }
  1367. break;
  1368. }
  1369. dlg.show();
  1370. }.bind(this));
  1371. },
  1372. notice: function(content, type, target, where, offset, option){
  1373. if (!where) where = {"x": "right", "y": "top"};
  1374. if (!target) target = this.node;
  1375. if (!type) type = "ok";
  1376. var noticeTarget = target || layout.layout.contentNode;
  1377. var off = offset;
  1378. if (!off){
  1379. off = {
  1380. x: 10,
  1381. y: where.y.toString().toLowerCase()=="bottom" ? 10 : 10
  1382. };
  1383. }
  1384. var options = {
  1385. type: type,
  1386. position: where,
  1387. move: false,
  1388. target: noticeTarget,
  1389. delayClose: (type==="error") ? 10000 : 5000,
  1390. offset: off,
  1391. content: content
  1392. }
  1393. if( this.json.noticeStyle ) {
  1394. options = Object.merge( options, this.json.noticeStyle);
  1395. }
  1396. if( this.json["notice"+type.capitalize()+"Style"] ){
  1397. options = Object.merge( options, this.json["notice"+type.capitalize()+"Style"] );
  1398. }
  1399. if( option && typeOf(option) === "object" ){
  1400. options = Object.merge( options, option );
  1401. }
  1402. new mBox.Notice(options);
  1403. },
  1404. addSplit: function(){
  1405. if (!this.businessData.control["allowAddSplit"]){
  1406. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "Permission Denied");
  1407. return false;
  1408. }
  1409. MWF.require("MWF.xDesktop.Dialog", function(){
  1410. var width = 600;
  1411. var height = 230;
  1412. var p = MWF.getCenterPosition(this.app.content, width, height);
  1413. var _self = this;
  1414. var dlg = new MWF.xDesktop.Dialog({
  1415. "title": this.app.lp.addSplit,
  1416. //"style": "work","
  1417. "style" : this.json.dialogStyle || "user",
  1418. "top": p.y-100,
  1419. "left": p.x,
  1420. "fromTop": p.y-100,
  1421. "fromLeft": p.x,
  1422. "width": width,
  1423. "height": height,
  1424. "url": this.app.path+"split.html",
  1425. "container": this.app.content,
  1426. "isClose": true,
  1427. "buttonList": [
  1428. {
  1429. "type" : "ok",
  1430. "text": MWF.LP.process.button.ok,
  1431. "action": function(d, e){
  1432. //this.doResetWork(dlg);
  1433. var input = dlg.content.getElement("input");
  1434. var checks = dlg.content.getElements(".o2_addSplit_radio");
  1435. var value = input.get("value");
  1436. var trimExist = true;
  1437. if (checks[1].checked) trimExist = false;
  1438. _self.doAddSplit(dlg, value, trimExist);
  1439. }.bind(this)
  1440. },
  1441. {
  1442. "type" : "cancel",
  1443. "text": MWF.LP.process.button.cancel,
  1444. "action": function(){dlg.close();}
  1445. }
  1446. ],
  1447. "onPostShow": function(){
  1448. //var okButton = dlg.content.getElement(".o2_addSplit_okButton");
  1449. //var cancelButton = dlg.content.getElement(".o2_addSplit_cancelButton");
  1450. var selectButton = dlg.content.getElement(".o2_addSplit_selector");
  1451. var input = dlg.content.getElement("input");
  1452. var checks = dlg.content.getElements(".o2_addSplit_radio");
  1453. //okButton.addEvent("click", function(){
  1454. // var value = input.get("value");
  1455. // var trimExist = true;
  1456. // if (checks[1].checked) trimExist = false;
  1457. // _self.doAddSplit(this, value, trimExist);
  1458. //}.bind(this));
  1459. //cancelButton.addEvent("click", function(){
  1460. // this.close();
  1461. //}.bind(this));
  1462. selectButton.addEvent("click", function(){
  1463. var value = input.get("value");
  1464. MWF.xDesktop.requireApp("Selector", "package", function(){
  1465. new o2.O2Selector(_self.app.content, {
  1466. "type": "",
  1467. "count": 0,
  1468. "values": (value) ? value.split(o2.splitStr): [],
  1469. "types": ["unit", "identity", "group", "role"],
  1470. "onComplete": function(items){
  1471. var v = [];
  1472. items.each(function(item){
  1473. v.push(item.data.distinguishedName);
  1474. });
  1475. input.set("value", v.join(", "));
  1476. }
  1477. });
  1478. }.bind(this));
  1479. //_self.selectSplitUnit(this);
  1480. }.bind(this));
  1481. }
  1482. });
  1483. dlg.show();
  1484. }.bind(this));
  1485. },
  1486. doAddSplit: function(dlg, splitValues, trimExist){
  1487. if (!splitValues){
  1488. this.app.notice(MWF.xApplication.process.Xform.LP.inputSplitValue, "error", dlg.node);
  1489. return false;
  1490. }
  1491. MWF.require("MWF.widget.Mask", function(){
  1492. var splitValue = splitValues.split(o2.splitStr);
  1493. this.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  1494. this.mask.loadNode(this.app.content);
  1495. this.fireEvent("beforeAddSplit");
  1496. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeAddSplit");
  1497. this.addSplitWork(splitValue, trimExist, function(json){
  1498. this.fireEvent("afterAddSplit");
  1499. if (this.app && this.app.fireEvent) this.app.fireEvent("afterAddSplit");
  1500. this.addAddSplitMessage(json.data);
  1501. // this.workAction.loadWork(function(workJson){
  1502. // this.fireEvent("afterAddSplit");
  1503. // if (this.app && this.app.fireEvent) this.app.fireEvent("afterAddSplit");
  1504. // this.addAddSplitMessage(workJson.data);
  1505. // }.bind(this), null, this.businessData.work.id);
  1506. dlg.close();
  1507. if (this.mask) {this.mask.hide(); this.mask = null;}
  1508. }.bind(this), function(xhr, text, error){
  1509. var errorText = error+":"+text;
  1510. if (xhr) errorText = xhr.responseText;
  1511. this.app.notice("request json error: "+errorText, "error", dlg.node);
  1512. if (this.mask) {this.mask.hide(); this.mask = null;}
  1513. }.bind(this));
  1514. }.bind(this));
  1515. },
  1516. addSplitWork: function(splitValue, trimExist, success, failure){
  1517. var data = {"splitValueList": splitValue, "trimExist": trimExist};
  1518. if (this.options.readonly){
  1519. this.workAction.addSplit(
  1520. function(json){
  1521. if (success) success(json);
  1522. }.bind(this),
  1523. function(xhr, text, error){
  1524. if (failure) failure(xhr, text, error);
  1525. },
  1526. this.businessData.work.id, data
  1527. );
  1528. }else{
  1529. this.saveFormData(
  1530. function(json){
  1531. this.workAction.addSplit(
  1532. function(json){
  1533. if (success) success(json);
  1534. }.bind(this),
  1535. function(xhr, text, error){
  1536. if (failure) failure(xhr, text, error);
  1537. },
  1538. this.businessData.work.id, data
  1539. );
  1540. }.bind(this),
  1541. function(xhr, text, error){
  1542. if (failure) failure(xhr, text, error);
  1543. }, true, null, true
  1544. );
  1545. }
  1546. },
  1547. setRollBackChecked: function(item){
  1548. item.store("isSelected", true);
  1549. item.setStyles(this.css.rollbackItemNode_current);
  1550. item.getFirst().setStyles(this.css.rollbackItemIconNode_current);
  1551. var node = item.getLast().getFirst();
  1552. node.getFirst().setStyles(this.css.rollbackItemActivityNode_current);
  1553. node.getLast().setStyles(this.css.rollbackItemTimeNode_current);
  1554. node = item.getLast().getLast();
  1555. node.getFirst().setStyles(this.css.rollbackItemTaskTitleNode_current);
  1556. node.getLast().setStyles(this.css.rollbackItemTaskNode_current);
  1557. },
  1558. setRollBackUnchecked: function(item){
  1559. item.store("isSelected", false);
  1560. item.setStyles(this.css.rollbackItemNode);
  1561. item.getFirst().setStyles(this.css.rollbackItemIconNode);
  1562. var node = item.getLast().getFirst();
  1563. node.getFirst().setStyles(this.css.rollbackItemActivityNode);
  1564. node.getLast().setStyles(this.css.rollbackItemTimeNode);
  1565. node = item.getLast().getLast();
  1566. node.getFirst().setStyles(this.css.rollbackItemTaskTitleNode);
  1567. node.getLast().setStyles(this.css.rollbackItemTaskNode);
  1568. },
  1569. getRollbackLogs: function(rollbackItemNode){
  1570. var _self = this;
  1571. this.businessData.workLogList.each(function(log){
  1572. if (!log.splitting && log.connected && (log.taskCompletedList.length || log.readList.length || log.readCompletedList.length)){
  1573. var node = new Element("div", {"styles": this.css.rollbackItemNode}).inject(rollbackItemNode);
  1574. node.store("log", log);
  1575. var iconNode = new Element("div", {"styles": this.css.rollbackItemIconNode}).inject(node);
  1576. var contentNode = new Element("div", {"styles": this.css.rollbackItemContentNode}).inject(node);
  1577. var div = new Element("div", {"styles": {"overflow": "hidden"}}).inject(contentNode);
  1578. var activityNode = new Element("div", {"styles": this.css.rollbackItemActivityNode, "text": log.fromActivityName}).inject(div);
  1579. var timeNode = new Element("div", {"styles": this.css.rollbackItemTimeNode, "text": log.arrivedTime}).inject(div);
  1580. div = new Element("div", {"styles": {"overflow": "hidden"}}).inject(contentNode);
  1581. var taskTitleNode = new Element("div", {"styles": this.css.rollbackItemTaskTitleNode, "text": this.app.lp.taskCompletedPerson+": "}).inject(div);
  1582. log.taskCompletedList.each(function(o){
  1583. var text = o2.name.cn(o.person)+"("+o.completedTime+")";
  1584. var taskNode = new Element("div", {"styles": this.css.rollbackItemTaskNode, "text": text}).inject(div);
  1585. }.bind(this));
  1586. node.addEvents({
  1587. "mouseover": function(){
  1588. var isSelected = this.retrieve("isSelected");
  1589. if (!isSelected) this.setStyles(_self.css.rollbackItemNode_over);
  1590. },
  1591. "mouseout": function(){
  1592. var isSelected = this.retrieve("isSelected");
  1593. if (!isSelected) this.setStyles(_self.css.rollbackItemNode)
  1594. },
  1595. "click": function(){
  1596. var isSelected = this.retrieve("isSelected");
  1597. if (isSelected){
  1598. _self.setRollBackUnchecked(this);
  1599. }else{
  1600. var items = rollbackItemNode.getChildren();
  1601. items.each(function(item){
  1602. _self.setRollBackUnchecked(item);
  1603. });
  1604. _self.setRollBackChecked(this);
  1605. }
  1606. }
  1607. });
  1608. }
  1609. }.bind(this));
  1610. },
  1611. rollback: function(){
  1612. if (!this.businessData.control["allowRollback"]){
  1613. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "Permission Denied");
  1614. return false;
  1615. }
  1616. var node = new Element("div", {"styles": this.css.rollbackAreaNode});
  1617. var html = "<div style=\"line-height: 30px; height: 30px; color: #333333; overflow: hidden\">请选择文件要回溯到的位置:</div>";
  1618. html += "<div style=\"max-height: 300px; margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  1619. node.set("html", html);
  1620. var rollbackItemNode = node.getLast();
  1621. this.getRollbackLogs(rollbackItemNode);
  1622. node.inject(this.app.content);
  1623. var dlg = o2.DL.open({
  1624. "title": this.app.lp.rollback,
  1625. "style": this.json.dialogStyle || "user",
  1626. "isResize": false,
  1627. "content": node,
  1628. "width": 600,
  1629. "buttonList": [
  1630. {
  1631. "type" : "ok",
  1632. "text": MWF.LP.process.button.ok,
  1633. "action": function(d, e){
  1634. this.doRollback(node, e, dlg);
  1635. }.bind(this)
  1636. },
  1637. {
  1638. "type" : "cancel",
  1639. "text": MWF.LP.process.button.cancel,
  1640. "action": function(){dlg.close();}
  1641. }
  1642. ]
  1643. });
  1644. },
  1645. doRollback: function(node, e, dlg){
  1646. var rollbackItemNode = node.getLast();
  1647. var items = rollbackItemNode.getChildren();
  1648. var _self = this;
  1649. for (var i=0; i<items.length; i++){
  1650. if (items[i].retrieve("isSelected")){
  1651. var text = this.app.lp.rollbackConfirmContent;
  1652. var log = items[i].retrieve("log");
  1653. text = text.replace("{log}", log.fromActivityName+"("+log.arrivedTime+")");
  1654. this.app.confirm("infor", e, this.app.lp.rollbackConfirmTitle, text, 450, 120, function(){
  1655. _self.doRollbackAction(log.id, dlg);
  1656. dlg.close();
  1657. this.close();
  1658. }, function(){
  1659. this.close();
  1660. }, null, null, this.json.confirmStyle);
  1661. break;
  1662. }
  1663. }
  1664. },
  1665. doRollbackAction: function(log){
  1666. MWF.require("MWF.widget.Mask", function(){
  1667. this.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  1668. this.mask.loadNode(this.app.content);
  1669. this.fireEvent("beforeRollback");
  1670. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeRollback");
  1671. this.doRollbackActionInvoke(log, function(json){
  1672. var id = json.data.id;
  1673. this.workAction.listTaskByWork(function(workJson){
  1674. this.fireEvent("afterRollback");
  1675. if (this.app && this.app.fireEvent) this.app.fireEvent("afterRollback");
  1676. this.addRollbackMessage(workJson.data);
  1677. //this.app.notice(MWF.xApplication.process.Xform.LP.rollbackOk+": "+MWF.name.cns(names).join(", "), "success");
  1678. this.app.close();
  1679. }.bind(this), null, id);
  1680. if (this.mask) {this.mask.hide(); this.mask = null;}
  1681. }.bind(this), function(xhr, text, error){
  1682. var errorText = error+":"+text;
  1683. if (xhr) errorText = xhr.responseText;
  1684. this.app.notice("request json error: "+errorText, "error");
  1685. if (this.mask) {this.mask.hide(); this.mask = null;}
  1686. }.bind(this));
  1687. }.bind(this));
  1688. },
  1689. doRollbackActionInvoke: function(id, success, failure){
  1690. var method = (this.businessData.work.completedTime) ? "rollbackWorkcompleted" : "rollback";
  1691. o2.Actions.get("x_processplatform_assemble_surface")[method](this.businessData.work.id, {"workLog":id}, function(json){
  1692. if (success) success(json);
  1693. }.bind(this), function(xhr, text, error){
  1694. if (failure) failure(xhr, text, error)
  1695. }.bind(this));
  1696. },
  1697. addRollbackMessage: function(data){
  1698. var users = [];
  1699. data.each(function(task){
  1700. users.push(MWF.name.cn(task.person)+"("+MWF.name.cn(task.unit)+")");
  1701. }.bind(this));
  1702. var content = "<div><b>"+MWF.xApplication.process.Xform.LP.currentActivity+"<font style=\"color: #ea621f\">"+data[0].activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  1703. var msg = {
  1704. "subject": MWF.xApplication.process.Xform.LP.workRollback,
  1705. "content": "<div>"+MWF.xApplication.process.Xform.LP.rollbackWorkInfor+"“"+this.businessData.work.title+"”</div>"+content
  1706. };
  1707. layout.desktop.message.addTooltip(msg);
  1708. return layout.desktop.message.addMessage(msg);
  1709. },
  1710. pressWork: function(e){
  1711. if(e && e.setDisable)e.setDisable(true);
  1712. o2.Actions.get("x_processplatform_assemble_surface").press(this.businessData.work.id, function(json){
  1713. var users = o2.name.cns(json.data.valueList).join(", ");
  1714. this.app.notice("已经向待办人:"+users+", 发送了提醒", "success");
  1715. if(e && e.setDisable)e.setDisable(false);
  1716. }.bind(this), function(xhr, text, error){
  1717. //e.setDisable(false);
  1718. if (xhr.status!=0){
  1719. var errorText = error;
  1720. if (xhr){
  1721. var json = JSON.decode(xhr.responseText);
  1722. if (json){
  1723. errorText = json.message.trim() || "request json error";
  1724. }else{
  1725. errorText = "request json error: "+xhr.responseText;
  1726. }
  1727. }
  1728. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  1729. }
  1730. });
  1731. },
  1732. resetWork: function(){
  1733. if (!this.businessData.control["allowReset"]){
  1734. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "Permission Denied");
  1735. return false;
  1736. }
  1737. MWF.require("MWF.xDesktop.Dialog", function(){
  1738. var width = 680;
  1739. var height = 300;
  1740. var p = MWF.getCenterPosition(this.app.content, width, height);
  1741. var _self = this;
  1742. var dlg = new MWF.xDesktop.Dialog({
  1743. "title": this.app.lp.reset,
  1744. "style": this.json.dialogStyle || "user", //|| "work",
  1745. "top": p.y-100,
  1746. "left": p.x,
  1747. "fromTop": p.y-100,
  1748. "fromLeft": p.x,
  1749. "width": width,
  1750. "height": height,
  1751. "url": this.app.path+"reset.html",
  1752. "container": this.app.content,
  1753. "isClose": true,
  1754. "buttonList": [
  1755. {
  1756. "type" : "ok",
  1757. "text": MWF.LP.process.button.ok,
  1758. "action": function(d, e){
  1759. this.doResetWork(dlg);
  1760. }.bind(this)
  1761. },
  1762. {
  1763. "type" : "cancel",
  1764. "text": MWF.LP.process.button.cancel,
  1765. "action": function(){dlg.close();}
  1766. }
  1767. ],
  1768. "onPostShow": function(){
  1769. //$("resetWork_okButton").addEvent("click", function(){
  1770. // _self.doResetWork(this);
  1771. //}.bind(this));
  1772. //$("resetWork_cancelButton").addEvent("click", function(){
  1773. // this.close();
  1774. //}.bind(this));
  1775. $("resetWork_selPeopleButton").addEvent("click", function(){
  1776. _self.selectPeople(this);
  1777. }.bind(this));
  1778. }
  1779. });
  1780. dlg.show();
  1781. }.bind(this));
  1782. },
  1783. selectPeople: function(dlg){
  1784. var range = this.businessData.activity.resetRange || "department";
  1785. var count = this.businessData.activity.resetCount || 0;
  1786. switch (range){
  1787. case "unit":
  1788. this.selectPeopleUnit(dlg, this.businessData.task.unit, count);
  1789. // this.personActions.getDepartmentByIdentity(function(json){
  1790. // this.selectPeopleDepartment(dlg, json.data, count);
  1791. // }.bind(this), null, this.businessData.task.identity);
  1792. break;
  1793. case "topUnit":
  1794. MWF.require("MWF.xScript.Actions.UnitActions", function(){
  1795. orgActions = new MWF.xScript.Actions.UnitActions();
  1796. var data = {"unitList": [this.businessData.task.unit]};
  1797. orgActions.listUnitSupNested(data, function(json){
  1798. v = json.data[0];
  1799. this.selectPeopleUnit(dlg, v, count);
  1800. }.bind(this));
  1801. }.bind(this));
  1802. // this.personActions.getCompanyByIdentity(function(json){
  1803. // this.selectPeopleCompany(dlg, json.data, count)
  1804. // }.bind(this), null, this.businessData.task.identity);
  1805. break;
  1806. default:
  1807. this.selectPeopleAll(dlg, count);
  1808. }
  1809. },
  1810. selectPeopleUnit: function(dlg, unit, count){
  1811. var names = dlg.identityList || [];
  1812. var areaNode = $("resetWork_selPeopleArea");
  1813. var options = {
  1814. "values": names,
  1815. "type": "identity",
  1816. "count": count,
  1817. "units": (unit) ? [unit]: [],
  1818. "title": this.app.lp.reset,
  1819. "onComplete": function (items) {
  1820. areaNode.empty();
  1821. var identityList = [];
  1822. items.each(function(item){
  1823. new MWF.widget.O2Identity(item.data, areaNode, {"style": "reset"});
  1824. identityList.push(item.data.distinguishedName);
  1825. }.bind(this));
  1826. dlg.identityList = identityList;
  1827. }.bind(this)
  1828. };
  1829. MWF.xDesktop.requireApp("Selector", "package", function(){
  1830. var selector = new MWF.O2Selector(this.app.content, options);
  1831. }.bind(this));
  1832. },
  1833. // selectPeopleDepartment: function(dlg, department, count){
  1834. // var names = dlg.identityList || [];
  1835. // var areaNode = $("resetWork_selPeopleArea");
  1836. // var options = {
  1837. // "names": names,
  1838. // "type": "identity",
  1839. // "count": count,
  1840. // "departments": (department) ? [department.name]: [],
  1841. // "title": this.app.lp.reset,
  1842. // "onComplete": function (items) {
  1843. // areaNode.empty();
  1844. // var identityList = [];
  1845. // items.each(function(item){
  1846. // var explorer = {
  1847. // "actions": this.personActions,
  1848. // "app": {"lp": this.app.lp}
  1849. // };
  1850. // new MWF.widget.Identity(item.data, areaNode, explorer, false, null, {"style": "reset"});
  1851. // identityList.push(item.data.name);
  1852. // }.bind(this));
  1853. // dlg.identityList = identityList;
  1854. // }.bind(this)
  1855. // };
  1856. //
  1857. // var selector = new MWF.OrgSelector(this.app.content, options);
  1858. // },
  1859. // selectPeopleCompany: function(dlg, company, count){
  1860. // var names = dlg.identityList || [];
  1861. // var areaNode = $("resetWork_selPeopleArea");
  1862. // var options = {
  1863. // "names": names,
  1864. // "type": "identity",
  1865. // "count": count,
  1866. // "companys": [company.name],
  1867. // "title": this.app.lp.reset,
  1868. // "onComplete": function (items) {
  1869. // areaNode.empty();
  1870. // var identityList = [];
  1871. // items.each(function(item){
  1872. // var explorer = {
  1873. // "actions": this.personActions,
  1874. // "app": {"lp": this.app.lp}
  1875. // };
  1876. // new MWF.widget.Identity(item.data, areaNode, explorer, false, null, {"style": "reset"});
  1877. // identityList.push(item.data.name);
  1878. // }.bind(this));
  1879. // dlg.identityList = identityList;
  1880. // }.bind(this)
  1881. // };
  1882. //
  1883. // var selector = new MWF.Selector(this.app.content, options);
  1884. // },
  1885. selectPeopleAll: function(dlg, count){
  1886. var names = dlg.identityList || [];
  1887. var areaNode = $("resetWork_selPeopleArea");
  1888. var options = {
  1889. "values": names,
  1890. "type": "identity",
  1891. "count": count,
  1892. "title": this.app.lp.reset,
  1893. "onComplete": function (items) {
  1894. areaNode.empty();
  1895. var identityList = [];
  1896. items.each(function(item){
  1897. new MWF.widget.O2Identity(item.data, areaNode, {"style": "reset"});
  1898. identityList.push(item.data.distinguishedName);
  1899. }.bind(this));
  1900. dlg.identityList = identityList;
  1901. }.bind(this)
  1902. };
  1903. MWF.xDesktop.requireApp("Selector", "package", function(){
  1904. var selector = new MWF.O2Selector(this.app.content, options);
  1905. }.bind(this));
  1906. },
  1907. doResetWork: function(dlg){
  1908. var names = dlg.identityList || [];
  1909. if (!names.length){
  1910. this.app.notice(MWF.xApplication.process.Xform.LP.inputResetPeople, "error", dlg.node);
  1911. return false;
  1912. }
  1913. var opinion = $("resetWork_opinion").get("value");
  1914. var nameText = [];
  1915. names.each(function(n){ nameText.push(MWF.name.cn(n)); });
  1916. if (!opinion){
  1917. opinion = MWF.xApplication.process.Xform.LP.resetTo+": "+nameText.join(", ");
  1918. }
  1919. MWF.require("MWF.widget.Mask", function(){
  1920. this.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  1921. this.mask.loadNode(this.app.content);
  1922. this.fireEvent("beforeReset");
  1923. if (this.app && this.app.fireEvent) this.app.fireEvent("beforeReset");
  1924. this.resetWorkToPeson(names, opinion, function(){
  1925. this.workAction.loadWork(function(workJson){
  1926. this.fireEvent("afterReset");
  1927. if (this.app && this.app.fireEvent) this.app.fireEvent("afterReset");
  1928. this.addResetMessage(workJson.data);
  1929. this.app.notice(MWF.xApplication.process.Xform.LP.resetOk+": "+MWF.name.cns(names).join(", "), "success");
  1930. this.app.close();
  1931. }.bind(this), null, this.businessData.work.id);
  1932. dlg.close();
  1933. if (this.mask) {this.mask.hide(); this.mask = null;}
  1934. }.bind(this), function(xhr, text, error){
  1935. var errorText = error+":"+text;
  1936. if (xhr) errorText = xhr.responseText;
  1937. this.app.notice("request json error: "+errorText, "error", dlg.node);
  1938. if (this.mask) {this.mask.hide(); this.mask = null;}
  1939. }.bind(this));
  1940. }.bind(this));
  1941. //var data = {
  1942. // "opinion": opinion,
  1943. // "routeName": MWF.xApplication.process.Xform.LP.reset,
  1944. // "identityList": names
  1945. //}
  1946. //
  1947. //this.workAction.resetWork(function(json){
  1948. //
  1949. //}.bind(this), null, this.businessData.task.id, data);
  1950. },
  1951. resetWorkToPeson: function(identityList, opinion, success, failure){
  1952. var data = {
  1953. "opinion": opinion,
  1954. "routeName": MWF.xApplication.process.Xform.LP.reset,
  1955. "identityList": identityList
  1956. };
  1957. this.saveFormData(
  1958. function(json){
  1959. this.workAction.resetWork(
  1960. function(json){
  1961. if (success) success(json);
  1962. }.bind(this),
  1963. function(xhr, text, error){
  1964. if (failure) failure(xhr, text, error);
  1965. },
  1966. this.businessData.task.id, data
  1967. );
  1968. }.bind(this),
  1969. function(xhr, text, error){
  1970. if (failure) failure(xhr, text, error);
  1971. }, true, null, true
  1972. );
  1973. },
  1974. addAddSplitMessage: function(data){
  1975. var content = "";
  1976. if (data && data.length){
  1977. data.each(function(work){
  1978. var users = [];
  1979. work.taskList.each(function(task){
  1980. users.push(MWF.name.cn(task.person)+"("+MWF.name.cn(task.unit)+")");
  1981. }.bind(this));
  1982. content += "<div><b>"+MWF.xApplication.process.Xform.LP.nextActivity+"<font style=\"color: #ea621f\">"+work.activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  1983. }.bind(this));
  1984. }else{
  1985. content += MWF.xApplication.process.Xform.LP.workCompleted;
  1986. }
  1987. //var content = "<div><b>"+MWF.xApplication.process.Xform.LP.currentActivity+"<font style=\"color: #ea621f\">"+data.work.activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  1988. var msg = {
  1989. "subject": MWF.xApplication.process.Xform.LP.addSplitWork,
  1990. "content": "<div>"+MWF.xApplication.process.Xform.LP.addSplitWorkInfor+"“"+this.businessData.work.title+"”</div>"+content
  1991. };
  1992. layout.desktop.message.addTooltip(msg);
  1993. return layout.desktop.message.addMessage(msg);
  1994. },
  1995. addResetMessage: function(data){
  1996. var users = [];
  1997. data.taskList.each(function(task){
  1998. users.push(MWF.name.cn(task.person)+"("+MWF.name.cn(task.unit)+")");
  1999. }.bind(this));
  2000. var content = "<div><b>"+MWF.xApplication.process.Xform.LP.currentActivity+"<font style=\"color: #ea621f\">"+data.work.activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  2001. var msg = {
  2002. "subject": MWF.xApplication.process.Xform.LP.workReset,
  2003. "content": "<div>"+MWF.xApplication.process.Xform.LP.resetWorkInfor+"“"+this.businessData.work.title+"”</div>"+content
  2004. };
  2005. layout.desktop.message.addTooltip(msg);
  2006. return layout.desktop.message.addMessage(msg);
  2007. },
  2008. retractWork: function(e, ev){
  2009. var _self = this;
  2010. if (this.json.mode=="Mobile"){
  2011. if (window.confirm(MWF.xApplication.process.Xform.LP.retractText)){
  2012. _self.app.content.mask({
  2013. "style": {
  2014. "background-color": "#999",
  2015. "opacity": 0.6
  2016. }
  2017. });
  2018. MWF.require("MWF.widget.Mask", function(){
  2019. _self.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  2020. _self.mask.loadNode(_self.app.content);
  2021. _self.fireEvent("beforeRetract");
  2022. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("beforeRetract");
  2023. _self.doRetractWork(function(){
  2024. //_self.workAction.getJobByWork(function(workJson){
  2025. _self.fireEvent("afterRetract");
  2026. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("afterRetract");
  2027. _self.app.notice(MWF.xApplication.process.Xform.LP.workRetract, "success");
  2028. _self.app.content.unmask();
  2029. _self.app.reload();
  2030. //}, null, _self.businessData.work.id);
  2031. // var uri = new URI(window.location.href);
  2032. // var redirectlink = uri.getData("redirectlink");
  2033. // if( redirectlink ){
  2034. // window.location = decodeURIComponent(redirectlink);
  2035. // }else{
  2036. // window.location = "appMobile.html?app=process.TaskCenter";
  2037. // }
  2038. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2039. }.bind(this), function(xhr, text, error){
  2040. _self.app.content.unmask();
  2041. var errorText = error+":"+text;
  2042. if (xhr) errorText = xhr.responseText;
  2043. _self.app.notice("request json error: "+errorText, "error");
  2044. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2045. });
  2046. }.bind(this));
  2047. }
  2048. }else{
  2049. var p = MWF.getCenterPosition(this.app.content, 300, 150);
  2050. var event = {
  2051. "event":{
  2052. "x": p.x,
  2053. "y": p.y-200,
  2054. "clientX": p.x,
  2055. "clientY": p.y-200
  2056. }
  2057. };
  2058. this.app.confirm("infor", event, MWF.xApplication.process.Xform.LP.retractTitle, MWF.xApplication.process.Xform.LP.retractText, 300, 120, function(){
  2059. _self.app.content.mask({
  2060. "style": {
  2061. "background-color": "#999",
  2062. "opacity": 0.6
  2063. }
  2064. });
  2065. MWF.require("MWF.widget.Mask", function(){
  2066. _self.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  2067. _self.mask.loadNode(_self.app.content);
  2068. _self.fireEvent("beforeRetract");
  2069. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("beforeRetract");
  2070. _self.doRetractWork(function(){
  2071. //_self.workAction.getJobByWork(function(workJson){
  2072. _self.fireEvent("afterRetract");
  2073. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("afterRetract");
  2074. _self.app.notice(MWF.xApplication.process.Xform.LP.workRetract, "success");
  2075. _self.app.content.unmask();
  2076. _self.app.reload();
  2077. //}, null, _self.businessData.work.id);
  2078. this.close();
  2079. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2080. }.bind(this), function(xhr, text, error){
  2081. _self.app.content.unmask();
  2082. var errorText = error+":"+text;
  2083. if (xhr) errorText = xhr.responseText;
  2084. _self.app.notice("request json error: "+errorText, "error");
  2085. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2086. });
  2087. }.bind(this));
  2088. //this.close();
  2089. }, function(){
  2090. this.close();
  2091. },null, null, this.json.confirmStyle);
  2092. }
  2093. },
  2094. doRetractWork: function(success, failure){
  2095. if (this.businessData.control["allowRetract"]){
  2096. this.workAction.retractWork(function(json){
  2097. if (success) success();
  2098. }.bind(this), function(xhr, text, error){
  2099. if (failure) failure(xhr, text, error);
  2100. }, this.businessData.work.id);
  2101. }else{
  2102. if (failure) failure(null, "Permission Denied", "");
  2103. }
  2104. },
  2105. addRetractMessage: function(data){
  2106. var users = [];
  2107. data.taskList.each(function(task){
  2108. users.push(MWF.name.cn(task.person)+"("+MWF.name.cn(task.unit)+")");
  2109. }.bind(this));
  2110. var content = "<div><b>"+MWF.xApplication.process.Xform.LP.currentActivity+"<font style=\"color: #ea621f\">"+data.work.activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  2111. var msg = {
  2112. "subject": MWF.xApplication.process.Xform.LP.workRetract,
  2113. "content": "<div>"+MWF.xApplication.process.Xform.LP.retractWorkInfor+"“"+this.businessData.work.title+"”</div>"+content
  2114. };
  2115. layout.desktop.message.addTooltip(msg);
  2116. return layout.desktop.message.addMessage(msg);
  2117. },
  2118. rerouteWork: function(e, ev){
  2119. if (!this.businessData.control["allowReroute"]){
  2120. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "Permission Denied");
  2121. return false;
  2122. }
  2123. MWF.require("MWF.xDesktop.Dialog", function(){
  2124. var width = 480;
  2125. var height = 200;
  2126. var p = MWF.getCenterPosition(this.app.content, width, height);
  2127. var _self = this;
  2128. var dlg = new MWF.xDesktop.Dialog({
  2129. "title": this.app.lp.reroute,
  2130. "style": this.json.dialogStyle || "user", //|| "work",
  2131. "top": p.y-100,
  2132. "left": p.x,
  2133. "fromTop": p.y-100,
  2134. "fromLeft": p.x,
  2135. "width": width,
  2136. "height": height,
  2137. "url": this.app.path+"reroute.html",
  2138. "container": this.app.content,
  2139. "isClose": true,
  2140. "buttonList": [
  2141. {
  2142. "type" : "ok",
  2143. "text": MWF.LP.process.button.ok,
  2144. "action": function(d, e){
  2145. _self.doRerouteWork(dlg);
  2146. }.bind(this)
  2147. },
  2148. {
  2149. "type" : "cancel",
  2150. "text": MWF.LP.process.button.cancel,
  2151. "action": function(){dlg.close();}
  2152. }
  2153. ],
  2154. "onPostShow": function(){
  2155. //$("rerouteWork_okButton").addEvent("click", function(){
  2156. // _self.doRerouteWork(this);
  2157. //}.bind(this));
  2158. //$("rerouteWork_cancelButton").addEvent("click", function(){
  2159. // this.close();
  2160. //}.bind(this));
  2161. var select = $("rerouteWork_selectActivity");
  2162. _self.workAction.getRerouteTo(_self.businessData.work.process, function(json){
  2163. json.data.agentList.each(function(activity){
  2164. new Element("option", {
  2165. "value": activity.id+"#agent",
  2166. "text": activity.name
  2167. }).inject(select);
  2168. }.bind(_self));
  2169. json.data.cancelList.each(function(activity){
  2170. new Element("option", {
  2171. "value": activity.id+"#cancel",
  2172. "text": activity.name
  2173. }).inject(select);
  2174. }.bind(_self));
  2175. json.data.choiceList.each(function(activity){
  2176. new Element("option", {
  2177. "value": activity.id+"#choice",
  2178. "text": activity.name
  2179. }).inject(select);
  2180. }.bind(_self));
  2181. // json.data.controllerList.each(function(activity){
  2182. // new Element("option", {
  2183. // "value": activity.id+"#condition",
  2184. // "text": activity.name
  2185. // }).inject(select);
  2186. // }.bind(_self));
  2187. json.data.delayList.each(function(activity){
  2188. new Element("option", {
  2189. "value": activity.id+"#delay",
  2190. "text": activity.name
  2191. }).inject(select);
  2192. }.bind(_self));
  2193. json.data.embedList.each(function(activity){
  2194. new Element("option", {
  2195. "value": activity.id+"#embed",
  2196. "text": activity.name
  2197. }).inject(select);
  2198. }.bind(_self));
  2199. json.data.endList.each(function(activity){
  2200. new Element("option", {
  2201. "value": activity.id+"#end",
  2202. "text": activity.name
  2203. }).inject(select);
  2204. }.bind(_self));
  2205. json.data.invokeList.each(function(activity){
  2206. new Element("option", {
  2207. "value": activity.id+"#invoke",
  2208. "text": activity.name
  2209. }).inject(select);
  2210. }.bind(_self));
  2211. json.data.manualList.each(function(activity){
  2212. new Element("option", {
  2213. "value": activity.id+"#manual",
  2214. "text": activity.name
  2215. }).inject(select);
  2216. }.bind(_self));
  2217. json.data.mergeList.each(function(activity){
  2218. new Element("option", {
  2219. "value": activity.id+"#merge",
  2220. "text": activity.name
  2221. }).inject(select);
  2222. }.bind(_self));
  2223. json.data.messageList.each(function(activity){
  2224. new Element("option", {
  2225. "value": activity.id+"#message",
  2226. "text": activity.name
  2227. }).inject(select);
  2228. }.bind(_self));
  2229. json.data.parallelList.each(function(activity){
  2230. new Element("option", {
  2231. "value": activity.id+"#parallel",
  2232. "text": activity.name
  2233. }).inject(select);
  2234. }.bind(_self));
  2235. json.data.serviceList.each(function(activity){
  2236. new Element("option", {
  2237. "value": activity.id+"#service",
  2238. "text": activity.name
  2239. }).inject(select);
  2240. }.bind(_self));
  2241. json.data.splitList.each(function(activity){
  2242. new Element("option", {
  2243. "value": activity.id+"#split",
  2244. "text": activity.name
  2245. }).inject(select);
  2246. }.bind(_self));
  2247. }.bind(_self));
  2248. }
  2249. });
  2250. dlg.show();
  2251. }.bind(this));
  2252. },
  2253. doRerouteWork: function(dlg){
  2254. var opinion = $("rerouteWork_opinion").get("value");
  2255. var select = $("rerouteWork_selectActivity");
  2256. var activity = select.options[select.selectedIndex].get("value");
  2257. var activityName = select.options[select.selectedIndex].get("text");
  2258. var tmp = activity.split("#");
  2259. activity = tmp[0];
  2260. var type = tmp[1];
  2261. MWF.require("MWF.widget.Mask", function(){
  2262. this.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  2263. this.mask.loadNode(this.app.content);
  2264. this.fireEvent("beforeReroute");
  2265. if (this.app && this.app.fireEvent) this.app.fireEvent("afterRetract");
  2266. this.rerouteWorkToActivity(activity, type, opinion, function(){
  2267. this.workAction.loadWork(function(workJson){
  2268. this.fireEvent("afterReroute");
  2269. if (this.app && this.app.fireEvent) this.app.fireEvent("afterReroute");
  2270. this.addRerouteMessage(workJson.data);
  2271. this.app.notice(MWF.xApplication.process.Xform.LP.rerouteOk+": "+activityName, "success");
  2272. this.app.close();
  2273. }.bind(this), null, this.businessData.work.id);
  2274. dlg.close();
  2275. if (this.mask) {this.mask.hide(); this.mask = null;}
  2276. }.bind(this), function(xhr, text, error){
  2277. var errorText = error+":"+text;
  2278. if (xhr) errorText = xhr.responseText;
  2279. this.app.notice("request json error: "+errorText, "error", dlg.node);
  2280. if (this.mask) {this.mask.hide(); this.mask = null;}
  2281. }.bind(this));
  2282. }.bind(this));
  2283. },
  2284. rerouteWorkToActivity: function(activity, type, opinion, success, failure){
  2285. if (this.businessData.task){
  2286. this.saveFormData(function(json){
  2287. this.workAction.rerouteWork(function(json){
  2288. if (success) success();
  2289. }.bind(this), function(xhr, text, error){
  2290. if (failure) failure(xhr, text, error);
  2291. }, this.businessData.work.id, activity, type);
  2292. }.bind(this), function(xhr, text, error){
  2293. if (failure) failure(xhr, text, error);
  2294. }, true, null, true);
  2295. }else{
  2296. this.workAction.rerouteWork(function(json){
  2297. if (success) success();
  2298. }.bind(this), function(xhr, text, error){
  2299. if (failure) failure(xhr, text, error);
  2300. }, this.businessData.work.id, activity, type);
  2301. }
  2302. },
  2303. addRerouteMessage: function(data){
  2304. var users = [];
  2305. data.taskList.each(function(task){
  2306. users.push(MWF.name.cn(task.person)+"("+MWF.name.cn(task.unit)+")");
  2307. }.bind(this));
  2308. var content = "<div><b>"+MWF.xApplication.process.Xform.LP.currentActivity+"<font style=\"color: #ea621f\">"+data.work.activityName+"</font>, "+MWF.xApplication.process.Xform.LP.nextUser+"<font style=\"color: #ea621f\">"+users.join(", ")+"</font></b></div>";
  2309. var msg = {
  2310. "subject": MWF.xApplication.process.Xform.LP.workReroute,
  2311. "content": "<div>"+MWF.xApplication.process.Xform.LP.rerouteWorkInfor+"“"+this.businessData.work.title+"”</div>"+content
  2312. };
  2313. layout.desktop.message.addTooltip(msg);
  2314. return layout.desktop.message.addMessage(msg);
  2315. },
  2316. deleteWork: function(){
  2317. var _self = this;
  2318. if (this.json.mode === "Mobile"){
  2319. if (window.confirm(MWF.xApplication.process.Xform.LP.deleteWorkText.text)){
  2320. MWF.require("MWF.widget.Mask", function(){
  2321. _self.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  2322. _self.mask.loadNode(_self.app.content);
  2323. _self.fireEvent("beforeDelete");
  2324. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("beforeDelete");
  2325. _self.doDeleteWork(function(){
  2326. _self.fireEvent("afterDelete");
  2327. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("afterDelete");
  2328. _self.app.notice(MWF.xApplication.process.Xform.LP.workDelete+": “"+_self.businessData.work.title+"”", "success");
  2329. _self.app.close();
  2330. //if (layout.mobile){
  2331. var uri = new URI(window.location.href);
  2332. var redirectlink = uri.getData("redirectlink");
  2333. if( redirectlink ){
  2334. window.location = decodeURIComponent(redirectlink);
  2335. }else{
  2336. window.location = "appMobile.html?app=process.TaskCenter";
  2337. }
  2338. //}
  2339. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2340. }.bind(this),function(xhr, text, error){
  2341. var errorText = error+":"+text;
  2342. if (xhr) errorText = xhr.responseText;
  2343. _self.app.notice("request json error: "+errorText, "error", dlg.node);
  2344. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2345. }.bind(this));
  2346. }.bind(this));
  2347. }
  2348. }else{
  2349. var p = MWF.getCenterPosition(this.app.content, 380, 150);
  2350. var event = {
  2351. "event":{
  2352. "x": p.x,
  2353. "y": p.y-200,
  2354. "clientX": p.x,
  2355. "clientY": p.y-200
  2356. }
  2357. };
  2358. this.app.confirm("infor", event, MWF.xApplication.process.Xform.LP.deleteWorkTitle, MWF.xApplication.process.Xform.LP.deleteWorkText, 380, 120, function(){
  2359. // _self.app.content.mask({
  2360. // "style": {
  2361. // "background-color": "#999",
  2362. // "opacity": 0.6
  2363. // }
  2364. // });
  2365. MWF.require("MWF.widget.Mask", function(){
  2366. _self.mask = new MWF.widget.Mask({"style": "desktop", "zIndex": 50000});
  2367. _self.mask.loadNode(_self.app.content);
  2368. _self.fireEvent("beforeDelete");
  2369. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("beforeDelete");
  2370. _self.doDeleteWork(function(){
  2371. _self.fireEvent("s");
  2372. if (_self.app && _self.app.fireEvent) _self.app.fireEvent("afterDelete");
  2373. _self.app.notice(MWF.xApplication.process.Xform.LP.workDelete+": “"+_self.businessData.work.title+"”", "success");
  2374. _self.app.close();
  2375. this.close();
  2376. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2377. }.bind(this),function(xhr, text, error){
  2378. var errorText = error+":"+text;
  2379. if (xhr) errorText = xhr.responseText;
  2380. _self.app.notice("request json error: "+errorText, "error", dlg.node);
  2381. if (_self.mask) {_self.mask.hide(); _self.mask = null;}
  2382. }.bind(this));
  2383. }.bind(this));
  2384. //_self.workAction.deleteWork(function(json){
  2385. // _self.app.notice(MWF.xApplication.process.Xform.LP.workDelete+": “"+_self.businessData.work.title+"”", "success");
  2386. // _self.app.close();
  2387. // this.close();
  2388. //}.bind(this), null, _self.businessData.work.id);
  2389. //this.close();
  2390. }, function(){
  2391. this.close();
  2392. }, null, this.app.content, this.json.confirmStyle);
  2393. }
  2394. },
  2395. doDeleteWork: function(success, failure){
  2396. if (this.businessData.control["allowDelete"]){
  2397. this.workAction.deleteWork(function(json){
  2398. if (success) success(json);
  2399. }.bind(this), function(xhr, text, error){
  2400. if (failure) failure(xhr, text, error);
  2401. }, this.businessData.work.id);
  2402. }else{
  2403. if (failure) failure(null, "Permission Denied", "");
  2404. }
  2405. },
  2406. //printWork: function(){
  2407. // var form = this.json.id;
  2408. // if (this.json.printForm){
  2409. // form = this.json.printForm;
  2410. // }
  2411. // window.open("/x_desktop/printWork.html?workid="+this.businessData.work.id+"&app="+this.businessData.work.application+"&form="+form);
  2412. //},
  2413. printWork: function(app, form){
  2414. var application = app || (this.businessData.work) ? this.businessData.work.application : this.businessData.workCompleted.application;
  2415. var form = form;
  2416. if (!form){
  2417. form = this.json.id;
  2418. if (this.json.printForm) form = this.json.printForm;
  2419. }
  2420. if (this.businessData.workCompleted){
  2421. var application = app || this.businessData.workCompleted.application;
  2422. window.open("/x_desktop/printWork.html?workCompletedId="+this.businessData.workCompleted.id+"&app="+application+"&form="+form);
  2423. }else{
  2424. var application = app || this.businessData.work.application;
  2425. window.open("/x_desktop/printWork.html?workid="+this.businessData.work.id+"&app="+application+"&form="+form);
  2426. }
  2427. },
  2428. readedWork: function(e){
  2429. var _self = this;
  2430. var text = "您确定要将“"+this.businessData.work.title+"”标记为已阅吗?"
  2431. this.app.confirm("infor", e, "标记已阅确认", text, 350, 150, function(){
  2432. var read = null;
  2433. for (var i=0; i<_self.businessData.readList.length; i++){
  2434. if (_self.businessData.readList[i].person === layout.session.user.distinguishedName){
  2435. read = _self.businessData.readList[i];
  2436. break;
  2437. }
  2438. }
  2439. if (read){
  2440. _self.app.action.setReaded(function(){
  2441. _self.app.reload();
  2442. }.bind(_self), null, read.id, read);
  2443. }else{
  2444. _self.app.reload();
  2445. }
  2446. this.close();
  2447. }, function(){
  2448. this.close();
  2449. }, null, this.app.content, this.json.confirmStyle);
  2450. },
  2451. openWindow: function(form, app){
  2452. //var application = app || (this.businessData.work) ? this.businessData.work.application : this.businessData.workCompleted.application;
  2453. var form = form;
  2454. if (!form){
  2455. form = this.json.id;
  2456. //if (this.json.printForm) form = this.json.printForm;
  2457. }
  2458. if (this.businessData.workCompleted){
  2459. var application = app || this.businessData.workCompleted.application;
  2460. window.open("/x_desktop/printWork.html?workCompletedId="+this.businessData.workCompleted.id+"&app="+application+"&form="+form);
  2461. }else{
  2462. var application = app || this.businessData.work.application;
  2463. window.open("/x_desktop/printWork.html?workid="+this.businessData.work.id+"&app="+application+"&form="+form);
  2464. }
  2465. //window.open("/x_desktop/printWork.html?workid="+this.businessData.work.id+"&app="+this.businessData.work.application+"&form="+form);
  2466. },
  2467. uploadedAttachment: function(site, id){
  2468. this.workAction.getAttachment(id, this.businessData.work.id, function(json){
  2469. var att = this.all[site];
  2470. if (att){
  2471. if (json.data) att.attachmentController.addAttachment(json.data);
  2472. att.attachmentController.checkActions();
  2473. att.fireEvent("upload", [json.data]);
  2474. }
  2475. }.bind(this));
  2476. },
  2477. replacedAttachment: function(site, id){
  2478. this.workAction.getAttachment(id, this.businessData.work.id, function(json){
  2479. var att = this.all[site];
  2480. if (att){
  2481. var attachmentController = att.attachmentController;
  2482. var attachment = null;
  2483. for (var i=0; i<attachmentController.attachments.length; i++){
  2484. if (attachmentController.attachments[i].data.id===id){
  2485. attachment = attachmentController.attachments[i];
  2486. break;
  2487. }
  2488. }
  2489. attachment.data = json.data;
  2490. attachment.reload();
  2491. attachmentController.checkActions();
  2492. }
  2493. }.bind(this))
  2494. }
  2495. });