Main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.xApplication.cms.Document = MWF.xApplication.cms.Document || {};
  3. MWF.xApplication.cms.Document.options = MWF.xApplication.cms.Document.options || Object.clone(o2.xApplication.Common.options);
  4. MWF.xApplication.cms.Document.options.multitask = true;
  5. MWF.xApplication.cms.Document.Main = new Class({
  6. Extends: MWF.xApplication.Common.Main,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "name": "cms.Document",
  11. "icon": "icon.png",
  12. "width": "1200",
  13. "height": "680",
  14. "title": "",
  15. "documentId": "",
  16. "isControl": false,
  17. "readonly": true,
  18. "autoSave" : true,
  19. "saveOnClose" : null,
  20. "postPublish" : null,
  21. "postDelete" : null,
  22. "forceFormId" : null, //不管编辑还是阅读都用此表单打开,优先使用
  23. "printFormId" : null, //打印表单,不管编辑还是阅读都用此表单打开,仅此于forceFormId
  24. "readFormId" : null, //强制的阅读表单,优先于表单的readFormId
  25. "editFormId" : null, //强制的编辑表单,优先于表单的formId
  26. "useProcessForm": false //表单ID参数是流程的
  27. },
  28. onQueryLoad: function(){
  29. if (!this.options.title && !layout.mobile) this.setOptions({"title": MWF.xApplication.cms.Document.LP.title})
  30. this.lp = MWF.xApplication.cms.Document.LP;
  31. if (this.status){
  32. this.options.documentId = this.status.documentId;
  33. this.options.readonly = (this.status.readonly==="true" || this.status.readonly===true) ? true : false;
  34. this.options.autoSave = (this.status.autoSave==="true" || this.status.autoSave===true) ? true : false;
  35. this.options.saveOnClose = (this.status.saveOnClose==="true" || this.status.saveOnClose===true) ? true : false;
  36. this.options.formId = this.status.formId;
  37. this.options.formEditId = this.status.formEditId;
  38. this.options.printFormId = this.status.printFormId;
  39. this.options.forceFormId = this.status.forceFormId;
  40. this.options.readFormId = this.status.readFormId;
  41. this.options.editFormId = this.status.editFormId;
  42. this.options.useProcessForm = this.status.useProcessForm;
  43. }
  44. //兼容之前的 formEditId 和 formId
  45. if( this.options.formId && !this.options.readFormId )this.options.readFormId = this.options.formId;
  46. if( this.options.formEditId && !this.options.editFormId )this.options.editFormId = this.options.formEditId;
  47. if( this.options.readonly === "false" )this.options.readonly = false;
  48. if( this.options.readonly === "true" )this.options.readonly = true;
  49. if( this.options.documentId && this.options.documentId!=""){
  50. this.options.appId = "cms.Document"+this.options.documentId;
  51. }
  52. },
  53. loadApplication: function(callback){
  54. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  55. MWF.require("MWF.widget.Mask", function(){
  56. this.mask = new MWF.widget.Mask({"style": "desktop"});
  57. this.formNode = new Element("div", {"styles": {"min-height": "100%"}}).inject(this.node);
  58. // MWF.xDesktop.requireApp("cms.Document", "Actions.RestActions", function(){
  59. this.action = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Document.Actions.RestActions();
  60. if (!this.options.isRefresh){
  61. this.maxSize(function(){
  62. this.mask.loadNode(this.content);
  63. // this.loadDocument();
  64. this.loadDocumentV2();
  65. }.bind(this));
  66. }else{
  67. this.mask.loadNode(this.content);
  68. // this.loadDocument();
  69. this.loadDocumentV2();
  70. }
  71. if (callback) callback();
  72. //}.bind(this));
  73. }.bind(this));
  74. this.addEvent("queryClose", function(){
  75. this.refreshTaskCenter();
  76. }.bind(this));
  77. this.addKeyboardEvents();
  78. },
  79. refreshTaskCenter: function(){
  80. if ( this.desktop.apps && this.desktop.apps["cms.Explorer"]){
  81. if(this.desktop.apps["cms.Explorer"].content){
  82. this.desktop.apps["cms.Explorer"].content.unmask();
  83. }
  84. if( this.desktop.apps["cms.Explorer"] ){
  85. this.desktop.apps["cms.Explorer"].refreshAll();
  86. }
  87. }
  88. },
  89. addKeyboardEvents: function(){
  90. this.addEvent("keySave", function(e){
  91. this.keySave(e);
  92. }.bind(this));
  93. },
  94. keySave: function(e){
  95. if (this.appForm){
  96. if (!this.readonly){
  97. this.appForm.saveDocument();
  98. e.preventDefault();
  99. }
  100. }
  101. },
  102. reload: function(){
  103. this.fireEvent("queryReload");
  104. this.fireAppEvent("queryReload");
  105. this.formNode.empty();
  106. if (this.appForm){
  107. MWF.release(this.appForm);
  108. this.appForm = null;
  109. this.form = null;
  110. this.$events = {};
  111. }
  112. // this.parseDocumentV2(data);
  113. // this.openDocument();
  114. this.loadDocumentV2();
  115. },
  116. loadDocumentV2 : function( callback ){
  117. debugger;
  118. this.loadFormFlag = false;
  119. this.loadDocumentFlag = false;
  120. this.loadModuleFlag = false;
  121. this.checkSaveOnCloseFlag = false;
  122. this.json_document = null;
  123. this.json_form = null;
  124. //只读或者匿名查看
  125. var readonly = this.options.readonly !== false || this.options.anonymousAccess || this.options.anonymous;
  126. var formId = "";
  127. if( this.options.forceFormId ) { //有确定的id
  128. formId = this.options.forceFormId;
  129. }else if( this.options.printFormId ){ //有确定的id
  130. formId = this.options.printFormId;
  131. }else if( readonly && this.options.readFormId ){ //只读,并且有只读表单id
  132. formId = this.options.readFormId;
  133. }
  134. if( formId ){
  135. this.useProcessForm = this.options.useProcessForm;
  136. //编辑状态要先获取document再判断有没有权限编辑
  137. if( this.options.readonly !== false || this.options.anonymousAccess || this.options.anonymous ){
  138. this.getFormV2(formId, null, false);
  139. }
  140. this.getDocumentV2();
  141. }else{
  142. if( readonly ){ //只读情况,不需要判断是否有阅读权限
  143. this.lookupFormV2( true );
  144. }
  145. this.getDocumentV2();
  146. }
  147. var cl = "$all";
  148. MWF.xDesktop.requireApp("cms.Xform", cl, function(){
  149. this.loadModuleFlag = true;
  150. this.checkLoad();
  151. }.bind(this));
  152. },
  153. checkLoad : function ( toLoadForm ) {
  154. if( toLoadForm ){
  155. if( this.json_document ){
  156. this.getFormV2( this.formId );
  157. }else{
  158. this.needLoadForm = true;
  159. }
  160. }
  161. if( this.needLoadForm && !this.loadFormFlag && this.json_document ){
  162. this.needLoadForm = false;
  163. this.getFormV2( this.formId );
  164. }
  165. if( this.loadFormFlag && this.loadDocumentFlag && this.loadModuleFlag && this.checkSaveOnCloseFlag ){
  166. this.parseFormV2( this.json_form.data );
  167. if (layout.session && layout.session.user){
  168. this.openDocument();
  169. if (this.mask) this.mask.hide();
  170. }else{
  171. if (layout.sessionPromise){
  172. layout.sessionPromise.then(function(){
  173. this.openDocument();
  174. if (this.mask) this.mask.hide();
  175. }.bind(this), function(){});
  176. }
  177. }
  178. }
  179. },
  180. getDocumentV2 : function(){
  181. var id = this.options.documentId || this.options.id;
  182. var readonly = this.options.readonly !== false;
  183. var documentMethod;
  184. if( this.options.anonymousAccess || this.options.anonymous ){
  185. documentMethod = "getDocumentByAnonymous";
  186. }else if( readonly && !this.options.printFormId){
  187. documentMethod = "viewDocument";
  188. }else{
  189. documentMethod = "getDocument";
  190. }
  191. var attachmentMethod = ( this.options.anonymousAccess || this.options.anonymous ) ? "listAttachmentByAnonymous" : "listAttachment";
  192. o2.Actions.invokeAsync([
  193. {"action": this.action, "name": documentMethod},
  194. {"action": this.action, "name": attachmentMethod },
  195. ], {"success": function(jsonDocument, jsonAtt){
  196. if (jsonDocument ){
  197. if( jsonAtt && typeOf( jsonAtt.data ) === "array" ){
  198. jsonDocument.data.attachmentList = jsonAtt.data ;
  199. }else{
  200. jsonDocument.data.attachmentList = [];
  201. }
  202. this.json_document = jsonDocument;
  203. this.loadDocumentFlag = true;
  204. this.parseDocumentV2(this.json_document.data);
  205. if( this.categoryFormWaitingDocument ){
  206. this.getFormByCategory();
  207. }else{
  208. //编辑状态要先获取document再判断有没有权限编辑
  209. var toLoadForm = !(this.options.readonly !== false || this.options.anonymousAccess || this.options.anonymous );
  210. // var toLoadForm = this.options.readonly !== true && !this.options.anonymousAccess;
  211. this.checkLoad( toLoadForm );
  212. }
  213. this.checkSaveOnClose();
  214. }else{
  215. this.errorLoadingV2();
  216. }
  217. }.bind(this), "failure": function(error){
  218. this.errorLoadingV2( error );
  219. }.bind(this)}, id, id);
  220. },
  221. lookupFormV2 : function ( isReadonly ) {
  222. var id = this.options.documentId || this.options.id;
  223. var lookupMethod;
  224. if( this.options.anonymousAccess || this.options.anonymous ){
  225. lookupMethod = layout.mobile ? "lookupFormWithDocMobileAnonymousV2" : "lookupFormWithDocAnonymousV2";
  226. }else{
  227. lookupMethod = layout.mobile ? "lookupFormWithDocMobileV2" : "lookupFormWithDocV2";
  228. }
  229. this.action[lookupMethod](id, function(json){
  230. var formId;
  231. if( json.data.ppFormId ){
  232. formId = json.data.ppFormId;
  233. this.useProcessForm = true;
  234. }else if( isReadonly ){
  235. formId = json.data.readFormId || json.data.formId;
  236. }else{
  237. formId = json.data.formId || json.data.readFormId;
  238. }
  239. if (json.data.form){
  240. this.json_form = json;
  241. this.loadFormFlag = true;
  242. this.checkLoad();
  243. }else{
  244. var cacheTag = json.data.cacheTag || "";
  245. this.getFormV2( formId, cacheTag, false )
  246. }
  247. }.bind(this), function(){
  248. this.checkLoad( true );
  249. }.bind(this));
  250. },
  251. getFormV2 : function( formId, cacheTag, ignoreFromCategory ){
  252. if( this.useProcessForm ){
  253. this.getProcessForm( formId, cacheTag, ignoreFromCategory );
  254. }else{
  255. this.getCMSForm( formId, cacheTag, ignoreFromCategory );
  256. }
  257. },
  258. getCMSForm: function(formId, cacheTag, ignoreFromCategory){
  259. var formMethod;
  260. if( this.options.anonymousAccess || this.options.anonymous ){
  261. formMethod = layout.mobile ? "getFormMobileAnonymousV2" : "getFormAnonymousV2";
  262. }else{
  263. formMethod = layout.mobile ? "getFormMobileV2" : "getFormV2";
  264. }
  265. this.action[formMethod](
  266. formId,
  267. cacheTag || "",
  268. function( jsonForm ){
  269. this.json_form = jsonForm;
  270. this.loadFormFlag = true;
  271. this.checkLoad();
  272. }.bind(this),
  273. function(error){
  274. //没有表单,重新获取分类表单
  275. if( ignoreFromCategory ){
  276. this.errorLoadingV2( error , "form" );
  277. }else if( this.document && this.document.categoryId ){
  278. this.getFormByCategory();
  279. }else{
  280. this.categoryFormWaitingDocument = true;
  281. }
  282. return true;
  283. }.bind(this)
  284. )
  285. },
  286. getProcessForm: function(formId, cacheTag, ignoreFromCategory){
  287. var formMethod;
  288. // if( this.options.anonymousAccess || this.options.anonymous ){
  289. // formMethod = layout.mobile ? "getFormAnonymousV2Mobile" : "getFormAnonymousV2";
  290. // }else{
  291. formMethod = layout.mobile ? "getFormV2Mobile": "getFormV2";
  292. // }
  293. MWF.Actions.get("x_processplatform_assemble_surface")[formMethod](
  294. formId,
  295. cacheTag || "",
  296. function( jsonForm ){
  297. this.json_form = jsonForm;
  298. this.loadFormFlag = true;
  299. this.checkLoad();
  300. }.bind(this),
  301. function(error){
  302. //没有表单,重新获取分类表单
  303. if( ignoreFromCategory ){
  304. this.errorLoadingV2( error , "form" );
  305. }else if( this.document && this.document.categoryId ){
  306. this.getFormByCategory();
  307. }else{
  308. this.categoryFormWaitingDocument = true;
  309. }
  310. }.bind(this)
  311. )
  312. },
  313. getFormByCategory: function(){
  314. this.action.getCategory( this.document.categoryId, function(json){
  315. var d = json.data;
  316. if( this.readonly === true && d.readFormId && d.readFormId != "" ){
  317. this.formId = d.readFormId;
  318. }else{
  319. this.formId = d.formId || d.readFormId;
  320. }
  321. this.useProcessForm = false;
  322. this.getFormV2(this.formId, null, true);
  323. }.bind(this));
  324. },
  325. checkSaveOnClose: function(){
  326. if( this.readonly || this.document.docStatus !== "draft" || typeOf( this.options.saveOnClose ) !== "null" ){
  327. this.checkSaveOnCloseFlag = true;
  328. this.checkLoad();
  329. }else{
  330. this.action.getColumn( this.document.appId, function (json) {
  331. var config = JSON.parse( json.data.config || {} );
  332. this.options.saveOnClose = typeOf( config.saveDraftOnClose ) === "boolean" ? config.saveDraftOnClose : true;
  333. this.checkSaveOnCloseFlag = true;
  334. this.checkLoad();
  335. }.bind(this));
  336. }
  337. },
  338. parseFormV2: function( json ){
  339. if (json.form){
  340. this.formDataText = (json.form.data) ? MWF.decodeJsonString(json.form.data): "";
  341. this.form = (this.formDataText) ? JSON.decode(this.formDataText): null;
  342. this.relatedFormMap = json.relatedFormMap;
  343. this.relatedScriptMap = json.relatedScriptMap;
  344. if( json.form.data )delete json.form.data;
  345. this.formInfor = json.form;
  346. }else{
  347. if( layout.mobile ){
  348. var formDataStr = json.data.mobileData || json.data.data;
  349. this.formDataText = (formDataStr) ? MWF.decodeJsonString(formDataStr): "";
  350. this.form = (this.formDataText) ? JSON.decode(this.formDataText): null;
  351. // if( !this.form ){
  352. // this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  353. // }
  354. }else{
  355. this.formDataText = (json.data.data) ? MWF.decodeJsonString(json.data.data): "";
  356. this.form = (this.formDataText) ? JSON.decode(this.formDataText): null;
  357. }
  358. if( json.data.data )delete json.data.data;
  359. if( json.data.mobileData )delete json.data.mobileData;
  360. this.formInfor = json.form;
  361. }
  362. },
  363. parseDocumentV2 : function( data ){
  364. var title = "";
  365. title = data.document.title;
  366. this.setTitle(title);
  367. data.document.subject = data.document.title;
  368. this.data = data.data;
  369. this.extend = {
  370. "isCommend" : data.isCommend
  371. };
  372. this.attachmentList = data.attachmentList || [];
  373. this.attachmentList.each(function(att){
  374. att.lastUpdateTime = att.updateTime;
  375. att.person = att.creatorUid;
  376. });
  377. this.data.isNew = this.isEmptyObject(this.data) ? true : false;
  378. this.document = data.document;
  379. var isAdmin = false;
  380. if( MWF.AC.isCMSManager() || data.isAppAdmin || data.isCategoryAdmin || data.isManager){
  381. this.options.isControl = true;
  382. this.isAdmin = true;
  383. }
  384. //文档创建人
  385. if( data.isCreator || this.desktop.session.user.distinguishedName==this.document.creatorPerson ){
  386. this.options.isControl = true;
  387. }
  388. //作者权限
  389. if( data.isEditor ){
  390. this.options.isControl = true;
  391. }
  392. if( this.options.readonly ){ //强制只读
  393. this.readonly = true;
  394. }else{
  395. if(this.options.isControl && this.document.docStatus != "archived"){ //有编辑权限并且不是归档状态
  396. this.readonly = false;
  397. }else{
  398. this.readonly = true;
  399. }
  400. }
  401. debugger;
  402. var formId;
  403. if( this.readonly === true ){
  404. formId = this.options.forceFormId || this.options.printFormId || this.options.readFormId;
  405. if( formId ){
  406. this.useProcessForm = this.options.useProcessForm;
  407. }
  408. if( !formId && this.document.ppFormId ){
  409. formId = this.document.ppFormId;
  410. this.useProcessForm = true;
  411. }
  412. if( !formId && this.document.readFormId ){
  413. formId = this.document.readFormId;
  414. this.useProcessForm = false;
  415. }
  416. if( !formId && this.options.editFormId ){
  417. formId = this.options.editFormId;
  418. this.useProcessForm = this.options.useProcessForm;
  419. }
  420. if( !formId && this.document.form ){
  421. formId = this.document.form;
  422. this.useProcessForm = false;
  423. }
  424. }else{
  425. formId = this.options.forceFormId || this.options.printFormId || this.options.editFormId;
  426. if( formId ){
  427. this.useProcessForm = this.options.useProcessForm;
  428. }
  429. if( !formId && this.document.ppFormId ){
  430. formId = this.document.ppFormId;
  431. this.useProcessForm = true;
  432. }
  433. if( !formId && this.document.form ){
  434. formId = this.document.form;
  435. this.useProcessForm = false;
  436. }
  437. if( !formId && this.options.readFormId ){
  438. formId = this.options.readFormId;
  439. this.useProcessForm = this.options.useProcessForm;
  440. }
  441. if( !formId && this.document.readFormId ){
  442. formId = this.document.readFormId;
  443. this.useProcessForm = false;
  444. }
  445. }
  446. this.formId = formId;
  447. if(this.readonly || this.document.docStatus == "published"){
  448. this.options.autoSave = false;
  449. this.options.saveOnClose = false;
  450. }
  451. var isControl = this.options.isControl;
  452. this.control = data.control || {
  453. "allowRead": true,
  454. "allowPublishDocument": isControl && ["draft","waitPublish"].contains( this.document.docStatus ),
  455. "allowPublishDocumentDelayed": isControl && ["draft","waitPublish"].contains( this.document.docStatus ),
  456. "allowSave": isControl && this.document.docStatus == "published",
  457. "allowPopularDocument": MWF.AC.isHotPictureManager() && this.document.docStatus == "published",
  458. "allowEditDocument": isControl && !this.document.wf_workId,
  459. "allowDeleteDocument": isControl && !this.document.wf_workId,
  460. "allowSetTop": this.isAdmin && this.document.docStatus == "published" && !this.document.isTop,
  461. "allowCancelTop": this.isAdmin && this.document.docStatus == "published" && this.document.isTop
  462. };
  463. },
  464. errorLoadingV2 : function( error, type ){
  465. var text;
  466. if( type === "form" ){
  467. text = this.lp.formGettedError;
  468. }else{
  469. text = this.lp.documentGettedError;
  470. }
  471. if( error )text = text + ":" + error.responseText;
  472. this.notice( text , "error");
  473. layout.sessionPromise.then(function(){
  474. if (this.mask) this.mask.hide();
  475. this.close();
  476. }.bind(this), function(){});
  477. },
  478. isEmptyObject: function( obj ) {
  479. var name;
  480. for ( name in obj ) {
  481. return false;
  482. }
  483. return true;
  484. },
  485. // getDocument : function( callback ){
  486. // var id = this.options.documentId;
  487. //
  488. // var documentMethod = "getDocument";
  489. // if( this.options.anonymousAccess ){
  490. // documentMethod = "getDocumentByAnonymous"
  491. // }else if( this.options.readonly && !this.options.printFormId){
  492. // documentMethod = "viewDocument";
  493. // }
  494. //
  495. // var attachmentMethod = "listAttachment";
  496. // if( this.options.anonymousAccess ){
  497. // attachmentMethod = "listAttachmentByAnonymous"
  498. // }
  499. //
  500. // o2.Actions.invokeAsync([
  501. // {"action": this.action, "name": documentMethod},
  502. // {"action": this.action, "name": attachmentMethod }
  503. // ], {"success": function(json_document, json_att){
  504. // if (json_document ){
  505. // if( json_att && typeOf( json_att.data ) === "array" ){
  506. // json_document.data.attachmentList = json_att.data ;
  507. // }else{
  508. // json_document.data.attachmentList = [];
  509. // }
  510. // callback(json_document)
  511. // }else{
  512. // this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  513. // this.close();
  514. // }
  515. // }.bind(this), "failure": function(){
  516. // this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  517. // this.close();
  518. // }.bind(this)}, id);
  519. // },
  520. // loadDocument: function(){
  521. // this.getDocument( function(json){
  522. // json.data = json.data || [];
  523. // this.parseData(json.data);
  524. // this.loadForm( this.formId );
  525. // }.bind(this) );
  526. // },
  527. // errorDocument: function(){
  528. // if (this.mask) this.mask.hide();
  529. // this.node.set("text", "openError");
  530. // },
  531. // loadForm : function( formId, flag ){
  532. // var success = function(json){
  533. // if (json.form){
  534. // this.form = (json.form.data) ? JSON.decode(MWF.decodeJsonString(json.form.data)): null;
  535. // this.relatedFormMap = json.relatedFormMap;
  536. // this.relatedScriptMap = json.relatedScriptMap;
  537. // if( json.form.data )delete json.form.data;
  538. // this.formInfor = json.form;
  539. // }else{
  540. // if( layout.mobile ){
  541. // this.form = (json.data.mobileData) ? JSON.decode(MWF.decodeJsonString(json.data.mobileData)): null;
  542. // if( !this.form ){
  543. // this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  544. // }
  545. // }else{
  546. // this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  547. // }
  548. // if( json.data.data )delete json.data.data;
  549. // if( json.data.mobileData )delete json.data.mobileData;
  550. // this.formInfor = json.form;
  551. // }
  552. // //this.listAttachment();
  553. // this.openDocument();
  554. // if (this.mask) this.mask.hide();
  555. // }.bind(this);
  556. // var failure = function(error){
  557. // //没有表单,重新获取分类表单
  558. // if( !flag ){
  559. // this.action.getCategory( this.document.categoryId, function(json){
  560. // var d = json.data;
  561. // this.formId = d.formId || d.readFormId;
  562. // if( this.readonly == true && d.readFormId && d.readFormId != "" ){
  563. // this.formId = d.readFormId;
  564. // }
  565. // this.loadForm( this.formId, true );
  566. // }.bind(this));
  567. // }else{
  568. // this.notice( this.lp.formGettedError + ":" + error.responseText , "error");
  569. // this.close();
  570. // }
  571. // }.bind(this);
  572. // if( this.options.printFormId){
  573. // this.action.getForm(this.options.printFormId, function( json ){
  574. // success(json);
  575. // }.bind(this), function(error){
  576. // failure(error)
  577. // }.bind(this));
  578. // }else{
  579. // if( this.options.anonymousAccess ){
  580. // this.action.getFormByAnonymous(formId, function( json ){
  581. // success(json);
  582. // }.bind(this), function(error){
  583. // failure(error)
  584. // }.bind(this));
  585. // }else{
  586. // this.action.getForm(formId, function( json ){
  587. // success(json);
  588. // }.bind(this), function(error){
  589. // failure(error)
  590. // }.bind(this));
  591. // }
  592. // }
  593. // },
  594. // parseData: function(data){
  595. //
  596. // var title = "";
  597. // title = data.document.title;
  598. //
  599. // this.setTitle(title);
  600. //
  601. // data.document.subject = data.document.title;
  602. //
  603. // this.data = data.data;
  604. //
  605. // this.attachmentList = data.attachmentList || [];
  606. // this.attachmentList.each(function(att){
  607. // att.lastUpdateTime = att.updateTime;
  608. // att.person = att.creatorUid;
  609. // });
  610. //
  611. // if( this.isEmptyObject(this.data) ){
  612. // this.data.isNew = true;
  613. // }else{
  614. // this.data.isNew = false;
  615. // }
  616. //
  617. // this.document = data.document;
  618. //
  619. // var isAdmin = false;
  620. //
  621. // if( MWF.AC.isCMSManager() ){
  622. // this.options.isControl = true;
  623. // isAdmin = true;
  624. // }
  625. //
  626. // if( data.isAppAdmin ){
  627. // this.options.isControl = true;
  628. // isAdmin = true;
  629. // }
  630. // if( data.isCategoryAdmin ){
  631. // this.options.isControl = true;
  632. // isAdmin = true;
  633. // }
  634. // if( data.isManager ){
  635. // this.options.isControl = true;
  636. // isAdmin = true;
  637. // }
  638. // this.isAdmin = isAdmin;
  639. //
  640. // //文档创建人
  641. // if( data.isCreator || this.desktop.session.user.distinguishedName==this.document.creatorPerson ){
  642. // this.options.isControl = true;
  643. // }
  644. //
  645. // if( data.isEditor ){ //作者权限
  646. // this.options.isControl = true;
  647. // }
  648. //
  649. // if( this.options.readonly ){ //强制只读
  650. // this.readonly = true;
  651. // }else{
  652. // this.readonly = true;
  653. // if(this.options.isControl && this.document.docStatus != "archived"){
  654. // this.readonly = false;
  655. // }
  656. // }
  657. //
  658. // this.formId = this.document.form || this.document.readFormId;
  659. // if( this.readonly == true && this.document.readFormId && this.document.readFormId != "" ){
  660. // this.formId = this.document.readFormId;
  661. // if(this.options.formId){
  662. // this.formId = this.options.formId
  663. // }
  664. // }else {
  665. // if(this.options.formEditId){
  666. // this.formId = this.options.formEditId
  667. // }
  668. // }
  669. //
  670. // if(this.readonly || this.document.docStatus == "published"){
  671. // this.options.autoSave = false;
  672. // this.options.saveOnClose = false;
  673. // }
  674. //
  675. // //this.attachmentList = data.attachmentList;
  676. //
  677. // //this.inheritedAttachmentList = data.inheritedAttachmentList;
  678. // var isControl = this.options.isControl;
  679. // this.control = data.control || {
  680. // "allowRead": true,
  681. // "allowPublishDocument": isControl && this.document.docStatus == "draft",
  682. // "allowSave": isControl && this.document.docStatus == "published",
  683. // "allowPopularDocument": MWF.AC.isHotPictureManager() && this.document.docStatus == "published",
  684. // "allowEditDocument": isControl && !this.document.wf_workId,
  685. // "allowDeleteDocument": isControl && !this.document.wf_workId
  686. // };
  687. // },
  688. setPopularDocument: function(){
  689. MWF.xDesktop.requireApp("cms.Document", "HotLinkForm", null, false);
  690. var form = new MWF.xApplication.cms.Document.HotLinkForm(this, this.document, {
  691. documentId : this.options.documentId,
  692. summary : this.data.explain || "",
  693. onPostOk : function( id ){
  694. }.bind(this)
  695. },{
  696. app : this, lp : this.lp, css : this.css, actions : this.action
  697. });
  698. form.create();
  699. },
  700. openDocument: function(){
  701. debugger;
  702. if (this.form){
  703. // MWF.xDesktop.requireApp("cms.Xform", "Form", function(){
  704. MWF.xDesktop.requireApp("cms.Xform", "$all", function(){
  705. this.appForm = new MWF.CMSForm(this.formNode, this.form, {
  706. "readonly": this.readonly,
  707. "autoSave" : this.options.autoSave,
  708. "saveOnClose" : this.options.saveOnClose,
  709. "onPostPublish" : this.options.postPublish,
  710. "onAfterPublish" : this.options.afterPublish,
  711. "onAfterSave" : this.options.afterSave,
  712. "onBeforeClose" : this.options.beforeClose,
  713. "onPostDelete" : this.options.postDelete,
  714. "useProcessForm": this.useProcessForm
  715. });
  716. this.appForm.businessData = {
  717. "data": this.data,
  718. "document": this.document,
  719. "extend" : this.extend,
  720. "work": this.data.$work || {}, //兼用流程发布到内容管理
  721. "control": this.control,
  722. "attachmentList": this.attachmentList,
  723. "formInfor": this.formInfor,
  724. "status": {
  725. //"readonly": (this.options.readonly) ? true : false
  726. "readonly": this.readonly
  727. }
  728. };
  729. if( this.useProcessForm && this.data.$work ){
  730. this.appForm.businessData.work = {
  731. id : this.data.$work.workId
  732. }
  733. }
  734. this.appForm.formDataText = this.formDataText;
  735. this.appForm.documentAction = this.action;
  736. this.appForm.app = this;
  737. if( this.$events && this.$events.queryLoadForm ){
  738. this.appForm.addEvent( "queryLoad", function () {
  739. this.fireEvent("queryLoadForm", [this]);
  740. }.bind(this));
  741. }
  742. this.appForm.load(function(){
  743. if (window.o2android && window.o2android.postMessage) {
  744. layout.appForm = this.appForm;
  745. } else if (window.o2android && window.o2android.cmsFormLoaded){
  746. layout.appForm = this.appForm;
  747. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.cmsFormLoaded){
  748. layout.appForm = this.appForm;
  749. }
  750. this.fireEvent("postLoadForm", [this]);
  751. }.bind(this));
  752. }.bind(this));
  753. }
  754. },
  755. //errorDocument: function(){
  756. //
  757. //},
  758. recordStatus: function(){
  759. var status ={
  760. "documentId": this.options.documentId,
  761. "readonly": this.options.readonly,
  762. "autoSave" : this.options.autoSave,
  763. "saveOnClose" : this.options.saveOnClose
  764. };
  765. if( this.options.readFormId )status.readFormId = this.options.readFormId;
  766. if( this.options.editFormId )status.editFormId = this.options.editFormId;
  767. if( this.options.printFormId )status.printFormId = this.options.printFormId;
  768. if( this.options.forceFormId )status.forceFormId = this.options.forceFormId;
  769. if(this.options.appId && this.options.appId!="")status.appId = this.options.appId;
  770. if( this.options.useProcessForm )status.useProcessForm = true;
  771. return status;
  772. },
  773. onPostClose: function(){
  774. if (this.appForm){
  775. this.appForm.modules.each(function(module){
  776. MWF.release(module);
  777. });
  778. MWF.release(this.appForm);
  779. }
  780. }
  781. });