FileExplorer.js 25 KB

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