Main.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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( layout.mobile ){
  164. this.form = (json.data.mobileData) ? JSON.decode(MWF.decodeJsonString(json.data.mobileData)): null;
  165. if( !this.form ){
  166. this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  167. }
  168. }else{
  169. this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  170. }
  171. //this.listAttachment();
  172. this.openDocument();
  173. if (this.mask) this.mask.hide();
  174. }.bind(this);
  175. var failure = function(error){
  176. //没有表单,重新获取分类表单
  177. if( !flag ){
  178. this.action.getCategory( this.document.categoryId, function(json){
  179. var d = json.data;
  180. this.formId = d.formId || d.readFormId;
  181. if( this.readonly == true && d.readFormId && d.readFormId != "" ){
  182. this.formId = d.readFormId;
  183. }
  184. this.loadForm( this.formId, true );
  185. }.bind(this));
  186. }else{
  187. this.notice( this.lp.formGettedError + ":" + error.responseText , "error");
  188. this.close();
  189. }
  190. }.bind(this);
  191. if( this.options.printFormId){
  192. this.action.getForm(this.options.printFormId, function( json ){
  193. success(json);
  194. }.bind(this), function(error){
  195. failure(error)
  196. }.bind(this));
  197. }else{
  198. if( this.options.anonymousAccess ){
  199. this.action.getFormByAnonymous(formId, function( json ){
  200. success(json);
  201. }.bind(this), function(error){
  202. failure(error)
  203. }.bind(this));
  204. }else{
  205. this.action.getForm(formId, function( json ){
  206. success(json);
  207. }.bind(this), function(error){
  208. failure(error)
  209. }.bind(this));
  210. }
  211. }
  212. },
  213. //listAttachment: function(){
  214. // if( this.document.attachmentList && this.document.attachmentList.length > 0 ){
  215. // this.action.listAttachment(this.options.documentId, function( json ){
  216. // if (this.mask) this.mask.hide();
  217. // this.attachmentList = json.data;
  218. // this.attachmentList.each(function(att){
  219. // att.lastUpdateTime = att.updateTime;
  220. // att.person = att.creatorUid;
  221. // })
  222. // this.openDocument();
  223. // }.bind(this), function(error){
  224. // this.notice( this.lp.attachmentGettedError + ":" + error.responseText, "error");
  225. // this.close();
  226. // }.bind(this));
  227. // }else{
  228. // if (this.mask) this.mask.hide();
  229. // this.attachmentList = [];
  230. // this.openDocument();
  231. // }
  232. //},
  233. isEmptyObject: function( obj ) {
  234. var name;
  235. for ( name in obj ) {
  236. return false;
  237. }
  238. return true;
  239. },
  240. parseData: function(data){
  241. var title = "";
  242. title = data.document.title;
  243. this.setTitle(title);
  244. data.document.subject = data.document.title;
  245. this.data = data.data;
  246. this.attachmentList = data.attachmentList || [];
  247. this.attachmentList.each(function(att){
  248. att.lastUpdateTime = att.updateTime;
  249. att.person = att.creatorUid;
  250. });
  251. if( this.isEmptyObject(this.data) ){
  252. this.data.isNew = true;
  253. }else{
  254. this.data.isNew = false;
  255. }
  256. this.document = data.document;
  257. var isAdmin = false;
  258. if( MWF.AC.isCMSManager() ){
  259. this.options.isControl = true;
  260. isAdmin = true;
  261. }
  262. if( data.isAppAdmin ){
  263. this.options.isControl = true;
  264. isAdmin = true;
  265. }
  266. if( data.isCategoryAdmin ){
  267. this.options.isControl = true;
  268. isAdmin = true;
  269. }
  270. if( data.isManager ){
  271. this.options.isControl = true;
  272. isAdmin = true;
  273. }
  274. this.isAdmin = isAdmin;
  275. ////系统管理员
  276. //if( MWF.AC.isAdministrator() ){
  277. // this.options.isControl = true;
  278. // isAdmin = true;
  279. //}
  280. ////栏目管理员
  281. //if(this.controllers && this.controllers.contains(this.desktop.session.user.name) ){
  282. // this.options.isControl = true;
  283. // isAdmin = true;
  284. //}
  285. //文档创建人
  286. if( data.isCreator || this.desktop.session.user.distinguishedName==this.document.creatorPerson ){
  287. this.options.isControl = true;
  288. }
  289. if( data.isEditor ){ //作者权限
  290. this.options.isControl = true;
  291. }
  292. if( this.options.readonly ){ //强制只读
  293. this.readonly = true;
  294. }else{
  295. this.readonly = true;
  296. if(this.options.isControl && this.document.docStatus != "archived"){
  297. this.readonly = false;
  298. }
  299. }
  300. this.formId = this.document.form || this.document.readFormId;
  301. if( this.readonly == true && this.document.readFormId && this.document.readFormId != "" ){
  302. this.formId = this.document.readFormId;
  303. if(this.options.formId){
  304. this.formId = this.options.formId
  305. }
  306. }else {
  307. if(this.options.formEditId){
  308. this.formId = this.options.formEditId
  309. }
  310. }
  311. if(this.readonly || this.document.docStatus == "published"){
  312. this.options.autoSave = false;
  313. this.options.saveOnClose = false;
  314. }
  315. //this.attachmentList = data.attachmentList;
  316. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  317. var isControl = this.options.isControl;
  318. this.control = data.control || {
  319. "allowRead": true,
  320. "allowPublishDocument": isControl && this.document.docStatus == "draft",
  321. "allowSave": isControl && this.document.docStatus == "published",
  322. "allowPopularDocument": MWF.AC.isHotPictureManager() && this.document.docStatus == "published",
  323. "allowEditDocument": isControl && !this.document.wf_workId,
  324. "allowDeleteDocument": isControl && !this.document.wf_workId
  325. };
  326. },
  327. setPopularDocument: function(){
  328. MWF.xDesktop.requireApp("cms.Document", "HotLinkForm", null, false);
  329. var form = new MWF.xApplication.cms.Document.HotLinkForm(this, this.document, {
  330. documentId : this.options.documentId,
  331. summary : this.data.explain || "",
  332. onPostOk : function( id ){
  333. }.bind(this)
  334. },{
  335. app : this, lp : this.lp, css : this.css, actions : this.action
  336. });
  337. form.create();
  338. },
  339. openDocument: function(){
  340. if (this.form){
  341. // MWF.xDesktop.requireApp("cms.Xform", "Form", function(){
  342. MWF.xDesktop.requireApp("cms.Xform", "$all", function(){
  343. this.appForm = new MWF.CMSForm(this.formNode, this.form, {
  344. "readonly": this.readonly,
  345. "autoSave" : this.options.autoSave,
  346. "saveOnClose" : this.options.saveOnClose,
  347. "onPostPublish" : this.options.postPublish,
  348. "onAfterPublish" : this.options.afterPublish,
  349. "onPostDelete" : this.options.postDelete
  350. });
  351. this.appForm.businessData = {
  352. "data": this.data,
  353. "document": this.document,
  354. "control": this.control,
  355. "attachmentList": this.attachmentList,
  356. "status": {
  357. //"readonly": (this.options.readonly) ? true : false
  358. "readonly": this.readonly
  359. }
  360. };
  361. this.appForm.documentAction = this.action;
  362. this.appForm.app = this;
  363. this.appForm.load();
  364. }.bind(this));
  365. }
  366. },
  367. //errorDocument: function(){
  368. //
  369. //},
  370. recordStatus: function(){
  371. var status ={
  372. "documentId": this.options.documentId,
  373. "readonly": this.options.readonly,
  374. "autoSave" : this.options.autoSave,
  375. "saveOnClose" : this.options.saveOnClose
  376. };
  377. if( this.options.formId )status.formId = this.options.formId;
  378. if( this.options.printFormId )status.printFormId = this.options.printFormId;
  379. if(this.options.appId && this.options.appId!="")status.appId = this.options.appId;
  380. return status;
  381. },
  382. onPostClose: function(){
  383. if (this.appForm){
  384. this.appForm.modules.each(function(module){
  385. MWF.release(module);
  386. });
  387. MWF.release(this.appForm);
  388. }
  389. }
  390. });