FileExplorer.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. MWF.xDesktop.requireApp("cms.ColumnManager", "Explorer", null, false);
  2. MWF.xApplication.cms.ColumnManager.FileExplorer = new Class({
  3. Extends: MWF.xApplication.cms.ColumnManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "create": MWF.CMSCM.LP.file.create,
  7. "search": MWF.CMSCM.LP.file.search,
  8. "searchText": MWF.CMSCM.LP.file.searchText,
  9. "noElement": MWF.CMSCM.LP.file.noDictionaryNoticeText,
  10. "topEnable": false
  11. },
  12. // createSearchElementNode: function(){
  13. // this.titleActionNodeNode = new Element("div", {
  14. // "styles": this.css.titleActionNode,
  15. // "text": MWF.CMSCM.LP.file.loadFiles
  16. // }).inject(this.toolbarNode);
  17. // this.titleActionNodeNode.addEvent("click", function(){
  18. // this.implodeFiles();
  19. // }.bind(this));
  20. // },
  21. getNewData: function(){
  22. return {
  23. "id": "",
  24. "name": "",
  25. "alias": "",
  26. "description": "",
  27. //"application": (this.app.options.application || this.app.application).id,
  28. "appId" : (this.app.options.application || this.app.application).id,
  29. "fileName": ""
  30. }
  31. },
  32. getSizeText: function(s){
  33. var o = [
  34. {"t": "K", "i": 1024},
  35. {"t": "M", "i": 1024*1024},
  36. {"t": "G", "i": 1024*1024*1024}
  37. ];
  38. var i = 0;
  39. var n = s/o[i].i;
  40. while (n>1000 && i<2){
  41. i++;
  42. n = s/o[i].i;
  43. }
  44. n = Math.round(n*100)/100;
  45. return ""+n+" "+o[i].t;
  46. },
  47. implodeFiles: function(){
  48. MWF.require("MWF.widget.Upload", function(){
  49. new MWF.widget.Upload(this.app.content, {
  50. "action": MWF.Actions.get("x_cms_assemble_control").action,
  51. "multiple": true,
  52. "method": "uploadFile",
  53. "parameter": {"id": ""},
  54. "onBeforeUploadEntry": function(file, up){
  55. var data = this.getNewData();
  56. data.name = file.name;
  57. data.fileName = file.name;
  58. data.description = file.name+" "+this.getSizeText(file.size);
  59. data.updateTime = (new Date()).format("db");
  60. MWF.Actions.get("x_cms_assemble_control").saveFile(data, function(json){
  61. debugger;
  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. if(this.noElementNode)this.noElementNode.hide();
  68. var itemObj = this._getItemObject(data);
  69. itemObj.load( true );
  70. }.bind(this), null, false);
  71. }.bind(this)
  72. }).load();
  73. }.bind(this));
  74. },
  75. loadContentNode: function(){
  76. this.cssPath = this.path+this.options.style+"/file.css";
  77. this.elementContentNode = new Element("div", {
  78. "styles": this.css.elementContentNode
  79. }).inject(this.node);
  80. this.elementContentNode.addEvent("click", function(){
  81. while (this.selectMarkItems.length){
  82. this.selectMarkItems[0].unSelected();
  83. }
  84. }.bind(this));
  85. this.elementContentListNode = new Element("div", {
  86. "styles": this.css.elementContentListNode
  87. }).inject(this.elementContentNode);
  88. this.elementContentListNode.loadCss(this.cssPath);
  89. this.setContentSize();
  90. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  91. },
  92. _createElement: function(e){
  93. this.implodeFiles();
  94. },
  95. _loadItemDataList: function(callback){
  96. var id = "";
  97. if (this.app.application) id = this.app.application.id;
  98. if (this.app.options.application) id = this.app.options.application.id;
  99. this.actions.listFile(id,callback);
  100. },
  101. _getItemObject: function(item){
  102. return new MWF.xApplication.cms.ColumnManager.FileExplorer.File(this, item)
  103. },
  104. setTooltip: function(){
  105. this.options.tooltip = {
  106. "create": MWF.CMSCM.LP.file.create,
  107. "search": MWF.CMSCM.LP.file.search,
  108. "searchText": MWF.CMSCM.LP.file.searchText,
  109. "noElement": MWF.CMSCM.LP.file.noScriptNoticeText
  110. };
  111. },
  112. deleteItems: function(){
  113. this.hideDeleteAction();
  114. while (this.deleteMarkItems.length){
  115. var item = this.deleteMarkItems.shift();
  116. if (this.deleteMarkItems.length){
  117. item.deleteFile();
  118. }else{
  119. item.deleteFile(function(){
  120. }.bind(this));
  121. }
  122. }
  123. },
  124. destroy: function(){
  125. this.node.destroy();
  126. o2.removeCss(this.cssPath);
  127. o2.release(this);
  128. },
  129. getIconJson: function(callback){
  130. if (!this.icons){
  131. MWF.getJSON("../x_component_File/$Main/icon.json", function(json){
  132. this.icons = json;
  133. if (callback) callback();
  134. }.bind(this), false, false);
  135. }else{
  136. if (callback) callback();
  137. }
  138. },
  139. getIcon: function(fileName){
  140. this.getIconJson();
  141. var ext = fileName.substring(fileName.lastIndexOf(".")+1, fileName.length);
  142. if (!ext) ext="unkonw";
  143. var iconName = this.icons[ext.toLowerCase()] || this.icons.unknow;
  144. return "../x_component_File/$Main/default/file/"+iconName;
  145. }
  146. });
  147. MWF.xApplication.cms.ColumnManager.FileExplorer.File = new Class({
  148. Extends: MWF.xApplication.cms.ColumnManager.Explorer.Item,
  149. // load: function( wait ){
  150. // if( wait ){
  151. // window.setTimeout(function () {
  152. // this._load();
  153. // }.bind(this), 100)
  154. // }else{
  155. // this._load();
  156. // }
  157. // },
  158. reset: function( data ){
  159. this.data = data;
  160. var node = new Element("div.o2_fileItemNode", {
  161. "events": {
  162. "mouseover": function(){
  163. if (this.deleteActionNode) this.deleteActionNode.fade("in");
  164. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  165. }.bind(this),
  166. "mouseout": function(){
  167. if (this.deleteActionNode) this.deleteActionNode.fade("out");
  168. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  169. }.bind(this)
  170. }
  171. }).inject(this.node, "after");
  172. this.node.destroy();
  173. this.node = node;
  174. this.load(true);
  175. },
  176. load: function( checkIcon ){
  177. var view = this.explorer.path+this.explorer.options.style+"/file.html";
  178. if(!this.node)this.node = new Element("div.o2_fileItemNode", {
  179. "events": {
  180. "mouseover": function(){
  181. if (this.deleteActionNode) this.deleteActionNode.fade("in");
  182. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  183. }.bind(this),
  184. "mouseout": function(){
  185. if (this.deleteActionNode) this.deleteActionNode.fade("out");
  186. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  187. }.bind(this)
  188. }
  189. }).inject(this.container);
  190. if (this.data.name.icon) this.icon = this.data.name.icon;
  191. var ext = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length);
  192. this.data.fileUrl = this._getUrl();
  193. if (this.data.fileUrl && ["png","jpg","bmp","gif","jpeg","jpe"].indexOf(ext)!==-1){
  194. //new Image()
  195. this.data.iconUrl = this.data.fileUrl;
  196. }else{
  197. this.data.iconUrl = this.explorer.getIcon(this.data.fileName);
  198. }
  199. //this.data.iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  200. this.node.loadHtml(view, {"bind": this.data}, function(){
  201. var itemIconNode = this.node.getElement(".o2_fileItemIconNode");
  202. var itemImgNode = this.node.getElement(".o2_fileItemImgNode");
  203. this.itemImgNode = itemImgNode;
  204. var itemUrlNode = this.node.getElement(".o2_fileItemUrlNode");
  205. itemUrlNode.setStyle("-webkit-user-select", "text");
  206. var s = itemIconNode.getSize();
  207. // if (!s.x) s.x = itemIconNode.getStyle("width").toFloat();
  208. // if (!s.y) s.y = itemIconNode.getStyle("height").toFloat();
  209. itemImgNode.setStyles({
  210. "max-width": ""+s.x+"px",
  211. "max-height": ""+s.y+"px"
  212. });
  213. this.deleteActionNode = this.node.getElement(".o2_fileDeleteActionNode");
  214. var itemTextTitleNode = this.node.getElement(".o2_fileItemTextTitleNode");
  215. itemIconNode.addEvent("click", function(e){
  216. this.toggleSelected();
  217. e.stopPropagation();
  218. }.bind(this));
  219. itemIconNode.makeLnk({
  220. "par": this._getLnkPar()
  221. });
  222. if( checkIcon ){
  223. this.setIcon();
  224. }else{
  225. itemImgNode.set("src", this.data.iconUrl);
  226. }
  227. if (!this.explorer.options.noDelete) this._createActions();
  228. itemTextTitleNode.addEvent("click", function(e){
  229. this._open(e);
  230. e.stopPropagation();
  231. }.bind(this));
  232. this._customNodes();
  233. this._isNew();
  234. }.bind(this));
  235. },
  236. // resetIcon: function(){
  237. // this.itemImgNode.set("src", "");
  238. // this.setIcon();
  239. // },
  240. setIcon: function(){
  241. this.itemImgNode.addEvents({
  242. "error": function () {
  243. window.setTimeout( function () {
  244. this.itemImgNode.set("src", this.data.iconUrl+ "?"+new Date().getMilliseconds())
  245. }.bind(this), 1000 )
  246. }.bind(this)
  247. })
  248. window.setTimeout( function () {
  249. this.itemImgNode.set("src", this.data.iconUrl + "?"+new Date().getMilliseconds())
  250. }.bind(this), 1000 )
  251. },
  252. _createActions: function(){
  253. if (this.deleteActionNode) this.deleteActionNode.addEvent("click", function(e){
  254. this.deleteItem(e);
  255. }.bind(this));
  256. },
  257. _customNodes: function(){},
  258. _open: function(e){
  259. var _self = this;
  260. MWF.Actions.get("x_cms_assemble_control").getFile(this.data.id, function(json){
  261. this.data = json.data;
  262. new MWF.xApplication.cms.ColumnManager.FileDesigner(this.explorer, this.data, this);
  263. }.bind(this));
  264. },
  265. _getIcon: function(){
  266. return "file.png";
  267. },
  268. _getUrl: function(){
  269. debugger;
  270. var url = MWF.Actions.get("x_cms_assemble_control").action.actions.readFile.uri;
  271. url = url.replace(/{flag}/, this.data.id);
  272. url = url.replace(/{applicationFlag}/, this.data.application || this.data.appId);
  273. url = "/x_cms_assemble_control"+url;
  274. return o2.filterUrl(MWF.Actions.getHost("x_cms_assemble_control")+url);
  275. },
  276. _getLnkPar: function(){
  277. return {
  278. "icon": this.data.iconUrl,
  279. "title": this.data.name,
  280. "par": "@url#"+this._getUrl()
  281. };
  282. },
  283. deleteFile: function(callback){
  284. this.explorer.app.restActions.deleteFile(this.data.id, function(){
  285. this.node.destroy();
  286. if (callback) callback();
  287. }.bind(this));
  288. },
  289. selected: function(){
  290. if (this.deleteMode) this.deleteItem();
  291. this.isSelected = true;
  292. this.node.setStyles(this.explorer.css.itemNode_selected);
  293. this.explorer.selectMarkItems.push(this);
  294. }
  295. });
  296. MWF.xApplication.cms.ColumnManager.FileDesigner = new Class({
  297. initialize: function(explorer, item, fileItem){
  298. this.explorer = explorer;
  299. this.app = this.explorer.app;
  300. this.data = item;
  301. this.fileItem = fileItem;
  302. this.container = this.explorer.container;
  303. this.css = this.explorer.css;
  304. this.lp = MWF.CMSCM.LP;
  305. this.load();
  306. },
  307. getNewData: function(){
  308. return {
  309. "id": "",
  310. "name": "",
  311. "alias": "",
  312. "description": "",
  313. //"application": (this.explorer.app.options.application || this.explorer.app.application).id,
  314. "appId": (this.explorer.app.options.application || this.explorer.app.application).id,
  315. "fileName": ""
  316. }
  317. },
  318. resize: function(){
  319. var size = this.app.content.getSize();
  320. var nodeSize = this.fileAreaNode.getSize();
  321. var x = (size.x-nodeSize.x)/2;
  322. var y = (size.y-nodeSize.y)/2;
  323. if (y<0) y=0;
  324. if (x<0) x=0;
  325. this.fileAreaNode.setStyles({
  326. "top": ""+y+"px",
  327. "left": ""+x+"px"
  328. });
  329. var titleSize = this.titleNode.getSize();
  330. var buttonSize = this.buttonNode.getSize();
  331. var h = nodeSize.y-titleSize.y-buttonSize.y;
  332. this.contentNode.setStyle("height", ""+h+"px");
  333. },
  334. load: function(){
  335. if (!this.data) this.data = this.getNewData();
  336. this.fileMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  337. this.fileAreaNode = new Element("div", {"styles": this.css.createTemplateAreaNode}).inject(this.app.content);
  338. this.fileAreaNode.fade("in");
  339. this.titleNode = new Element("div", {"styles": this.css.fileDesignerTitleNode}).inject(this.fileAreaNode);
  340. this.titleIconNode = new Element("div", {"styles": this.css.fileDesignerTitleIconNode}).inject(this.titleNode);
  341. if (!this.data.id) this.titleIconNode.setStyle("background-image", "url("+this.explorer.path+this.app.options.style+"/icon/new.png)");
  342. this.titleTextNode = new Element("div", {"styles": this.css.fileDesignerTitleTextNode}).inject(this.titleNode);
  343. var title = (this.data.name) ? this.data.name : this.explorer.options.tooltip.create;
  344. this.titleTextNode.set("text", title);
  345. this.contentNode = new Element("div", {"styles": this.css.fileDesignerContentNode}).inject(this.fileAreaNode);
  346. this.createContent();
  347. this.buttonNode = new Element("div", {"styles": this.css.fileDesignerButtonNode}).inject(this.fileAreaNode);
  348. this.createButton();
  349. this.resizeFun = this.resize.bind(this);
  350. this.resizeFun();
  351. this.app.addEvent("resize", this.resizeFun);
  352. this.setEvent();
  353. },
  354. createContent: function(){
  355. this.contentAreaNode = new Element("div", {"styles": this.css.fileDesignerContentAreaNode}).inject(this.contentNode);
  356. this.nameInput = this.createContentLine(this.lp.name, this.data.name);
  357. this.aliasInput = this.createContentLine(this.lp.alias, this.data.alias);
  358. this.descriptionInput = this.createContentLine(this.lp.file.description, this.data.description, true);
  359. this.createContentFile();
  360. this.createContentFileUrl();
  361. },
  362. createContentFileUrl: function(){
  363. if (this.data.fileName){
  364. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  365. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": "URL"}).inject(div);
  366. this.fileUrlNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  367. div.setStyle("height", "80px");
  368. var url = MWF.Actions.get("x_cms_assemble_control").action.actions.readFile.uri;
  369. url = url.replace(/{flag}/, this.data.id);
  370. url = url.replace(/{applicationFlag}/, this.data.application || this.data.appId);
  371. url = "/x_cms_assemble_control"+url;
  372. this.fileUrlNode.setStyle("line-height", "18px");
  373. var href = MWF.Actions.getHost("x_cms_assemble_control")+url;
  374. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  375. this.fileUrlNode.set("text", url);
  376. var a = new Element("div", {
  377. "styles": {"height": "30px"},
  378. "html": "<a target='_blank' href='"+o2.filterUrl(href)+"'>open</a>"
  379. }).inject(this.fileUrlNode, "bottom");
  380. }
  381. },
  382. modifyContentFileUrl: function(){
  383. if (!this.fileUrlNode){
  384. this.createContentFileUrl();
  385. }else{
  386. var url = MWF.Actions.get("x_cms_assemble_control").action.actions.readFile.uri;
  387. url = url.replace(/{flag}/, this.data.id);
  388. url = url.replace(/{applicationFlag}/, this.data.application || this.data.appId);
  389. //this.fileUrlNode.set("text", "/x_cms_assemble_control"+url);
  390. url = "/x_cms_assemble_control"+url;
  391. this.fileUrlNode.setStyle("line-height", "18px");
  392. var href = MWF.Actions.getHost("x_cms_assemble_control")+url;
  393. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  394. this.fileUrlNode.set("text", url);
  395. var a = new Element("div", {
  396. "styles": {"height": "30px"},
  397. "html": "<a target='_blank' href='"+o2.filterUrl(href)+"'>open</a>"
  398. }).inject(this.fileUrlNode, "bottom");
  399. }
  400. },
  401. createContentFile: function(){
  402. var div = new Element("div", {"styles": this.css.fileDesignerContentFileLineNode}).inject(this.contentAreaNode);
  403. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineTitleNode, "text": this.lp.attachment}).inject(div);
  404. var lineRightNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineRightNode}).inject(div);
  405. this.fileContentNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineContentNode}).inject(div);
  406. this.uploadFileButton = new Element("div", {"styles": this.css.fileDesignerUploadButtonNode, "text": this.lp.upload}).inject(lineRightNode);
  407. if (this.data.fileName){
  408. this.loadFileIcon();
  409. }
  410. },
  411. // getIconJson: function(callback){
  412. // if (!this.icons){
  413. // MWF.getJSON("../x_component_File/$Main/icon.json", function(json){
  414. // this.icons = json;
  415. // if (callback) callback();
  416. // }.bind(this), false, false);
  417. // }else{
  418. // if (callback) callback();
  419. // }
  420. // },
  421. // getIcon: function(ext){
  422. // if (!ext) ext="unkonw";
  423. // var iconName = this.icons[ext.toLowerCase()] || this.icons.unknow;
  424. // return "../x_component_File/$Main/default/file/"+iconName;
  425. // },
  426. loadFileIcon: function(){
  427. debugger;
  428. this.fileContentNode.empty();
  429. //var ext = this.data.fileName.substr(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length);
  430. //this.explorer.getIconJson(function(){
  431. var url = this.explorer.getIcon(this.data.fileName);
  432. var fileIconNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileIconNode}).inject(this.fileContentNode);
  433. fileIconNode.setStyle("background-image", "url('"+url+"')");
  434. var fileTextNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileNameNode, "text": this.data.fileName}).inject(this.fileContentNode);
  435. var fileSizeNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileSizeNode, "text": this.data.description}).inject(this.fileContentNode);
  436. //}.bind(this));
  437. },
  438. createContentLine: function(text, value, readonly){
  439. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  440. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": text}).inject(div);
  441. var lineContentNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  442. return new Element("input", {"styles": this.css.fileDesignerContentLineInputNode, "value": value, "readonly": readonly}).inject(lineContentNode);
  443. },
  444. createButton: function(){
  445. this.cancelButton = new Element("div", {"styles": this.css.fileDesignerCancelButtonNode, "text": this.lp.cancel}).inject(this.buttonNode);
  446. this.okButton = new Element("div", {"styles": this.css.fileDesignerOkButtonNode, "text": this.lp.ok}).inject(this.buttonNode);
  447. },
  448. setEvent: function(){
  449. this.cancelButton.addEvent("click", function(e){ this.close(e); }.bind(this));
  450. this.okButton.addEvent("click", function(){ this.save(); }.bind(this));
  451. this.uploadFileButton.addEvent("click", function(){ this.upload(); }.bind(this));
  452. },
  453. upload: function(){
  454. if (!this.data.id){
  455. //MWF.Actions.get("x_cms_assemble_control").saveFile(this.data, function(){
  456. // this.explorer.reload();
  457. this.uploadFile(function(){
  458. this.app.notice(this.lp.file.uploadSuccess, "success");
  459. }.bind(this));
  460. //}.bind(this));
  461. }else{
  462. this.uploadFile(function(){
  463. this.app.notice(this.lp.file.uploadSuccess, "success");
  464. }.bind(this));
  465. }
  466. },
  467. uploadFile: function(callback){
  468. MWF.require("MWF.widget.Upload", function(){
  469. new MWF.widget.Upload(this.app.content, {
  470. "action": MWF.Actions.get("x_cms_assemble_control").action,
  471. "multiple": false,
  472. "method": "uploadFile",
  473. "parameter": {"id": this.data.id},
  474. "onCompleted": function(){
  475. this.loadFileIcon();
  476. this.modifyContentFileUrl();
  477. // this.explorer.reload();
  478. if (callback) callback();
  479. }.bind(this),
  480. "onBeforeUpload": function(files, up){
  481. var name = files[0].name;
  482. this.nameInput.set("value", name);
  483. var data = this.getData();
  484. this.data = Object.merge(this.data, data);
  485. MWF.Actions.get("x_cms_assemble_control").saveFile(this.data, function(json){
  486. // this.explorer.reload();
  487. up.options.parameter = {"id": json.data.id};
  488. }.bind(this), null, false);
  489. }.bind(this),
  490. "onEvery": function(json, current, count, file){
  491. //this.data.description = file.name+" "+this.getSizeText(file.size);
  492. //this.data.id = json.data.id;
  493. this.data.fileName = file.name;
  494. this.data.description = file.name+" "+this.getSizeText(file.size);
  495. this.descriptionInput.set("value", this.data.description);
  496. MWF.Actions.get("x_cms_assemble_control").saveFile(this.data);
  497. }.bind(this)
  498. }).load();
  499. }.bind(this));
  500. },
  501. getSizeText: function(s){
  502. var o = [
  503. {"t": "K", "i": 1024},
  504. {"t": "M", "i": 1024*1024},
  505. {"t": "G", "i": 1024*1024*1024}
  506. ];
  507. var i = 0;
  508. var n = s/o[i].i;
  509. while (n>1000 && i<2){
  510. i++;
  511. n = s/o[i].i;
  512. }
  513. n = Math.round(n*100)/100;
  514. return ""+n+" "+o[i].t;
  515. },
  516. getData: function(){
  517. return {
  518. "name": this.nameInput.get("value"),
  519. "alias": this.aliasInput.get("value"),
  520. "description": this.descriptionInput.get("value")
  521. }
  522. },
  523. close: function(e){
  524. var data = this.getData();
  525. var _self = this;
  526. if (data.name!==this.data.name || data.alias!==this.data.alias || data.description!== this.data.description){
  527. this.app.confirm("infor", e, this.lp.file.saveConfirm, this.lp.file.saveConfirmText, 350, 120, function(){
  528. this.close();
  529. _self.save();
  530. }, function(){
  531. this.close();
  532. _self.destroy();
  533. })
  534. }else{
  535. this.destroy();
  536. }
  537. },
  538. save: function(){
  539. var data = this.getData();
  540. this.data = Object.merge(this.data, data);
  541. MWF.Actions.get("x_cms_assemble_control").saveFile(this.data, function(){
  542. // this.explorer.reload();
  543. if( this.fileItem && this.fileItem.reset ){
  544. this.fileItem.reset( this.data );
  545. }
  546. this.app.notice(this.lp.file.saveSuccess, "success");
  547. this.destroy();
  548. }.bind(this));
  549. },
  550. destroy: function(){
  551. this.fileMaskNode.destroy();
  552. this.fileAreaNode.destroy();
  553. if (this.resizeFun) this.app.removeEvent("resize", this.resizeFun);
  554. MWF.release(this);
  555. }
  556. });