FileExplorer.js 10 KB

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