FileExplorer.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  77. url = url.replace(/{flag}/, this.data.id);
  78. url = url.replace(/{applicationFlag}/, this.data.portal);
  79. url = "/x_portal_assemble_surface"+url;
  80. var href = MWF.Actions.getHost("x_portal_assemble_surface")+url;
  81. return {
  82. "icon": this.explorer.path+this.explorer.options.style+"/fileIcon/lnk.png",
  83. "title": this.data.name,
  84. "par": "@url#"+href
  85. };
  86. },
  87. deleteFile: function(callback){
  88. this.explorer.app.restActions.deleteFile(this.data.id, function(){
  89. this.node.destroy();
  90. if (callback) callback();
  91. }.bind(this));
  92. }
  93. });
  94. MWF.xApplication.portal.PortalManager.FileDesigner = new Class({
  95. Extends: MWF.xApplication.process.ProcessManager.FileDesigner,
  96. getNewData: function(){
  97. return {
  98. "id": "",
  99. "name": "",
  100. "alias": "",
  101. "description": "",
  102. "portal": (this.explorer.app.options.application || this.explorer.app.application).id,
  103. "fileName": ""
  104. }
  105. },
  106. createContentFileUrl: function(){
  107. if (this.data.fileName){
  108. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  109. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": "URL"}).inject(div);
  110. this.fileUrlNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  111. div.setStyle("height", "80px");
  112. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  113. url = url.replace(/{flag}/, this.data.id);
  114. url = url.replace(/{applicationFlag}/, this.data.portal);
  115. url = "/x_portal_assemble_surface"+url;
  116. this.fileUrlNode.setStyle("line-height", "18px");
  117. var href = MWF.Actions.getHost("x_portal_assemble_surface")+url;
  118. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  119. this.fileUrlNode.set("text", url);
  120. var a = new Element("div", {
  121. "styles": {"height": "30px"},
  122. "html": "<a target='_blank' href='"+href+"'>open</a>"
  123. }).inject(this.fileUrlNode, "bottom");
  124. }
  125. },
  126. modifyContentFileUrl: function(){
  127. if (!this.fileUrlNode){
  128. this.createContentFileUrl();
  129. }else{
  130. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  131. url = url.replace(/{flag}/, this.data.id);
  132. url = url.replace(/{applicationFlag}/, this.data.portal);
  133. //this.fileUrlNode.set("text", "/x_processplatform_assemble_surface"+url);
  134. url = "/x_portal_assemble_surface"+url;
  135. this.fileUrlNode.setStyle("line-height", "18px");
  136. var href = MWF.Actions.getHost("x_portal_assemble_surface")+url;
  137. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  138. this.fileUrlNode.set("text", url);
  139. var a = new Element("div", {
  140. "styles": {"height": "30px"},
  141. "html": "<a target='_blank' href='"+href+"'>open</a>"
  142. }).inject(this.fileUrlNode, "bottom")
  143. }
  144. },
  145. upload: function(){
  146. if (!this.data.id){
  147. // var data = this.getData();
  148. // this.data = Object.merge(this.data, data);
  149. // MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(){
  150. // this.explorer.reload();
  151. this.uploadFile(function(){
  152. this.app.notice(this.lp.file.uploadSuccess, "success");
  153. }.bind(this));
  154. // }.bind(this));
  155. }else{
  156. this.uploadFile(function(){
  157. this.app.notice(this.lp.file.uploadSuccess, "success");
  158. }.bind(this));
  159. }
  160. },
  161. uploadFile: function(callback){
  162. MWF.require("MWF.widget.Upload", function(){
  163. new MWF.widget.Upload(this.app.content, {
  164. "action": MWF.Actions.get("x_portal_assemble_designer").action,
  165. "method": "uploadFile",
  166. "parameter": {"id": this.data.id},
  167. "onCompleted": function(){
  168. this.loadFileIcon();
  169. this.modifyContentFileUrl();
  170. if (callback) callback();
  171. }.bind(this),
  172. "onBeforeUpload": function(files, up){
  173. var name = files[0].name;
  174. this.nameInput.set("value", name);
  175. var data = this.getData();
  176. this.data = Object.merge(this.data, data);
  177. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(json){
  178. this.explorer.reload();
  179. up.options.parameter = {"id": json.data.id};
  180. }.bind(this), null, false);
  181. }.bind(this),
  182. "onEvery": function(json, current, count, file){
  183. debugger;
  184. //this.data.description = file.name+" "+this.getSizeText(file.size);
  185. //this.data.id = json.data.id;
  186. this.data.fileName = file.name;
  187. this.data.description = file.name+" "+this.getSizeText(file.size);
  188. this.descriptionInput.set("value", this.data.description);
  189. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data);
  190. }.bind(this)
  191. }).load();
  192. }.bind(this));
  193. },
  194. save: function(){
  195. var data = this.getData();
  196. this.data = Object.merge(this.data, data);
  197. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(){
  198. this.explorer.reload();
  199. this.app.notice(this.lp.file.saveSuccess, "success");
  200. this.destroy();
  201. }.bind(this));
  202. }
  203. });