Main.js 15 KB

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