Main.js 14 KB

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