Main.js 15 KB

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