Main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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" : false,
  19. "saveOnClose" : false,
  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 ){
  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. this.notice( this.lp.formGettedError + ":" + error.responseText , "error");
  174. this.close();
  175. }.bind(this);
  176. if( this.options.anonymousAccess ){
  177. this.action.getFormByAnonymous(formId, function( json ){
  178. success(json);
  179. }.bind(this), function(error){
  180. failure(error)
  181. }.bind(this));
  182. }else{
  183. this.action.getForm(formId, function( json ){
  184. success(json);
  185. }.bind(this), function(error){
  186. failure(error)
  187. }.bind(this));
  188. }
  189. },
  190. //listAttachment: function(){
  191. // if( this.document.attachmentList && this.document.attachmentList.length > 0 ){
  192. // this.action.listAttachment(this.options.documentId, function( json ){
  193. // if (this.mask) this.mask.hide();
  194. // this.attachmentList = json.data;
  195. // this.attachmentList.each(function(att){
  196. // att.lastUpdateTime = att.updateTime;
  197. // att.person = att.creatorUid;
  198. // })
  199. // this.openDocument();
  200. // }.bind(this), function(error){
  201. // this.notice( this.lp.attachmentGettedError + ":" + error.responseText, "error");
  202. // this.close();
  203. // }.bind(this));
  204. // }else{
  205. // if (this.mask) this.mask.hide();
  206. // this.attachmentList = [];
  207. // this.openDocument();
  208. // }
  209. //},
  210. isEmptyObject: function( obj ) {
  211. var name;
  212. for ( name in obj ) {
  213. return false;
  214. }
  215. return true;
  216. },
  217. parseData: function(data){
  218. var title = "";
  219. title = data.document.title;
  220. this.setTitle(title);
  221. data.document.subject = data.document.title;
  222. this.data = data.data;
  223. this.attachmentList = data.attachmentList || [];
  224. this.attachmentList.each(function(att){
  225. att.lastUpdateTime = att.updateTime;
  226. att.person = att.creatorUid;
  227. });
  228. if( this.isEmptyObject(this.data) ){
  229. this.data.isNew = true;
  230. }else{
  231. this.data.isNew = false;
  232. }
  233. this.document = data.document;
  234. var isAdmin = false;
  235. if( MWF.AC.isCMSManager() ){
  236. this.options.isControl = true;
  237. isAdmin = true;
  238. }
  239. if( data.isAppAdmin ){
  240. this.options.isControl = true;
  241. isAdmin = true;
  242. }
  243. if( data.isCategoryAdmin ){
  244. this.options.isControl = true;
  245. isAdmin = true;
  246. }
  247. if( data.isManager ){
  248. this.options.isControl = true;
  249. isAdmin = true;
  250. }
  251. ////系统管理员
  252. //if( MWF.AC.isAdministrator() ){
  253. // this.options.isControl = true;
  254. // isAdmin = true;
  255. //}
  256. ////栏目管理员
  257. //if(this.controllers && this.controllers.contains(this.desktop.session.user.name) ){
  258. // this.options.isControl = true;
  259. // isAdmin = true;
  260. //}
  261. //文档创建人
  262. if( data.isCreator || this.desktop.session.user.distinguishedName==this.document.creatorPerson ){
  263. this.options.isControl = true;
  264. }
  265. if( data.isEditor ){ //作者权限
  266. this.options.isControl = true;
  267. }
  268. if( this.options.readonly ){ //强制只读
  269. this.readonly = true;
  270. }else{
  271. this.readonly = true;
  272. if(this.options.isControl && this.document.docStatus != "archived"){
  273. this.readonly = false;
  274. }
  275. }
  276. this.formId = this.document.form || this.document.readFormId;
  277. if( this.readonly == true && this.document.readFormId && this.document.readFormId != "" ){
  278. this.formId = this.document.readFormId;
  279. }
  280. if(!this.readonly){
  281. this.options.autoSave = true;
  282. this.options.saveOnClose = true;
  283. }
  284. //this.attachmentList = data.attachmentList;
  285. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  286. var isControl = this.options.isControl;
  287. this.control = data.control || {
  288. "allowRead": true,
  289. "allowPublishDocument": isControl && this.document.docStatus == "draft",
  290. "allowSave": isControl && this.document.docStatus == "published",
  291. "allowPopularDocument": MWF.AC.isHotPictureManager() && this.document.docStatus == "published",
  292. "allowEditDocument": isControl && !this.document.wf_workId,
  293. "allowDeleteDocument": isControl && !this.document.wf_workId
  294. };
  295. },
  296. setPopularDocument: function(){
  297. var form = new MWF.xApplication.cms.Document.HotLinkForm(this, this.document, {
  298. documentId : this.options.documentId,
  299. onPostOk : function( id ){
  300. }.bind(this)
  301. },{
  302. app : this, lp : this.lp, css : this.css, actions : this.action
  303. });
  304. form.create();
  305. },
  306. openDocument: function(){
  307. if (this.form){
  308. MWF.xDesktop.requireApp("cms.Xform", "Form", function(){
  309. this.appForm = new MWF.CMSForm(this.formNode, this.form, {
  310. "readonly": this.readonly,
  311. "autoSave" : this.options.autoSave,
  312. "saveOnClose" : this.options.saveOnClose,
  313. "onPostPublish" : this.options.postPublish,
  314. "onPostDelete" : this.options.postDelete
  315. });
  316. this.appForm.businessData = {
  317. "data": this.data,
  318. "document": this.document,
  319. "control": this.control,
  320. "attachmentList": this.attachmentList,
  321. "status": {
  322. //"readonly": (this.options.readonly) ? true : false
  323. "readonly": this.readonly
  324. }
  325. };
  326. this.appForm.documentAction = this.action;
  327. this.appForm.app = this;
  328. this.appForm.load();
  329. }.bind(this));
  330. }
  331. },
  332. //errorDocument: function(){
  333. //
  334. //},
  335. recordStatus: function(){
  336. var status ={
  337. "documentId": this.options.documentId,
  338. "readonly": this.options.readonly,
  339. "autoSave" : this.options.autoSave,
  340. "saveOnClose" : this.options.saveOnClose
  341. };
  342. if(this.options.appId && this.options.appId!="")status.appId = this.options.appId;
  343. return status;
  344. },
  345. onPostClose: function(){
  346. if (this.appForm){
  347. this.appForm.modules.each(function(module){
  348. MWF.release(module);
  349. });
  350. MWF.release(this.appForm);
  351. }
  352. }
  353. });