Main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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": MWF.xApplication.cms.Document.LP.title,
  15. "documentId": "",
  16. "isControl": false,
  17. "readonly": true,
  18. "autoSave" : true,
  19. "saveOnClose" : true,
  20. "postPublish" : null,
  21. "postDelete" : null,
  22. "formId" : null,
  23. "formEditId" : null
  24. },
  25. onQueryLoad: function(){
  26. this.lp = MWF.xApplication.cms.Document.LP;
  27. if (this.status){
  28. this.options.documentId = this.status.documentId;
  29. this.options.readonly = (this.status.readonly=="true" || this.status.readonly==true) ? true : false;
  30. this.options.autoSave = (this.status.autoSave=="true" || this.status.autoSave==true) ? true : false;
  31. this.options.saveOnClose = (this.status.saveOnClose=="true" || this.status.saveOnClose==true) ? true : false;
  32. this.options.formId = this.status.formId;
  33. this.options.printFormId = this.status.printFormId;
  34. }
  35. if( this.options.readonly === "false" )this.options.readonly = false;
  36. if( this.options.documentId && this.options.documentId!=""){
  37. this.options.appId = "cms.Document"+this.options.documentId;
  38. }
  39. },
  40. loadApplication: function(callback){
  41. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  42. MWF.require("MWF.widget.Mask", function(){
  43. this.mask = new MWF.widget.Mask({"style": "desktop"});
  44. this.formNode = new Element("div", {"styles": {"min-height": "100%"}}).inject(this.node);
  45. // MWF.xDesktop.requireApp("cms.Document", "Actions.RestActions", function(){
  46. this.action = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Document.Actions.RestActions();
  47. if (!this.options.isRefresh){
  48. this.maxSize(function(){
  49. this.mask.loadNode(this.content);
  50. this.loadDocument();
  51. }.bind(this));
  52. }else{
  53. this.mask.loadNode(this.content);
  54. this.loadDocument();
  55. }
  56. if (callback) callback();
  57. //}.bind(this));
  58. }.bind(this));
  59. this.addEvent("queryClose", function(){
  60. this.refreshTaskCenter();
  61. }.bind(this));
  62. this.addKeyboardEvents();
  63. },
  64. refreshTaskCenter: function(){
  65. if ( this.desktop.apps && this.desktop.apps["cms.Explorer"]){
  66. if(this.desktop.apps["cms.Explorer"].content){
  67. this.desktop.apps["cms.Explorer"].content.unmask();
  68. }
  69. if( this.desktop.apps["cms.Explorer"] ){
  70. this.desktop.apps["cms.Explorer"].refreshAll();
  71. }
  72. }
  73. },
  74. addKeyboardEvents: function(){
  75. this.addEvent("keySave", function(e){
  76. this.keySave(e);
  77. }.bind(this));
  78. },
  79. keySave: function(e){
  80. if (this.appForm){
  81. if (!this.readonly){
  82. this.appForm.saveDocument();
  83. e.preventDefault();
  84. }
  85. }
  86. },
  87. reload: function(data){
  88. if (this.form){
  89. this.formNode.empty();
  90. MWF.release(this.form);
  91. this.form = null;
  92. }
  93. this.parseData(data);
  94. this.openDocument();
  95. },
  96. getDocument : function( callback ){
  97. var id = this.options.documentId;
  98. //if( this.options.anonymousAccess ){
  99. // this.action.getDocumentByAnonymous(id, function(json){
  100. // callback(json)
  101. // }.bind(this), function( error ){
  102. // this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  103. // this.close();
  104. // }.bind(this));
  105. //}else if( this.options.readonly ){
  106. // this.action.viewDocument(id, function(json){
  107. // callback(json)
  108. // }.bind(this), function( error ){
  109. // this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  110. // this.close();
  111. // }.bind(this));
  112. //}else{
  113. // this.action.getDocument(id, function(json){
  114. // callback(json)
  115. // }.bind(this), function( error ){
  116. // this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  117. // this.close();
  118. // }.bind(this));
  119. //}
  120. var documentMethod = "getDocument";
  121. if( this.options.anonymousAccess ){
  122. documentMethod = "getDocumentByAnonymous"
  123. }else if( this.options.readonly && !this.options.printFormId){
  124. documentMethod = "viewDocument";
  125. }
  126. var attachmentMethod = "listAttachment";
  127. if( this.options.anonymousAccess ){
  128. attachmentMethod = "listAttachmentByAnonymous"
  129. }
  130. o2.Actions.invokeAsync([
  131. {"action": this.action, "name": documentMethod},
  132. {"action": this.action, "name": attachmentMethod }
  133. ], {"success": function(json_document, json_att){
  134. if (json_document ){
  135. if( json_att && typeOf( json_att.data ) === "array" ){
  136. json_document.data.attachmentList = json_att.data ;
  137. }else{
  138. json_document.data.attachmentList = [];
  139. }
  140. callback(json_document)
  141. }else{
  142. this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  143. this.close();
  144. }
  145. }.bind(this), "failure": function(){
  146. this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  147. this.close();
  148. }.bind(this)}, id);
  149. },
  150. loadDocument: function(){
  151. this.getDocument( function(json){
  152. json.data = json.data || [];
  153. this.parseData(json.data);
  154. this.loadForm( this.formId );
  155. }.bind(this) );
  156. },
  157. errorDocument: function(){
  158. if (this.mask) this.mask.hide();
  159. this.node.set("text", "openError");
  160. },
  161. loadForm : function( formId, flag ){
  162. var success = function(json){
  163. if (json.form){
  164. this.form = (json.form.data) ? JSON.decode(MWF.decodeJsonString(json.form.data)): null;
  165. this.relatedFormMap = json.relatedFormMap;
  166. this.relatedScriptMap = json.relatedScriptMap;
  167. if( json.form.data )delete json.form.data;
  168. this.formInfor = json.form;
  169. }else{
  170. if( layout.mobile ){
  171. this.form = (json.data.mobileData) ? JSON.decode(MWF.decodeJsonString(json.data.mobileData)): null;
  172. if( !this.form ){
  173. this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  174. }
  175. }else{
  176. this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  177. }
  178. if( json.data.data )delete json.data.data;
  179. if( json.data.mobileData )delete json.data.mobileData;
  180. this.formInfor = json.form;
  181. }
  182. //this.listAttachment();
  183. this.openDocument();
  184. if (this.mask) this.mask.hide();
  185. }.bind(this);
  186. var failure = function(error){
  187. //没有表单,重新获取分类表单
  188. if( !flag ){
  189. this.action.getCategory( this.document.categoryId, function(json){
  190. var d = json.data;
  191. this.formId = d.formId || d.readFormId;
  192. if( this.readonly == true && d.readFormId && d.readFormId != "" ){
  193. this.formId = d.readFormId;
  194. }
  195. this.loadForm( this.formId, true );
  196. }.bind(this));
  197. }else{
  198. this.notice( this.lp.formGettedError + ":" + error.responseText , "error");
  199. this.close();
  200. }
  201. }.bind(this);
  202. if( this.options.printFormId){
  203. this.action.getForm(this.options.printFormId, function( json ){
  204. success(json);
  205. }.bind(this), function(error){
  206. failure(error)
  207. }.bind(this));
  208. }else{
  209. if( this.options.anonymousAccess ){
  210. this.action.getFormByAnonymous(formId, function( json ){
  211. success(json);
  212. }.bind(this), function(error){
  213. failure(error)
  214. }.bind(this));
  215. }else{
  216. this.action.getForm(formId, function( json ){
  217. success(json);
  218. }.bind(this), function(error){
  219. failure(error)
  220. }.bind(this));
  221. }
  222. }
  223. },
  224. //listAttachment: function(){
  225. // if( this.document.attachmentList && this.document.attachmentList.length > 0 ){
  226. // this.action.listAttachment(this.options.documentId, function( json ){
  227. // if (this.mask) this.mask.hide();
  228. // this.attachmentList = json.data;
  229. // this.attachmentList.each(function(att){
  230. // att.lastUpdateTime = att.updateTime;
  231. // att.person = att.creatorUid;
  232. // })
  233. // this.openDocument();
  234. // }.bind(this), function(error){
  235. // this.notice( this.lp.attachmentGettedError + ":" + error.responseText, "error");
  236. // this.close();
  237. // }.bind(this));
  238. // }else{
  239. // if (this.mask) this.mask.hide();
  240. // this.attachmentList = [];
  241. // this.openDocument();
  242. // }
  243. //},
  244. isEmptyObject: function( obj ) {
  245. var name;
  246. for ( name in obj ) {
  247. return false;
  248. }
  249. return true;
  250. },
  251. parseData: function(data){
  252. var title = "";
  253. title = data.document.title;
  254. this.setTitle(title);
  255. data.document.subject = data.document.title;
  256. this.data = data.data;
  257. this.attachmentList = data.attachmentList || [];
  258. this.attachmentList.each(function(att){
  259. att.lastUpdateTime = att.updateTime;
  260. att.person = att.creatorUid;
  261. });
  262. if( this.isEmptyObject(this.data) ){
  263. this.data.isNew = true;
  264. }else{
  265. this.data.isNew = false;
  266. }
  267. this.document = data.document;
  268. var isAdmin = false;
  269. if( MWF.AC.isCMSManager() ){
  270. this.options.isControl = true;
  271. isAdmin = true;
  272. }
  273. if( data.isAppAdmin ){
  274. this.options.isControl = true;
  275. isAdmin = true;
  276. }
  277. if( data.isCategoryAdmin ){
  278. this.options.isControl = true;
  279. isAdmin = true;
  280. }
  281. if( data.isManager ){
  282. this.options.isControl = true;
  283. isAdmin = true;
  284. }
  285. this.isAdmin = isAdmin;
  286. ////系统管理员
  287. //if( MWF.AC.isAdministrator() ){
  288. // this.options.isControl = true;
  289. // isAdmin = true;
  290. //}
  291. ////栏目管理员
  292. //if(this.controllers && this.controllers.contains(this.desktop.session.user.name) ){
  293. // this.options.isControl = true;
  294. // isAdmin = true;
  295. //}
  296. //文档创建人
  297. if( data.isCreator || this.desktop.session.user.distinguishedName==this.document.creatorPerson ){
  298. this.options.isControl = true;
  299. }
  300. if( data.isEditor ){ //作者权限
  301. this.options.isControl = true;
  302. }
  303. if( this.options.readonly ){ //强制只读
  304. this.readonly = true;
  305. }else{
  306. this.readonly = true;
  307. if(this.options.isControl && this.document.docStatus != "archived"){
  308. this.readonly = false;
  309. }
  310. }
  311. this.formId = this.document.form || this.document.readFormId;
  312. if( this.readonly == true && this.document.readFormId && this.document.readFormId != "" ){
  313. this.formId = this.document.readFormId;
  314. if(this.options.formId){
  315. this.formId = this.options.formId
  316. }
  317. }else {
  318. if(this.options.formEditId){
  319. this.formId = this.options.formEditId
  320. }
  321. }
  322. if(this.readonly || this.document.docStatus == "published"){
  323. this.options.autoSave = false;
  324. this.options.saveOnClose = false;
  325. }
  326. //this.attachmentList = data.attachmentList;
  327. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  328. var isControl = this.options.isControl;
  329. this.control = data.control || {
  330. "allowRead": true,
  331. "allowPublishDocument": isControl && this.document.docStatus == "draft",
  332. "allowSave": isControl && this.document.docStatus == "published",
  333. "allowPopularDocument": MWF.AC.isHotPictureManager() && this.document.docStatus == "published",
  334. "allowEditDocument": isControl && !this.document.wf_workId,
  335. "allowDeleteDocument": isControl && !this.document.wf_workId
  336. };
  337. },
  338. setPopularDocument: function(){
  339. MWF.xDesktop.requireApp("cms.Document", "HotLinkForm", null, false);
  340. var form = new MWF.xApplication.cms.Document.HotLinkForm(this, this.document, {
  341. documentId : this.options.documentId,
  342. summary : this.data.explain || "",
  343. onPostOk : function( id ){
  344. }.bind(this)
  345. },{
  346. app : this, lp : this.lp, css : this.css, actions : this.action
  347. });
  348. form.create();
  349. },
  350. openDocument: function(){
  351. if (this.form){
  352. // MWF.xDesktop.requireApp("cms.Xform", "Form", function(){
  353. MWF.xDesktop.requireApp("cms.Xform", "$all", function(){
  354. this.appForm = new MWF.CMSForm(this.formNode, this.form, {
  355. "readonly": this.readonly,
  356. "autoSave" : this.options.autoSave,
  357. "saveOnClose" : this.options.saveOnClose,
  358. "onPostPublish" : this.options.postPublish,
  359. "onAfterPublish" : this.options.afterPublish,
  360. "onPostDelete" : this.options.postDelete
  361. });
  362. this.appForm.businessData = {
  363. "data": this.data,
  364. "document": this.document,
  365. "control": this.control,
  366. "attachmentList": this.attachmentList,
  367. "status": {
  368. //"readonly": (this.options.readonly) ? true : false
  369. "readonly": this.readonly
  370. }
  371. };
  372. this.appForm.documentAction = this.action;
  373. this.appForm.app = this;
  374. this.appForm.load();
  375. }.bind(this));
  376. }
  377. },
  378. //errorDocument: function(){
  379. //
  380. //},
  381. recordStatus: function(){
  382. var status ={
  383. "documentId": this.options.documentId,
  384. "readonly": this.options.readonly,
  385. "autoSave" : this.options.autoSave,
  386. "saveOnClose" : this.options.saveOnClose
  387. };
  388. if( this.options.formId )status.formId = this.options.formId;
  389. if( this.options.printFormId )status.printFormId = this.options.printFormId;
  390. if(this.options.appId && this.options.appId!="")status.appId = this.options.appId;
  391. return status;
  392. },
  393. onPostClose: function(){
  394. if (this.appForm){
  395. this.appForm.modules.each(function(module){
  396. MWF.release(module);
  397. });
  398. MWF.release(this.appForm);
  399. }
  400. }
  401. });