Main.js 14 KB

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