Main.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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": "800",
  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. debugger;
  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 = 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.readonly ){
  90. this.action.viewDocument(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{
  97. this.action.getDocument(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. }
  104. },
  105. loadDocument: function(){
  106. this.getDocument( function(json){
  107. //if (this.mask) this.mask.hide();
  108. //this.openDocument();
  109. this.loadController( json.data.document, function(){
  110. json.data = json.data || [];
  111. this.parseData(json.data);
  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. }.bind(this), function(error){
  156. this.notice( this.lp.formGettedError + ":" + error.responseText , "error");
  157. this.close();
  158. }.bind(this));
  159. },
  160. listAttachment: function(){
  161. if( this.document.attachmentList && this.document.attachmentList.length > 0 ){
  162. this.action.listAttachment(this.options.documentId, function( json ){
  163. if (this.mask) this.mask.hide();
  164. this.attachmentList = json.data;
  165. this.attachmentList.each(function(att){
  166. att.lastUpdateTime = att.updateTime;
  167. att.person = att.creatorUid;
  168. })
  169. this.openDocument();
  170. }.bind(this), function(error){
  171. this.notice( this.lp.attachmentGettedError + ":" + error.responseText, "error");
  172. this.close();
  173. }.bind(this));
  174. }else{
  175. if (this.mask) this.mask.hide();
  176. this.attachmentList = [];
  177. this.openDocument();
  178. }
  179. },
  180. isEmptyObject: function( obj ) {
  181. var name;
  182. for ( name in obj ) {
  183. return false;
  184. }
  185. return true;
  186. },
  187. parseData: function(data){
  188. var title = "";
  189. title = data.document.title;
  190. this.setTitle(title);
  191. data.document.subject = data.document.title;
  192. this.data = data.data;
  193. if( this.isEmptyObject(this.data) ){
  194. this.data.isNew = true;
  195. }else{
  196. this.data.isNew = false;
  197. }
  198. this.document = data.document;
  199. var isAdmin = false;
  200. //系统管理员
  201. if( MWF.AC.isAdministrator() ){
  202. this.options.isControl = true;
  203. isAdmin = true;
  204. }
  205. //栏目管理员
  206. if(this.controllers && this.controllers.contains(this.desktop.session.user.name) ){
  207. this.options.isControl = true;
  208. isAdmin = true;
  209. }
  210. //文档创建人
  211. if( this.desktop.session.user.name==this.document.creatorPerson ){
  212. this.options.isControl = true;
  213. }
  214. if( this.options.readonly ){ //强制只读
  215. this.readonly = true;
  216. }else{
  217. this.readonly = true;
  218. if(this.options.isControl && this.document.docStatus != "archived"){
  219. this.readonly = false;
  220. }
  221. }
  222. if(!this.readonly){
  223. this.options.autoSave = true;
  224. this.options.saveOnClose = true;
  225. }
  226. //this.attachmentList = data.attachmentList;
  227. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  228. var isControl = this.options.isControl;
  229. this.control = data.control || {
  230. "allowRead": true,
  231. "allowPublishDocument": isControl && this.document.docStatus == "draft",
  232. "allowArchiveDocument" : isControl && this.document.docStatus == "published",
  233. "allowRedraftDocument" : isControl && this.document.docStatus == "published",
  234. "allowSave": isControl && this.document.docStatus == "published",
  235. "allowPopularDocument": isAdmin && this.document.docStatus == "published",
  236. "allowEditDocument": isControl,
  237. "allowDeleteDocument": isControl
  238. };
  239. // this.form = (data.form) ? JSON.decode(MWF.decodeJsonString(data.form.data)): null;
  240. },
  241. setPopularDocument: function(){
  242. MWF.xDesktop.requireApp("cms.Document", "HotLinkForm", null, false);
  243. var form = new MWF.xApplication.cms.Document.HotLinkForm(this, this.document, {
  244. documentId : this.options.documentId,
  245. onPostOk : function( id ){
  246. }.bind(this)
  247. },{
  248. app : this, lp : this.lp, css : this.css, actions : this.action
  249. });
  250. form.create();
  251. },
  252. openDocument: function(){
  253. if (this.form){
  254. MWF.xDesktop.requireApp("cms.Xform", "Form", function(){
  255. this.appForm = new MWF.CMSForm(this.formNode, this.form, {
  256. "readonly": this.readonly,
  257. "autoSave" : this.options.autoSave,
  258. "saveOnClose" : this.options.saveOnClose,
  259. "onPostPublish" : this.options.postPublish,
  260. "onPostDelete" : this.options.postDelete
  261. });
  262. this.appForm.businessData = {
  263. "data": this.data,
  264. "document": this.document,
  265. "control": this.control,
  266. "attachmentList": this.attachmentList,
  267. "status": {
  268. //"readonly": (this.options.readonly) ? true : false
  269. "readonly": this.readonly
  270. }
  271. };
  272. this.appForm.documentAction = this.action;
  273. this.appForm.app = this;
  274. this.appForm.load();
  275. }.bind(this));
  276. }
  277. },
  278. //errorDocument: function(){
  279. //
  280. //},
  281. recordStatus: function(){
  282. var status ={
  283. "documentId": this.options.documentId,
  284. "readonly": this.options.readonly,
  285. "autoSave" : this.options.autoSave,
  286. "saveOnClose" : this.options.saveOnClose
  287. };
  288. if(this.options.appId && this.options.appId!="")status.appId = this.options.appId;
  289. return status;
  290. },
  291. onPostClose: function(){
  292. if (this.appForm){
  293. this.appForm.modules.each(function(module){
  294. MWF.release(module);
  295. });
  296. MWF.release(this.appForm);
  297. }
  298. }
  299. });