FileExplorer.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. if (this.upload){
  35. this.upload.upload();
  36. }else{
  37. }
  38. MWF.require("MWF.widget.Upload", function(){
  39. var datas = [];
  40. new MWF.widget.Upload(this.app.content, {
  41. "action": MWF.Actions.get("x_portal_assemble_designer").action,
  42. "multiple": true,
  43. "method": "uploadFile",
  44. "parameter": {"id": ""},
  45. "onBeforeUploadEntry": function(file, up){
  46. var data = this.getNewData();
  47. data.name = file.name;
  48. data.fileName = file.name;
  49. data.description = file.name+" "+this.getSizeText(file.size);
  50. data.updateTime = (new Date()).format("db");
  51. MWF.Actions.get("x_portal_assemble_designer").saveFile(data, function(json){
  52. up.options.parameter = {"id": json.data.id};
  53. var node = this.elementContentListNode.getFirst();
  54. if (node) if (node.hasClass("noElementNode")){
  55. node.destroy();
  56. }
  57. datas.push(data);
  58. // var itemObj = this._getItemObject(data);
  59. // itemObj.load();
  60. }.bind(this), null, false);
  61. }.bind(this),
  62. "onEvery": function(json, current, count, file){
  63. var data = datas[current-1];
  64. var itemObj = this._getItemObject(data);
  65. itemObj.load();
  66. }.bind(this)
  67. }).load();
  68. }.bind(this));
  69. },
  70. _getItemObject: function(item){
  71. return new MWF.xApplication.portal.PortalManager.FileExplorer.File(this, item)
  72. }
  73. });
  74. MWF.xApplication.portal.PortalManager.FileExplorer.File = new Class({
  75. Extends: MWF.xApplication.process.ProcessManager.FileExplorer.File,
  76. _open: function(e){
  77. var _self = this;
  78. MWF.Actions.get("x_portal_assemble_designer").getFile(this.data.id, function(json){
  79. this.data = json.data;
  80. new MWF.xApplication.portal.PortalManager.FileDesigner(this.explorer, this.data);
  81. }.bind(this));
  82. },
  83. _getUrl: function(){
  84. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  85. url = url.replace(/{flag}/, this.data.id);
  86. url = url.replace(/{applicationFlag}/, this.data.portal);
  87. url = "/x_portal_assemble_surface"+url;
  88. return o2.filterUrl(MWF.Actions.getHost("x_portal_assemble_surface")+url);
  89. },
  90. _getIcon: function(){
  91. return "file.png";
  92. },
  93. _getLnkPar: function(){
  94. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  95. url = url.replace(/{flag}/, this.data.id);
  96. url = url.replace(/{applicationFlag}/, this.data.portal);
  97. url = "/x_portal_assemble_surface"+url;
  98. var href = o2.filterUrl(MWF.Actions.getHost("x_portal_assemble_surface")+url);
  99. return {
  100. "icon": this.data.iconUrl,
  101. "title": this.data.name,
  102. "par": "@url#"+href
  103. };
  104. },
  105. deleteFile: function(callback){
  106. this.explorer.app.restActions.deleteFile(this.data.id, function(){
  107. this.node.destroy();
  108. if (callback) callback();
  109. }.bind(this));
  110. }
  111. });
  112. MWF.xApplication.portal.PortalManager.FileDesigner = new Class({
  113. Extends: MWF.xApplication.process.ProcessManager.FileDesigner,
  114. getNewData: function(){
  115. return {
  116. "id": "",
  117. "name": "",
  118. "alias": "",
  119. "description": "",
  120. "portal": (this.explorer.app.options.application || this.explorer.app.application).id,
  121. "fileName": ""
  122. }
  123. },
  124. createContentFileUrl: function(){
  125. if (this.data.fileName){
  126. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  127. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": "URL"}).inject(div);
  128. this.fileUrlNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  129. div.setStyle("height", "80px");
  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. url = "/x_portal_assemble_surface"+url;
  134. this.fileUrlNode.setStyle("line-height", "18px");
  135. var href = MWF.Actions.getHost("x_portal_assemble_surface")+url;
  136. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  137. this.fileUrlNode.set("text", url);
  138. var a = new Element("div", {
  139. "styles": {"height": "30px"},
  140. "html": "<a target='_blank' href='"+o2.filterUrl(href)+"'>open</a>"
  141. }).inject(this.fileUrlNode, "bottom");
  142. }
  143. },
  144. modifyContentFileUrl: function(){
  145. if (!this.fileUrlNode){
  146. this.createContentFileUrl();
  147. }else{
  148. var url = MWF.Actions.get("x_portal_assemble_surface").action.actions.readFile.uri;
  149. url = url.replace(/{flag}/, this.data.id);
  150. url = url.replace(/{applicationFlag}/, this.data.portal);
  151. //this.fileUrlNode.set("text", "/x_processplatform_assemble_surface"+url);
  152. url = "/x_portal_assemble_surface"+url;
  153. this.fileUrlNode.setStyle("line-height", "18px");
  154. var href = MWF.Actions.getHost("x_portal_assemble_surface")+url;
  155. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  156. this.fileUrlNode.set("text", url);
  157. var a = new Element("div", {
  158. "styles": {"height": "30px"},
  159. "html": "<a target='_blank' href='"+o2.filterUrl(href)+"'>open</a>"
  160. }).inject(this.fileUrlNode, "bottom")
  161. }
  162. },
  163. upload: function(){
  164. if (!this.data.id){
  165. // var data = this.getData();
  166. // this.data = Object.merge(this.data, data);
  167. // MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(){
  168. // this.explorer.reload();
  169. this.uploadFile(function(){
  170. this.app.notice(this.lp.file.uploadSuccess, "success");
  171. }.bind(this));
  172. // }.bind(this));
  173. }else{
  174. this.uploadFile(function(){
  175. this.app.notice(this.lp.file.uploadSuccess, "success");
  176. }.bind(this));
  177. }
  178. },
  179. uploadFile: function(callback){
  180. MWF.require("MWF.widget.Upload", function(){
  181. new MWF.widget.Upload(this.app.content, {
  182. "action": MWF.Actions.get("x_portal_assemble_designer").action,
  183. "method": "uploadFile",
  184. "parameter": {"id": this.data.id},
  185. "onCompleted": function(){
  186. this.loadFileIcon();
  187. this.modifyContentFileUrl();
  188. if (callback) callback();
  189. }.bind(this),
  190. "onBeforeUpload": function(files, up){
  191. var name = files[0].name;
  192. this.nameInput.set("value", name);
  193. var data = this.getData();
  194. this.data = Object.merge(this.data, data);
  195. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(json){
  196. this.explorer.reload();
  197. up.options.parameter = {"id": json.data.id};
  198. }.bind(this), null, false);
  199. }.bind(this),
  200. "onEvery": function(json, current, count, file){
  201. debugger;
  202. //this.data.description = file.name+" "+this.getSizeText(file.size);
  203. //this.data.id = json.data.id;
  204. this.data.fileName = file.name;
  205. this.data.description = file.name+" "+this.getSizeText(file.size);
  206. this.descriptionInput.set("value", this.data.description);
  207. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data);
  208. }.bind(this)
  209. }).load();
  210. }.bind(this));
  211. },
  212. save: function(){
  213. var data = this.getData();
  214. this.data = Object.merge(this.data, data);
  215. MWF.Actions.get("x_portal_assemble_designer").saveFile(this.data, function(){
  216. this.explorer.reload();
  217. this.app.notice(this.lp.file.saveSuccess, "success");
  218. this.destroy();
  219. }.bind(this));
  220. }
  221. });