Main.js 11 KB

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