FileExplorer.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. MWF.xDesktop.requireApp("process.ProcessManager", "FileExplorer", null, false);
  2. MWF.xApplication.portal.PortalManager.FileExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.FileExplorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "create": MWF.APPPM.LP.file.create,
  7. "search": MWF.APPPM.LP.file.search,
  8. "searchText": MWF.APPPM.LP.file.searchText,
  9. "noElement": MWF.APPPM.LP.file.noDictionaryNoticeText
  10. },
  11. _createElement: function(e){
  12. // var _self = this;
  13. // var options = {
  14. // "onQueryLoad": function(){
  15. // this.actions = _self.app.restActions;
  16. // this.application = _self.app.options.application || _self.app.application;
  17. // this.explorer = _self;
  18. // }
  19. // };
  20. // this.app.desktop.openApplication(e, "process.FileDesigner", options);
  21. new MWF.xApplication.portal.PortalManager.FileDesigner(this);
  22. },
  23. getNewData: function(){
  24. return {
  25. "id": "",
  26. "name": "",
  27. "alias": "",
  28. "description": "",
  29. "portal": (this.app.options.application || this.app.application).id,
  30. "fileName": ""
  31. }
  32. },
  33. implodeFiles: function(){
  34. MWF.require("MWF.widget.Upload", function(){
  35. new MWF.widget.Upload(this.app.content, {
  36. "action": MWF.Actions.get("x_portal_assemble_designer").action,
  37. "multiple": true,
  38. "method": "uploadFile",
  39. "parameter": {"id": ""},
  40. "onBeforeUploadEntry": function(file, up){
  41. var data = this.getNewData();
  42. data.name = file.name;
  43. data.fileName = file.name;
  44. data.description = file.name+" "+this.getSizeText(file.size);
  45. data.updateTime = (new Date()).format("db");
  46. MWF.Actions.get("x_portal_assemble_designer").saveFile(data, function(json){
  47. up.options.parameter = {"id": json.data.id};
  48. var node = this.elementContentListNode.getFirst();
  49. if (node) if (node.hasClass("noElementNode")){
  50. node.destroy();
  51. }
  52. var itemObj = this._getItemObject(data);
  53. itemObj.load();
  54. }.bind(this), null, false);
  55. }.bind(this)
  56. }).load();
  57. }.bind(this));
  58. },
  59. _getItemObject: function(item){
  60. return new MWF.xApplication.portal.PortalManager.FileExplorer.File(this, item)
  61. }
  62. });
  63. MWF.xApplication.portal.PortalManager.FileExplorer.File = new Class({
  64. Extends: MWF.xApplication.process.ProcessManager.FileExplorer.File,
  65. _open: function(e){
  66. var _self = this;
  67. MWF.Actions.get("x_portal_assemble_designer").getFile(this.data.id, function(json){
  68. this.data = json.data;
  69. new MWF.xApplication.portal.PortalManager.FileDesigner(this.explorer, this.data);
  70. }.bind(this));
  71. },
  72. _getIcon: function(){
  73. return "file.png";
  74. },
  75. _getLnkPar: function(){
  76. return {
  77. "icon": this.explorer.path+this.explorer.options.style+"/fileIcon/lnk.png",
  78. "title": this.data.name,
  79. "par": "portal.FileDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.options.application.id+"\"}"
  80. };
  81. },
  82. deleteFile: function(callback){
  83. this.explorer.app.restActions.deleteFile(this.data.id, function(){
  84. this.node.destroy();
  85. if (callback) callback();
  86. }.bind(this));
  87. }
  88. });
  89. MWF.xApplication.portal.PortalManager.FileDesigner = new Class({
  90. Extends: MWF.xApplication.process.ProcessManager.FileDesigner,
  91. getNewData: function(){
  92. return {
  93. "id": "",
  94. "name": "",
  95. "alias": "",
  96. "description": "",
  97. "portal": (this.explorer.app.options.application || this.explorer.app.application).id,
  98. "fileName": ""
  99. }
  100. },
  101. createContentFileUrl: function(){
  102. if (this.data.fileName){
  103. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  104. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": "URL"}).inject(div);
  105. this.fileUrlNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  106. div.setStyle("height", "80px");
  107. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  108. url = url.replace(/{flag}/, this.data.id);
  109. url = url.replace(/{applicationFlag}/, this.data.portal);
  110. url = "/x_portal_assemble_surface"+url;
  111. this.fileUrlNode.setStyle("line-height", "18px");
  112. var href = MWF.Actions.getHost("x_portal_assemble_surface")+url;
  113. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  114. this.fileUrlNode.set("text", url);
  115. var a = new Element("div", {
  116. "styles": {"height": "30px"},
  117. "html": "<a target='_blank' href='"+href+"'>open</a>"
  118. }).inject(this.fileUrlNode, "bottom");
  119. }
  120. },
  121. modifyContentFileUrl: function(){
  122. if (!this.fileUrlNode){
  123. this.createContentFileUrl();
  124. }else{
  125. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  126. url = url.replace(/{flag}/, this.data.id);
  127. url = url.replace(/{applicationFlag}/, this.data.portal);
  128. //this.fileUrlNode.set("text", "/x_processplatform_assemble_surface"+url);
  129. url = "/x_portal_assemble_surface"+url;
  130. this.fileUrlNode.setStyle("line-height", "18px");
  131. var href = MWF.Actions.getHost("x_portal_assemble_surface")+url;
  132. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  133. this.fileUrlNode.set("text", url);
  134. var a = new Element("div", {
  135. "styles": {"height": "30px"},
  136. "html": "<a target='_blank' href='"+href+"'>open</a>"
  137. }).inject(this.fileUrlNode, "bottom")
  138. }
  139. },
  140. upload: function(){
  141. if (!this.data.id){
  142. // var data = this.getData();
  143. // this.data = Object.merge(this.data, data);
  144. // MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(){
  145. // this.explorer.reload();
  146. this.uploadFile(function(){
  147. this.app.notice(this.lp.file.uploadSuccess, "success");
  148. }.bind(this));
  149. // }.bind(this));
  150. }else{
  151. this.uploadFile(function(){
  152. this.app.notice(this.lp.file.uploadSuccess, "success");
  153. }.bind(this));
  154. }
  155. },
  156. uploadFile: function(callback){
  157. MWF.require("MWF.widget.Upload", function(){
  158. new MWF.widget.Upload(this.app.content, {
  159. "action": MWF.Actions.get("x_portal_assemble_designer").action,
  160. "method": "uploadFile",
  161. "parameter": {"id": this.data.id},
  162. "onCompleted": function(){
  163. this.loadFileIcon();
  164. this.modifyContentFileUrl();
  165. if (callback) callback();
  166. }.bind(this),
  167. "onBeforeUpload": function(files, up){
  168. var name = files[0].name;
  169. this.nameInput.set("value", name);
  170. var data = this.getData();
  171. this.data = Object.merge(this.data, data);
  172. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(json){
  173. this.explorer.reload();
  174. up.options.parameter = {"id": json.data.id};
  175. }.bind(this), null, false);
  176. }.bind(this),
  177. "onEvery": function(json, current, count, file){
  178. debugger;
  179. //this.data.description = file.name+" "+this.getSizeText(file.size);
  180. //this.data.id = json.data.id;
  181. this.data.fileName = file.name;
  182. this.data.description = file.name+" "+this.getSizeText(file.size);
  183. this.descriptionInput.set("value", this.data.description);
  184. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data);
  185. }.bind(this)
  186. }).load();
  187. }.bind(this));
  188. },
  189. save: function(){
  190. var data = this.getData();
  191. this.data = Object.merge(this.data, data);
  192. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(){
  193. this.explorer.reload();
  194. this.app.notice(this.lp.file.saveSuccess, "success");
  195. this.destroy();
  196. }.bind(this));
  197. }
  198. });