Attachment.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.require("MWF.widget.AttachmentController", null, false);
  3. MWF.xApplication.process.Xform.AttachmentController = new Class({
  4. Extends: MWF.widget.ATTER,
  5. "options": {
  6. "officeFiles": ["doc","docx","dotx","dot","xls","xlsx","xlsm","xlt","xltx","pptx","ppt","pot","potx","potm","pdf"],
  7. },
  8. checkDeleteAction: function(){
  9. if (this.options.readonly){
  10. this.setActionDisabled(this.deleteAction);
  11. this.setActionDisabled(this.min_deleteAction);
  12. return false;
  13. }
  14. if (this.options.isDeleteOption!=="y" && this.options.isDeleteOption!=="n"){
  15. if (this.selectedAttachments.length){
  16. var flag = true;
  17. if (this.options.isDeleteOption==="o"){
  18. for (var i=0; i<this.selectedAttachments.length; i++){
  19. if (this.selectedAttachments[i].data.person!==layout.desktop.session.user.distinguishedName){
  20. flag = false;
  21. break;
  22. }
  23. }
  24. }else if (this.options.isDeleteOption==="a"){
  25. for (var i=0; i<this.selectedAttachments.length; i++){
  26. if (this.selectedAttachments[i].data.activity!==this.module.form.businessData.activity.id){
  27. flag = false;
  28. break;
  29. }
  30. }
  31. }else if (this.options.isDeleteOption==="ao"){
  32. for (var i=0; i<this.selectedAttachments.length; i++){
  33. if ((this.selectedAttachments[i].data.activity!==this.module.form.businessData.activity.id) || (this.selectedAttachments[i].data.person!==layout.desktop.session.user.distinguishedName)){
  34. flag = false;
  35. break;
  36. }
  37. }
  38. }
  39. if (flag){
  40. this.setActionEnabled(this.deleteAction);
  41. this.setActionEnabled(this.min_deleteAction);
  42. }else{
  43. this.setActionDisabled(this.deleteAction);
  44. this.setActionDisabled(this.min_deleteAction);
  45. }
  46. }else{
  47. this.setActionDisabled(this.deleteAction);
  48. this.setActionDisabled(this.min_deleteAction);
  49. }
  50. }else{
  51. if (!this.options.isDelete){
  52. this.setActionDisabled(this.deleteAction);
  53. this.setActionDisabled(this.min_deleteAction);
  54. }else{
  55. if (this.selectedAttachments.length){
  56. this.setActionEnabled(this.deleteAction);
  57. this.setActionEnabled(this.min_deleteAction);
  58. }else{
  59. this.setActionDisabled(this.deleteAction);
  60. this.setActionDisabled(this.min_deleteAction);
  61. }
  62. }
  63. }
  64. },
  65. openInOfficeControl: function(att, office){
  66. if (office){
  67. if (!office.openedAttachment || office.openedAttachment.id!==att.id){
  68. office.save();
  69. if (this.module.form.businessData.workCompleted){
  70. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompletedUrl(att.id, this.module.form.businessData.workCompleted.id, function(url){
  71. office.openedAttachment = {"id": att.id, "site": this.module.json.name, "name": att.name};
  72. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  73. }.bind(this));
  74. }else{
  75. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.id, this.module.form.businessData.work.id, function(url){
  76. office.openedAttachment = {"id": att.id, "site": this.module.json.name, "name": att.name};
  77. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  78. }.bind(this));
  79. }
  80. }
  81. }
  82. },
  83. checkReplaceAction: function(){
  84. if (this.options.readonly){
  85. this.setActionDisabled(this.replaceAction);
  86. this.setActionDisabled(this.min_replaceAction);
  87. return false;
  88. }
  89. if (this.options.isReplaceOption!=="y" && this.options.isReplaceOption!=="n") {
  90. if (this.selectedAttachments.length && this.selectedAttachments.length===1){
  91. var flag;
  92. if (this.options.isReplaceOption==="o"){
  93. flag = this.selectedAttachments[0].data.person === layout.desktop.session.user.distinguishedName;
  94. }
  95. if (this.options.isReplaceOption==="a"){
  96. flag = this.selectedAttachments[0].data.activity===this.module.form.businessData.activity.id;
  97. }
  98. if (this.options.isReplaceOption==="ao"){
  99. flag = (this.selectedAttachments[0].data.person === layout.desktop.session.user.distinguishedName && this.selectedAttachments[0].data.activity===this.module.form.businessData.activity.id);
  100. }
  101. if (!this.selectedAttachments[0].data.control.allowEdit) flag = false;
  102. if (flag) {
  103. this.setActionEnabled(this.replaceAction);
  104. this.setActionEnabled(this.min_replaceAction);
  105. }else{
  106. this.setActionDisabled(this.replaceAction);
  107. this.setActionDisabled(this.min_replaceAction);
  108. }
  109. } else {
  110. this.setActionDisabled(this.replaceAction);
  111. this.setActionDisabled(this.min_replaceAction);
  112. }
  113. }else{
  114. if (!this.options.isReplace){
  115. this.setActionDisabled(this.replaceAction);
  116. this.setActionDisabled(this.min_replaceAction);
  117. }else{
  118. if (this.selectedAttachments.length && this.selectedAttachments.length===1){
  119. this.setActionEnabled(this.replaceAction);
  120. this.setActionEnabled(this.min_replaceAction);
  121. }else{
  122. this.setActionDisabled(this.replaceAction);
  123. this.setActionDisabled(this.min_replaceAction);
  124. }
  125. }
  126. }
  127. },
  128. replaceAttachment: function(e, node){
  129. var att = this.selectedAttachments[0].data;
  130. if (this.module.json.isOpenInOffice && this.module.json.officeControlName && (this.options.officeFiles.indexOf(att.extension)!==-1)){
  131. var office = this.module.form.all[this.module.json.officeControlName];
  132. if (office){
  133. if (this.min_closeOfficeAction) this.setActionEnabled(this.min_closeOfficeAction);
  134. if (this.closeOfficeAction) this.setActionEnabled(this.closeOfficeAction);
  135. this.openInOfficeControl(att, office);
  136. }else{
  137. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  138. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  139. }
  140. }
  141. }else{
  142. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  143. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  144. }
  145. }
  146. },
  147. createTopNode: function(){
  148. if (this.options.title){
  149. if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
  150. }
  151. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  152. this.createEditGroupActions();
  153. this.createReadGroupActions();
  154. this.createListGroupActions();
  155. if (this.module.json.isOpenInOffice && this.module.json.officeControlName) this.createOfficeGroupActions();
  156. this.createConfigGroupActions();
  157. this.createViewGroupActions();
  158. },
  159. checkActions: function(){
  160. // if (this.options.readonly){
  161. // this.setReadonly();
  162. // }else{
  163. this.checkUploadAction();
  164. this.checkDeleteAction();
  165. this.checkReplaceAction();
  166. //this.checkOfficeAction();
  167. this.checkDownloadAction();
  168. this.checkSizeAction();
  169. this.checkConfigAction();
  170. this.checkListStyleAction();
  171. // }
  172. },
  173. checkConfigAction: function(){
  174. if (this.options.readonly){
  175. this.setActionDisabled(this.configAction);
  176. this.setActionDisabled(this.checkTextAction);
  177. return false;
  178. }
  179. if (this.selectedAttachments.length){
  180. var flag = true;
  181. for (var i=0; i<this.selectedAttachments.length; i++){
  182. if (!this.selectedAttachments[i].data.control.allowControl){
  183. flag = false;
  184. break;
  185. }
  186. }
  187. if (flag){
  188. this.setActionEnabled(this.configAction);
  189. }else{
  190. this.setActionDisabled(this.configAction);
  191. }
  192. //this.setActionEnabled(this.min_deleteAction);
  193. }else{
  194. this.setActionDisabled(this.configAction);
  195. //this.setActionDisabled(this.min_deleteAction);
  196. }
  197. this.setActionDisabled(this.checkTextAction);
  198. if (this.selectedAttachments.length && this.selectedAttachments.length===1){
  199. var att = this.selectedAttachments[0];
  200. if (this.options.images.indexOf(att.data.extension.toLowerCase())!==-1){
  201. this.setActionEnabled(this.checkTextAction);
  202. }
  203. }
  204. },
  205. createConfigGroupActions: function(){
  206. this.configActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  207. this.configActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.configActionBoxNode);
  208. this.configAction = this.createAction(this.configActionsGroupNode, "config", MWF.LP.widget.configAttachment, function(e, node){
  209. this.configAttachment(e, node);
  210. }.bind(this));
  211. this.createSeparate(this.configActionsGroupNode);
  212. this.checkTextAction = this.createAction(this.configActionsGroupNode, "check", MWF.LP.widget.checkOcrText, function(e, node){
  213. this.checkImageTex(e, node);
  214. }.bind(this));
  215. if (this.configAction) this.setActionDisabled(this.configAction);
  216. if (this.checkTextAction) this.setActionDisabled(this.checkTextAction);
  217. },
  218. createOfficeGroupActions: function(){
  219. this.officeActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  220. this.officeActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.officeActionBoxNode);
  221. this.closeOfficeAction = this.createAction(this.officeActionsGroupNode, "closeOffice", MWF.LP.widget.closeOffice, function(e, node){
  222. this.closeAttachmentOffice(e, node);
  223. }.bind(this));
  224. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  225. },
  226. loadMinActions: function(){
  227. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", MWF.LP.widget.upload, function(e, node){
  228. this.uploadAttachment(e, node);
  229. }.bind(this));
  230. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", MWF.LP.widget["delete"], function(e, node){
  231. this.deleteAttachment(e, node);
  232. }.bind(this));
  233. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", MWF.LP.widget.replace, function(e, node){
  234. this.replaceAttachment(e, node);
  235. }.bind(this));
  236. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download, function(e, node){
  237. this.downloadAttachment(e, node);
  238. }.bind(this));
  239. if (this.module.json.isOpenInOffice && this.module.json.officeControlName){
  240. this.min_closeOfficeAction = this.createAction(this.minActionAreaNode, "closeOffice", MWF.LP.widget.closeOffice, function(e, node){
  241. this.closeAttachmentOffice(e, node);
  242. }.bind(this));
  243. if (this.min_closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  244. }
  245. this.createSeparate(this.minActionAreaNode);
  246. this.sizeAction = this.createAction(this.minActionAreaNode, "max", MWF.LP.widget.min, function(){
  247. this.changeControllerSize();
  248. }.bind(this));
  249. },
  250. closeAttachmentOffice: function(){
  251. var office = this.module.form.all[this.module.json.officeControlName];
  252. if (office){
  253. office.openFile();
  254. if (this.min_closeOfficeAction) this.setActionDisabled(this.min_closeOfficeAction);
  255. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  256. }
  257. },
  258. configAttachment: function(){
  259. var lp = MWF.xApplication.process.Xform.LP;
  260. var css = this.module.form.css;
  261. var node = new Element("div", {"styles": css.attachmentPermissionNode}).inject(this.node);
  262. var attNames = new Element("div", {"styles": css.attachmentPermissionNamesNode}).inject(node);
  263. var attNamesTitle = new Element("div", {"styles": css.attachmentPermissionNamesTitleNode, "text": lp.attachmentPermissionInfo}).inject(attNames);
  264. var attNamesArea = new Element("div", {"styles": css.attachmentPermissionNamesAreaNode}).inject(attNames);
  265. if (this.selectedAttachments.length){
  266. this.selectedAttachments.each(function(att){
  267. var attNode = new Element("div", {"styles": css.attachmentPermissionAttNode, "text": att.data.name}).inject(attNamesArea);
  268. }.bind(this));
  269. }
  270. var editArea = new Element("div", {"styles": css.attachmentPermissionEditAreaNode}).inject(node);
  271. var title = new Element("div", {"styles": css.attachmentPermissionTitleNode, "text": lp.attachmentRead}).inject(editArea);
  272. var readInput = new Element("div", {"styles": css.attachmentPermissionInputNode}).inject(editArea);
  273. title = new Element("div", {"styles": css.attachmentPermissionTitleNode, "text": lp.attachmentEdit}).inject(editArea);
  274. var editInput = new Element("div", {"styles": css.attachmentPermissionInputNode}).inject(editArea);
  275. title = new Element("div", {"styles": css.attachmentPermissionTitleNode, "text": lp.attachmentController}).inject(editArea);
  276. var controllerInput = new Element("div", {"styles": css.attachmentPermissionInputNode}).inject(editArea);
  277. var dlg = o2.DL.open({
  278. "title": lp.attachmentPermission,
  279. "isResize": false,
  280. "content": node,
  281. "buttonList": [
  282. {
  283. "text": MWF.LP.process.button.ok,
  284. "action": function(){
  285. this.setAttachmentConfig(readInput, editInput, controllerInput);
  286. dlg.close();
  287. }.bind(this)
  288. },
  289. {
  290. "text": MWF.LP.process.button.cancel,
  291. "action": function(){dlg.close();}
  292. }
  293. ]
  294. });
  295. if (this.selectedAttachments.length===1){
  296. var data = this.selectedAttachments[0].data;
  297. var readUnitList = (data.readUnitList) || [];
  298. var readIdentityList = (data.readIdentityList) || [];
  299. var editUnitList = (data.editUnitList) || [];
  300. var editIdentityList = (data.editIdentityList) || [];
  301. var controllerUnitList = (data.controllerUnitList) || [];
  302. var controllerIdentityList = (data.controllerIdentityList) || [];
  303. readInput.setSelectPerson(this.module.form.app.content, {
  304. "types": ["unit", "identity"],
  305. "values": readUnitList.concat(readIdentityList).trim()
  306. });
  307. editInput.setSelectPerson(this.module.form.app.content, {
  308. "types": ["unit", "identity"],
  309. "values": editUnitList.concat(editIdentityList).trim()
  310. });
  311. controllerInput.setSelectPerson(this.module.form.app.content, {
  312. "types": ["unit", "identity"],
  313. "values": controllerUnitList.concat(controllerIdentityList).trim()
  314. });
  315. }else{
  316. readInput.setSelectPerson(this.module.form.app.content, { "types": ["unit", "identity"] });
  317. editInput.setSelectPerson(this.module.form.app.content, { "types": ["unit", "identity"] });
  318. controllerInput.setSelectPerson(this.module.form.app.content, { "types": ["unit", "identity"] });
  319. }
  320. },
  321. setAttachmentConfig: function(readInput, editInput, controllerInput){
  322. if (this.selectedAttachments.length){
  323. var readList = readInput.retrieve("data-value");
  324. var editList = editInput.retrieve("data-value");
  325. var controllerList = controllerInput.retrieve("data-value");
  326. var readUnitList = [];
  327. var readIdentityList = [];
  328. var editUnitList = [];
  329. var editIdentityList = [];
  330. var controllerUnitList = [];
  331. var controllerIdentityList = [];
  332. if (readList){
  333. readList.each(function(v){
  334. var vName = (typeOf(v)==="string") ? v : v.distinguishedName;
  335. var len = vName.length;
  336. var flag = vName.substring(len-1,len);
  337. if (flag==="U") readUnitList.push(vName);
  338. if (flag==="I") readIdentityList.push(vName);
  339. });
  340. }
  341. if (editList){
  342. editList.each(function(v){
  343. var vName = (typeOf(v)==="string") ? v : v.distinguishedName;
  344. var len = vName.length;
  345. var flag = vName.substring(len-1,len);
  346. if (flag==="U") editUnitList.push(vName);
  347. if (flag==="I") editIdentityList.push(vName);
  348. });
  349. }
  350. if (controllerList){
  351. controllerList.each(function(v){
  352. var vName = (typeOf(v)==="string") ? v : v.distinguishedName;
  353. var len = vName.length;
  354. var flag = vName.substring(len-1,len);
  355. if (flag==="U") controllerUnitList.push(vName);
  356. if (flag==="I") controllerIdentityList.push(vName);
  357. });
  358. }
  359. this.selectedAttachments.each(function(att){
  360. att.data.readUnitList = readUnitList;
  361. att.data.readIdentityList = readIdentityList;
  362. att.data.editUnitList = editUnitList;
  363. att.data.editIdentityList = editIdentityList;
  364. att.data.controllerUnitList = controllerUnitList;
  365. att.data.controllerIdentityList = controllerIdentityList;
  366. o2.Actions.get("x_processplatform_assemble_surface").configAttachment(att.data.id, this.module.form.businessData.work.id, att.data);
  367. }.bind(this));
  368. }
  369. },
  370. checkImageTex: function(){
  371. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  372. var att = this.selectedAttachments[0];
  373. var lp = MWF.xApplication.process.Xform.LP;
  374. var css = this.module.form.css;
  375. var node = new Element("div", {"styles": css.attachmentOCRNode}).inject(this.node);
  376. var previewNode = new Element("div", {"styles": css.attachmentOCRImageAreaNode}).inject(node);
  377. var imgNode = new Element("img", {"styles": css.attachmentOCRImageNode}).inject(previewNode);
  378. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.data.id, this.module.form.businessData.work.id, function(url){
  379. imgNode.set("src", url);
  380. });
  381. var areaNode = new Element("div", {"styles": css.attachmentOCRInputAreaNode}).inject(node);
  382. var inputNode = new Element("textarea", {"styles": css.attachmentOCRInputNode}).inject(areaNode);
  383. var dlg = o2.DL.open({
  384. "title": lp.attachmentOCRTitle,
  385. "isResize": false,
  386. "content": node,
  387. "buttonList": [
  388. {
  389. "text": MWF.LP.process.button.ok,
  390. "action": function(){
  391. this.setAttachmentOCR(inputNode, att);
  392. dlg.close();
  393. }.bind(this)
  394. },
  395. {
  396. "text": MWF.LP.process.button.cancel,
  397. "action": function(){dlg.close();}
  398. }
  399. ]
  400. });
  401. if (att.data.ocr){
  402. inputNode.set("text", att.data.ocr.text || "");
  403. }else{
  404. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentOCR(att.data.id, this.module.form.businessData.work.id, function(json){
  405. att.data.ocr = json.data;
  406. inputNode.set("text", json.data.text || "");
  407. }.bind(this))
  408. }
  409. }
  410. },
  411. setAttachmentOCR: function(inputNode, att){
  412. var data = inputNode.get("text");
  413. if (!att.data.ocr) att.data.ocr = {};
  414. att.data.ocr.text = data;
  415. o2.Actions.get("x_processplatform_assemble_surface").setAttachmentOCR(att.data.id, this.module.form.businessData.work.id, {
  416. "text": data
  417. }, function(){
  418. this.module.form.app.notice("success", lp.attachmentOCR_saved, this.node);
  419. }.bind(this));
  420. }
  421. });
  422. MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class({
  423. Extends: MWF.APP$Module,
  424. options: {
  425. "moduleEvents": ["upload", "delete", "afterDelete", "load"]
  426. },
  427. initialize: function(node, json, form, options){
  428. this.node = $(node);
  429. this.node.store("module", this);
  430. this.json = json;
  431. this.form = form;
  432. this.field = true;
  433. },
  434. _loadUserInterface: function(){
  435. this.node.empty();
  436. this.loadAttachmentController();
  437. this.fireEvent("load");
  438. },
  439. loadAttachmentController: function(){
  440. //MWF.require("MWF.widget.AttachmentController", function() {
  441. var options = {
  442. "title": "附件区域",
  443. "listStyle": this.json.listStyle || "icon",
  444. "size": this.json.size || "max",
  445. "resize": (this.json.size==="true"),
  446. "attachmentCount": this.json.attachmentCount || 0,
  447. "isUpload": (this.json.isUpload==="y"),
  448. "isDelete": (this.json.isDelete==="y"),
  449. "isReplace": (this.json.isReplace==="y"),
  450. "isDownload": (this.json.isDownload==="y"),
  451. "isSizeChange": (this.json.isSizeChange==="y"),
  452. "readonly": (this.json.readonly==="y"),
  453. "isDeleteOption": this.json.isDelete,
  454. "isReplaceOption": this.json.isReplace
  455. };
  456. if (this.readonly) options.readonly = true;
  457. //this.attachmentController = new MWF.widget.ATTER(this.node, this, options);
  458. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  459. this.attachmentController.load();
  460. this.form.businessData.attachmentList.each(function (att) {
  461. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  462. if (att.site===this.json.id) this.attachmentController.addAttachment(att);
  463. }.bind(this));
  464. //}.bind(this));
  465. },
  466. _loadEvents: function(editorConfig){
  467. Object.each(this.json.events, function(e, key){
  468. if (e.code){
  469. if (this.options.moduleEvents.indexOf(key)!==-1){
  470. this.addEvent(key, function(event){
  471. return this.form.Macro.fire(e.code, this, event);
  472. }.bind(this));
  473. }else{
  474. this.node.addEvent(key, function(event){
  475. return this.form.Macro.fire(e.code, this, event);
  476. }.bind(this));
  477. }
  478. }
  479. }.bind(this));
  480. },
  481. getData: function(){
  482. return this.attachmentController.getAttachmentNames();
  483. },
  484. createUploadFileNode: function(){
  485. this.attachmentController.doUploadAttachment({"site": this.json.id}, this.form.workAction.action, "uploadAttachment", {"id": this.form.businessData.work.id}, null, function(o){
  486. if (o.id){
  487. this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function(json){
  488. if (json.data) this.attachmentController.addAttachment(json.data);
  489. this.attachmentController.checkActions();
  490. this.fireEvent("upload", [json.data]);
  491. }.bind(this))
  492. }
  493. this.attachmentController.checkActions();
  494. }.bind(this), function(files){
  495. if (files.length){
  496. if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  497. var content = MWF.xApplication.process.Xform.LP.uploadMore;
  498. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  499. this.form.notice(content, "error");
  500. return false;
  501. }
  502. }
  503. return true;
  504. }.bind(this));
  505. // this.uploadFileAreaNode = new Element("div");
  506. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  507. // this.uploadFileAreaNode.set("html", html);
  508. //
  509. // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  510. // this.fileUploadNode.addEvent("change", function(){
  511. //
  512. // var files = this.fileUploadNode.files;
  513. // if (files.length){
  514. // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  515. // var content = MWF.xApplication.process.Xform.LP.uploadMore;
  516. // content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  517. // this.form.notice(content, "error");
  518. // }else{
  519. // for (var i = 0; i < files.length; i++) {
  520. // var file = files.item(i);
  521. //
  522. // var formData = new FormData();
  523. // formData.append('site', this.json.id);
  524. // formData.append('file', file);
  525. //
  526. // //formData.append('folder', folderId);
  527. //
  528. // this.form.workAction.uploadAttachment(this.form.businessData.work.id ,function(o, text){
  529. // if (o.id){
  530. // this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function(json){
  531. // if (json.data) this.attachmentController.addAttachment(json.data);
  532. // this.attachmentController.checkActions();
  533. //
  534. // this.fireEvent("upload", [json.data]);
  535. // }.bind(this))
  536. // }
  537. // this.attachmentController.checkActions();
  538. // }.bind(this), null, formData, file);
  539. // }
  540. // }
  541. // }
  542. // }.bind(this));
  543. },
  544. uploadAttachment: function(e, node){
  545. if (window.o2android && window.o2android.uploadAttachment){
  546. window.o2android.uploadAttachment(this.json.id);
  547. }else if(window.webkit && window.webkit.messageHandlers) {
  548. window.webkit.messageHandlers.uploadAttachment.postMessage({"site": this.json.id});
  549. }else{
  550. // if (!this.uploadFileAreaNode){
  551. this.createUploadFileNode();
  552. // }
  553. // this.fileUploadNode.click();
  554. }
  555. },
  556. deleteAttachments: function(e, node, attachments){
  557. var names = [];
  558. attachments.each(function(attachment){
  559. names.push(attachment.data.name);
  560. }.bind(this));
  561. // if ((window.o2 && window.o2.replaceAttachment) || (window.webkit && window.webkit.messageHandlers)){
  562. // if (window.confirm(MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )")){
  563. // while (attachments.length){
  564. // attachment = attachments.shift();
  565. // this.deleteAttachment(attachment);
  566. // }
  567. // }
  568. // }else {
  569. // var tmpNode = new Element("div", {
  570. // "styles": {
  571. // "background-color": "#0000ff",
  572. // "border-style": "solid",
  573. // "border-color": "#fff",
  574. // "border-width": "1",
  575. // "box-shadow": "0px 0px 20px #999",
  576. // "z-index": "20000",
  577. // "overflow": "hidden",
  578. // "font-size": "14px",
  579. // "height": "160px",
  580. // "padding": "0px",
  581. // "width": "300px",
  582. // "position": "absolute",
  583. // "top": "50px",
  584. // "left": "20px",
  585. // "opacity": 1,
  586. // "border-radius": "5px"
  587. // }
  588. // }).inject(this.form.app.content);
  589. var _self = this;
  590. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.deleteAttachmentTitle, MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )", 300, 120, function(){
  591. while (attachments.length){
  592. var attachment = attachments.shift();
  593. _self.deleteAttachment(attachment);
  594. }
  595. this.close();
  596. }, function(){
  597. this.close();
  598. }, null);
  599. },
  600. deleteAttachment: function(attachment){
  601. this.fireEvent("delete", [attachment.data]);
  602. this.form.workAction.deleteAttachment(attachment.data.id, this.form.businessData.work.id, function(josn){
  603. this.attachmentController.removeAttachment(attachment);
  604. this.attachmentController.checkActions();
  605. this.fireEvent("afterDelete", [attachment.data]);
  606. }.bind(this));
  607. },
  608. replaceAttachment: function(e, node, attachment){
  609. if (window.o2android && window.o2android.replaceAttachment){
  610. window.o2android.replaceAttachment(attachment.data.id, this.json.id);
  611. }else if(window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
  612. window.webkit.messageHandlers.replaceAttachment.postMessage({"id": attachment.data.id, "site": this.json.id});
  613. }else {
  614. var _self = this;
  615. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment+"( "+attachment.data.name+" )", 350, 120, function(){
  616. _self.replaceAttachmentFile(attachment);
  617. this.close();
  618. }, function(){
  619. this.close();
  620. }, null);
  621. }
  622. },
  623. createReplaceFileNode: function(attachment){
  624. this.attachmentController.doUploadAttachment({"site": this.json.id}, this.form.workAction.action, "replaceAttachment",
  625. {"id": attachment.data.id, "workid": this.form.businessData.work.id}, null, function(o){
  626. this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
  627. attachment.data = json.data;
  628. attachment.reload();
  629. this.attachmentController.checkActions();
  630. }.bind(this))
  631. }.bind(this), null);
  632. // this.replaceFileAreaNode = new Element("div");
  633. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  634. // this.replaceFileAreaNode.set("html", html);
  635. //
  636. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  637. // this.fileReplaceNode.addEvent("change", function(){
  638. //
  639. // var files = this.fileReplaceNode.files;
  640. // if (files.length){
  641. // for (var i = 0; i < files.length; i++) {
  642. // var file = files.item(i);
  643. //
  644. // var formData = new FormData();
  645. // formData.append('file', file);
  646. // // formData.append('site', this.json.id);
  647. //
  648. // this.form.workAction.replaceAttachment(attachment.data.id, this.form.businessData.work.id ,function(o, text){
  649. // this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
  650. // attachment.data = json.data;
  651. // attachment.reload();
  652. // this.attachmentController.checkActions();
  653. // }.bind(this))
  654. // }.bind(this), null, formData, file);
  655. // }
  656. // }
  657. // }.bind(this));
  658. },
  659. replaceAttachmentFile: function(attachment){
  660. //if (!this.replaceFileAreaNode){
  661. this.createReplaceFileNode(attachment);
  662. // }
  663. // this.fileReplaceNode.click();
  664. },
  665. downloadAttachment: function(e, node, attachments){
  666. if (this.form.businessData.work){
  667. attachments.each(function(att){
  668. if (window.o2android && window.o2android.downloadAttachment){
  669. window.o2android.downloadAttachment(att.data.id);
  670. }else if(window.webkit && window.webkit.messageHandlers) {
  671. window.webkit.messageHandlers.downloadAttachment.postMessage({"id": att.data.id, "site": this.json.id});
  672. }else{
  673. this.form.workAction.getAttachmentStream(att.data.id, this.form.businessData.work.id);
  674. }
  675. }.bind(this));
  676. }else{
  677. attachments.each(function(att){
  678. if (window.o2android && window.o2android.downloadAttachment){
  679. window.o2android.downloadAttachment(att.data.id);
  680. }else if(window.webkit && window.webkit.messageHandlers) {
  681. window.webkit.messageHandlers.downloadAttachment.postMessage({"id": att.data.id, "site": this.json.id});
  682. }else{
  683. this.form.workAction.getWorkcompletedAttachmentStream(att.data.id, this.form.businessData.workCompleted.id);
  684. }
  685. }.bind(this));
  686. }
  687. },
  688. openAttachment: function(e, node, attachments){
  689. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  690. attachments.each(function(att){
  691. if (window.o2android && window.o2android.downloadAttachment){
  692. window.o2android.downloadAttachment(att.data.id);
  693. }else if(window.webkit && window.webkit.messageHandlers) {
  694. window.webkit.messageHandlers.downloadAttachment.postMessage({"id": att.data.id, "site": this.json.id});
  695. }else {
  696. this.form.workAction.getAttachmentData(att.data.id, this.form.businessData.work.id);
  697. }
  698. }.bind(this));
  699. }else{
  700. attachments.each(function(att){
  701. if (window.o2android && window.o2android.downloadAttachment){
  702. window.o2android.downloadAttachment(att.data.id);
  703. }else if(window.webkit && window.webkit.messageHandlers) {
  704. window.webkit.messageHandlers.downloadAttachment.postMessage(att.data.id, this.json.id);
  705. }else {
  706. this.form.workAction.getWorkcompletedAttachmentData(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  707. }
  708. }.bind(this));
  709. }
  710. //this.downloadAttachment(e, node, attachment);
  711. },
  712. getAttachmentUrl: function(attachment, callback){
  713. if (this.form.businessData.work){
  714. this.form.workAction.getAttachmentUrl(attachment.data.id, this.form.businessData.work.id, callback);
  715. }else{
  716. this.form.workAction.getAttachmentWorkcompletedUrl(attachment.data.id, this.form.businessData.workCompleted.id, callback);
  717. }
  718. },
  719. createErrorNode: function(text){
  720. var node = new Element("div");
  721. var iconNode = new Element("div", {
  722. "styles": {
  723. "width": "20px",
  724. "height": "20px",
  725. "float": "left",
  726. "background": "url("+"/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  727. }
  728. }).inject(node);
  729. var textNode = new Element("div", {
  730. "styles": {
  731. "line-height": "20px",
  732. "margin-left": "20px",
  733. "color": "red",
  734. "word-break": "keep-all"
  735. },
  736. "text": text
  737. }).inject(node);
  738. return node;
  739. },
  740. notValidationMode: function(text){
  741. if (!this.isNotValidationMode){
  742. this.isNotValidationMode = true;
  743. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  744. this.node.setStyle("border", "1px solid red");
  745. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  746. this.showNotValidationMode(this.node);
  747. }
  748. },
  749. showNotValidationMode: function(node){
  750. var p = node.getParent("div");
  751. if (p){
  752. if (p.get("MWFtype") == "tab$Content"){
  753. if (p.getParent("div").getStyle("display")=="none"){
  754. var contentAreaNode = p.getParent("div").getParent("div");
  755. var tabAreaNode = contentAreaNode.getPrevious("div");
  756. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  757. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  758. tabNode.click();
  759. p = tabAreaNode.getParent("div");
  760. }
  761. }
  762. this.showNotValidationMode(p);
  763. }
  764. },
  765. validationMode: function(){
  766. if (this.isNotValidationMode){
  767. this.isNotValidationMode = false;
  768. this.node.setStyles(this.node.retrieve("borderStyle"));
  769. if (this.errNode){
  770. this.errNode.destroy();
  771. this.errNode = null;
  772. }
  773. }
  774. },
  775. validationConfigItem: function(routeName, data){
  776. var flag = (data.status=="all") ? true: (routeName == data.decision);
  777. if (flag){
  778. var n = this.getData();
  779. var v = (data.valueType=="value") ? n : n.length;
  780. switch (data.operateor){
  781. case "isnull":
  782. if (!v){
  783. this.notValidationMode(data.prompt);
  784. return false;
  785. }
  786. break;
  787. case "notnull":
  788. if (v){
  789. this.notValidationMode(data.prompt);
  790. return false;
  791. }
  792. break;
  793. case "gt":
  794. if (v>data.value){
  795. this.notValidationMode(data.prompt);
  796. return false;
  797. }
  798. break;
  799. case "lt":
  800. if (v<data.value){
  801. this.notValidationMode(data.prompt);
  802. return false;
  803. }
  804. break;
  805. case "equal":
  806. if (v==data.value){
  807. this.notValidationMode(data.prompt);
  808. return false;
  809. }
  810. break;
  811. case "neq":
  812. if (v!=data.value){
  813. this.notValidationMode(data.prompt);
  814. return false;
  815. }
  816. break;
  817. case "contain":
  818. if (v.indexOf(data.value)!=-1){
  819. this.notValidationMode(data.prompt);
  820. return false;
  821. }
  822. break;
  823. case "notcontain":
  824. if (v.indexOf(data.value)==-1){
  825. this.notValidationMode(data.prompt);
  826. return false;
  827. }
  828. break;
  829. }
  830. }
  831. return true;
  832. },
  833. validationConfig: function(routeName, opinion){
  834. if (this.json.validationConfig){
  835. if (this.json.validationConfig.length){
  836. for (var i=0; i<this.json.validationConfig.length; i++) {
  837. var data = this.json.validationConfig[i];
  838. if (!this.validationConfigItem(routeName, data)) return false;
  839. }
  840. }
  841. return true;
  842. }
  843. return true;
  844. },
  845. validation: function(routeName, opinion){
  846. if (!this.validationConfig(routeName, opinion)) return false;
  847. if (!this.json.validation) return true;
  848. if (!this.json.validation.code) return true;
  849. var flag = this.form.Macro.exec(this.json.validation.code, this);
  850. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  851. if (flag.toString()!="true"){
  852. this.notValidationMode(flag);
  853. return false;
  854. }
  855. return true;
  856. }
  857. });