Main.js 15 KB

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