FileExplorer.js 10 KB

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