Main.js 14 KB

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