Main.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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.xApplication.cms.Document.Main = new Class({
  5. Extends: MWF.xApplication.Common.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "cms.Document",
  10. "icon": "icon.png",
  11. "width": "1200",
  12. "height": "680",
  13. "title": MWF.xApplication.cms.Document.LP.title,
  14. "documentId": "",
  15. "isControl": false,
  16. "readonly": true,
  17. "autoSave" : false,
  18. "saveOnClose" : false,
  19. "postPublish" : null,
  20. "postDelete" : null
  21. },
  22. onQueryLoad: function(){
  23. this.lp = MWF.xApplication.cms.Document.LP;
  24. if (this.status){
  25. this.options.documentId = this.status.documentId;
  26. this.options.readonly = (this.status.readonly=="true" || this.status.readonly==true) ? true : false;
  27. this.options.autoSave = (this.status.autoSave=="true" || this.status.autoSave==true) ? true : false;
  28. this.options.saveOnClose = (this.status.saveOnClose=="true" || this.status.saveOnClose==true) ? true : false;
  29. }
  30. if( this.options.documentId && this.options.documentId!=""){
  31. this.options.appId = "cms.Document"+this.options.documentId;
  32. }
  33. },
  34. loadApplication: function(callback){
  35. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  36. MWF.require("MWF.widget.Mask", function(){
  37. this.mask = new MWF.widget.Mask({"style": "desktop"});
  38. this.formNode = new Element("div", {"styles": {"min-height": "100%"}}).inject(this.node);
  39. MWF.xDesktop.requireApp("cms.Document", "Actions.RestActions", function(){
  40. this.action = new MWF.xApplication.cms.Document.Actions.RestActions();
  41. if (!this.options.isRefresh){
  42. this.maxSize(function(){
  43. this.mask.loadNode(this.content);
  44. this.loadDocument();
  45. }.bind(this));
  46. }else{
  47. this.mask.loadNode(this.content);
  48. this.loadDocument();
  49. }
  50. if (callback) callback();
  51. }.bind(this));
  52. }.bind(this));
  53. this.addEvent("queryClose", function(){
  54. this.refreshTaskCenter();
  55. }.bind(this))
  56. this.addKeyboardEvents();
  57. },
  58. refreshTaskCenter: function(){
  59. if (this.desktop.apps["cms.Explorer"]){
  60. this.desktop.apps["cms.Explorer"].content.unmask();
  61. this.desktop.apps["cms.Explorer"].refreshAll();
  62. }
  63. },
  64. addKeyboardEvents: function(){
  65. this.addEvent("keySave", function(e){
  66. this.keySave(e);
  67. }.bind(this));
  68. },
  69. keySave: function(e){
  70. if (this.appForm){
  71. if (!this.readonly){
  72. this.appForm.saveDocument();
  73. e.preventDefault();
  74. }
  75. }
  76. },
  77. reload: function(data){
  78. if (this.form){
  79. this.formNode.empty();
  80. MWF.release(this.form);
  81. this.form = null;
  82. }
  83. this.parseData(data);
  84. this.openDocument();
  85. },
  86. getDocument : function( callback ){
  87. var id = this.options.documentId;
  88. if( this.options.readonly ){
  89. this.action.viewDocument(id, function(json){
  90. callback(json)
  91. }.bind(this), function( error ){
  92. this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  93. this.close();
  94. }.bind(this));
  95. }else{
  96. this.action.getDocument(id, function(json){
  97. callback(json)
  98. }.bind(this), function( error ){
  99. this.notice( this.lp.documentGettedError + ":" + error.responseText , "error");
  100. this.close();
  101. }.bind(this));
  102. }
  103. },
  104. loadDocument: function(){
  105. this.getDocument( function(json){
  106. //if (this.mask) this.mask.hide();
  107. //this.openDocument();
  108. //this.loadController( json.data.document, function(){
  109. json.data = json.data || [];
  110. this.parseData(json.data);
  111. this.loadForm( this.formId );
  112. //this.action.getCategory( json.data.document.categoryId, function( js ){
  113. // this.categoryData = js.data;
  114. // var formId = this.categoryData.formId || this.categoryData.readFormId;
  115. // if( this.readonly == true && this.categoryData.readFormId && this.categoryData.readFormId != "" ){
  116. // formId = this.categoryData.readFormId
  117. // }
  118. // if( !formId || formId=="" ){
  119. // this.notice( json.data.document.categoryName + this.lp.formNotSetted , "error");
  120. // }else{
  121. // this.loadForm( formId );
  122. // }
  123. //}.bind(this))
  124. //}.bind(this))
  125. }.bind(this) );
  126. },
  127. //loadController: function(document, callback){
  128. // this.controllers =[];
  129. // this.action.listColumnController(document.appId, function( json ){
  130. // json.data = json.data || [];
  131. // json.data.each(function(item){
  132. // this.controllers.push(item.adminUid);
  133. // }.bind(this));
  134. // this.action.listCategoryController( document.categoryId, function( j ){
  135. // j.data = j.data || [];
  136. // j.data.each(function(item){
  137. // this.controllers.push(item.adminUid);
  138. // }.bind(this));
  139. // if(callback)callback(json);
  140. // }.bind(this) )
  141. // }.bind(this), function(error){
  142. // this.notice( this.lp.controllerGettedError + ":" + error.responseText , "error");
  143. // this.close();
  144. // }.bind(this));
  145. //},
  146. errorDocument: function(){
  147. if (this.mask) this.mask.hide();
  148. this.node.set("text", "openError");
  149. },
  150. loadForm : function( formId ){
  151. this.action.getForm(formId, function( json ){
  152. //if (this.mask) this.mask.hide();
  153. this.form = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  154. //this.listAttachment();
  155. this.openDocument();
  156. if (this.mask) this.mask.hide();
  157. }.bind(this), function(error){
  158. this.notice( this.lp.formGettedError + ":" + error.responseText , "error");
  159. this.close();
  160. }.bind(this));
  161. },
  162. //listAttachment: function(){
  163. // if( this.document.attachmentList && this.document.attachmentList.length > 0 ){
  164. // this.action.listAttachment(this.options.documentId, function( json ){
  165. // if (this.mask) this.mask.hide();
  166. // this.attachmentList = json.data;
  167. // this.attachmentList.each(function(att){
  168. // att.lastUpdateTime = att.updateTime;
  169. // att.person = att.creatorUid;
  170. // })
  171. // this.openDocument();
  172. // }.bind(this), function(error){
  173. // this.notice( this.lp.attachmentGettedError + ":" + error.responseText, "error");
  174. // this.close();
  175. // }.bind(this));
  176. // }else{
  177. // if (this.mask) this.mask.hide();
  178. // this.attachmentList = [];
  179. // this.openDocument();
  180. // }
  181. //},
  182. isEmptyObject: function( obj ) {
  183. var name;
  184. for ( name in obj ) {
  185. return false;
  186. }
  187. return true;
  188. },
  189. parseData: function(data){
  190. var title = "";
  191. title = data.document.title;
  192. this.setTitle(title);
  193. data.document.subject = data.document.title;
  194. this.data = data.data;
  195. this.attachmentList = data.attachmentList || [];
  196. this.attachmentList.each(function(att){
  197. att.lastUpdateTime = att.updateTime;
  198. att.person = att.creatorUid;
  199. });
  200. if( this.isEmptyObject(this.data) ){
  201. this.data.isNew = true;
  202. }else{
  203. this.data.isNew = false;
  204. }
  205. this.document = data.document;
  206. var isAdmin = false;
  207. if( data.isAppAdmin ){
  208. this.options.isControl = true;
  209. isAdmin = true;
  210. }
  211. if( data.isCategoryAdmin ){
  212. this.options.isControl = true;
  213. isAdmin = true;
  214. }
  215. if( data.isManager ){
  216. this.options.isControl = true;
  217. isAdmin = true;
  218. }
  219. ////系统管理员
  220. //if( MWF.AC.isAdministrator() ){
  221. // this.options.isControl = true;
  222. // isAdmin = true;
  223. //}
  224. ////栏目管理员
  225. //if(this.controllers && this.controllers.contains(this.desktop.session.user.name) ){
  226. // this.options.isControl = true;
  227. // isAdmin = true;
  228. //}
  229. //文档创建人
  230. if( this.desktop.session.user.name==this.document.creatorPerson ){
  231. this.options.isControl = true;
  232. }
  233. if( this.options.readonly ){ //强制只读
  234. this.readonly = true;
  235. }else{
  236. this.readonly = true;
  237. if(this.options.isControl && this.document.docStatus != "archived"){
  238. this.readonly = false;
  239. }
  240. }
  241. this.formId = this.document.form || this.document.readFormId;
  242. if( this.readonly == true && this.document.readFormId && this.document.readFormId != "" ){
  243. this.formId = this.document.readFormId;
  244. }
  245. if(!this.readonly){
  246. this.options.autoSave = true;
  247. this.options.saveOnClose = true;
  248. }
  249. //this.attachmentList = data.attachmentList;
  250. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  251. var isControl = this.options.isControl;
  252. this.control = data.control || {
  253. "allowRead": true,
  254. "allowPublishDocument": isControl && this.document.docStatus == "draft",
  255. "allowArchiveDocument" : isControl && this.document.docStatus == "published",
  256. "allowRedraftDocument" : isControl && this.document.docStatus == "published",
  257. "allowSave": isControl && this.document.docStatus == "published",
  258. "allowPopularDocument": isAdmin && this.document.docStatus == "published",
  259. "allowEditDocument": isControl && !this.document.workId,
  260. "allowDeleteDocument": isControl && !this.document.workId
  261. };
  262. // this.form = (data.form) ? JSON.decode(MWF.decodeJsonString(data.form.data)): null;
  263. },
  264. setPopularDocument: function(){
  265. MWF.xDesktop.requireApp("cms.Document", "HotLinkForm", null, false);
  266. var form = new MWF.xApplication.cms.Document.HotLinkForm(this, this.document, {
  267. documentId : this.options.documentId,
  268. onPostOk : function( id ){
  269. }.bind(this)
  270. },{
  271. app : this, lp : this.lp, css : this.css, actions : this.action
  272. });
  273. form.create();
  274. },
  275. openDocument: function(){
  276. if (this.form){
  277. MWF.xDesktop.requireApp("cms.Xform", "Form", function(){
  278. this.appForm = new MWF.CMSForm(this.formNode, this.form, {
  279. "readonly": this.readonly,
  280. "autoSave" : this.options.autoSave,
  281. "saveOnClose" : this.options.saveOnClose,
  282. "onPostPublish" : this.options.postPublish,
  283. "onPostDelete" : this.options.postDelete
  284. });
  285. this.appForm.businessData = {
  286. "data": this.data,
  287. "document": this.document,
  288. "control": this.control,
  289. "attachmentList": this.attachmentList,
  290. "status": {
  291. //"readonly": (this.options.readonly) ? true : false
  292. "readonly": this.readonly
  293. }
  294. };
  295. this.appForm.documentAction = this.action;
  296. this.appForm.app = this;
  297. this.appForm.load();
  298. }.bind(this));
  299. }
  300. },
  301. //errorDocument: function(){
  302. //
  303. //},
  304. recordStatus: function(){
  305. var status ={
  306. "documentId": this.options.documentId,
  307. "readonly": this.options.readonly,
  308. "autoSave" : this.options.autoSave,
  309. "saveOnClose" : this.options.saveOnClose
  310. };
  311. if(this.options.appId && this.options.appId!="")status.appId = this.options.appId;
  312. return status;
  313. },
  314. onPostClose: function(){
  315. if (this.appForm){
  316. this.appForm.modules.each(function(module){
  317. MWF.release(module);
  318. });
  319. MWF.release(this.appForm);
  320. }
  321. }
  322. });