MainMenu.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. MWF.xApplication.MinderEditor.MainMenu = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "defaultAction" : "openRecentFiles"
  7. },
  8. initialize : function( container, app, options){
  9. this.setOptions( options );
  10. this.container = container;
  11. this.app = app;
  12. //this.css = this.app.css;
  13. this.lp = this.app.lp;
  14. this.isHidden = false;
  15. this.path = "../x_component_MinderEditor/$MainMenu/";
  16. this.cssPath = "../x_component_MinderEditor/$MainMenu/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.itemJson = [
  19. {
  20. text : "新建",
  21. action : "openCreate",
  22. hasContent : false
  23. },
  24. {
  25. text : "打开",
  26. action : "openRecentFiles",
  27. hasContent : true
  28. },
  29. {
  30. text : "另存为",
  31. action : "openSaveAs",
  32. hasContent : true
  33. },
  34. {
  35. text : "共享",
  36. action : "openShare",
  37. hasContent : true
  38. },
  39. {
  40. text : "历史版本",
  41. action : "openFileVersion",
  42. hasContent : true
  43. }
  44. ];
  45. this.load();
  46. },
  47. load : function(){
  48. this.maskNode = new Element("div.maskNode",{
  49. "styles": this.css.maskNode,
  50. events : {
  51. mousedown : function( ev ){
  52. this.hide();
  53. }.bind(this)
  54. }
  55. }).inject(this.container);
  56. this.node = new Element("div.MainMenu", {
  57. "styles": this.css.node,
  58. events : {
  59. mousedown : function( ev ){
  60. ev.stopPropagation();
  61. }
  62. }
  63. }).inject(this.container);
  64. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  65. this.rightContentNode = new Element("div", {"styles": this.css.rightContentNode}).inject(this.node);
  66. this.loadItems();
  67. this.show();
  68. this.resetNodeSizeFun = this.resetNodeSize.bind(this);
  69. this.app.addEvent("resize", this.resetNodeSizeFun );
  70. },
  71. //show : function(){
  72. // this.node.setStyle("display","");
  73. // this.rightNode.setStyle("display","none");
  74. // this.fireEvent("show");
  75. // this.resetNodeSize();
  76. //},
  77. //hide : function(){
  78. // this.node.setStyle("display","");
  79. // this.rightNode.setStyle("display","none");
  80. // this.fireEvent("hide");
  81. //},
  82. loadItems : function(){
  83. var _self = this;
  84. this.itemContainer = new Element("div", {"styles": this.css.itemContainer}).inject(this.contentNode);
  85. this.menuItem = {};
  86. this.itemJson.each( function( item ){
  87. var itemNode = new Element("div", {
  88. "styles": this.css.itemNode,
  89. "text" : item.text
  90. }).inject(this.contentNode);
  91. itemNode.addEvents( {
  92. mouseover : function(){
  93. if( _self.currentItemNode != this )this.setStyles( _self.css.itemNode_over )
  94. },
  95. mouseout : function(){
  96. if( _self.currentItemNode != this )this.setStyles( _self.css.itemNode )
  97. },
  98. click : function(){
  99. _self.setCurrentItemNode( this, item.action, item );
  100. }
  101. });
  102. this.menuItem[ item.action ] = itemNode;
  103. if( item.action == (this.app.options.menuAction || this.options.defaultAction) )itemNode.click();
  104. }.bind(this))
  105. },
  106. setCurrentItemNode : function( node , action, item ){
  107. if( this.currentItemNode && item.hasContent ){
  108. this.currentItemNode.setStyles( this.css.itemNode );
  109. }
  110. if( this[action] ){
  111. this[action]();
  112. }
  113. if( item.hasContent ){
  114. this.currentItemNode = node;
  115. node.setStyles( this.css.itemNode_current );
  116. }
  117. },
  118. trigger : function(){
  119. this.isHidden ? this.show( true ) : this.hide( true )
  120. },
  121. hide: function( isFireEvent ){
  122. this.maskNode.setStyle("display","none");
  123. this.isHidden = true;
  124. this.node.setStyle("display", "none");
  125. this.fireEvent("hide");
  126. //var x = this.node.getSize().x + 9;
  127. //var fx = new Fx.Morph(this.node, {
  128. // "duration": "300",
  129. // "transition": Fx.Transitions.Expo.easeOut
  130. //});
  131. //fx.start({
  132. // "opacity": 0
  133. //}).chain(function(){
  134. // this.isHidden = true;
  135. // //this.node.setStyle("display", "none");
  136. // this.node.setStyles({
  137. // "left": "-"+x+"px"
  138. // });
  139. // this.fireEvent("hide");
  140. //}.bind(this));
  141. },
  142. show: function( action ){
  143. if( action ){
  144. this.menuItem[ action ].click()
  145. }else if( this.currentItemNode ){
  146. this.currentItemNode.click();
  147. }
  148. this.resetNodeSize();
  149. this.maskNode.setStyle("display","");
  150. this.isHidden = false;
  151. this.node.setStyles({"display":""});
  152. this.fireEvent("show");
  153. //this.resetNodeSize();
  154. //var fx = new Fx.Morph(this.node, {
  155. // "duration": "500",
  156. // "transition": Fx.Transitions.Expo.easeOut
  157. //});
  158. //fx.start({
  159. // "opacity": 1
  160. //}).chain(function(){
  161. // this.node.setStyles({
  162. // "left": "0px"
  163. // });
  164. // this.fireEvent("show");
  165. // this.isHidden = false;
  166. //}.bind(this))
  167. },
  168. resetNodeSize: function(){
  169. var size = this.container.getSize();
  170. this.contentNode.setStyle("height", size.y - 84 );
  171. this.rightContentNode.setStyle("height", size.y - 86 );
  172. this.setShareRecordListHeight();
  173. this.setFileVersionListHeight();
  174. //this.trapezoid.setStyle("top", ( (size.y - 50)/2 - this.trapezoid.getSize().y/2 ));
  175. //var y = size.y - 395;
  176. //var meetContainerY = this.meetingItemContainer.getSize().y + 12;
  177. //this.scrollNode.setStyle("height", Math.min( y, meetContainerY ) );
  178. },
  179. setShareRecordListHeight : function(){
  180. if( this.shareRecordList ){
  181. var size = this.container.getSize();
  182. this.shareRecordList.setStyle("height", size.y - 256 );
  183. }
  184. },
  185. setFileVersionListHeight : function(){
  186. if( this.fileVersionList ){
  187. var size = this.container.getSize();
  188. this.fileVersionList.setStyle("height", size.y - 156 );
  189. }
  190. },
  191. getSize : function(){
  192. //var size = this.node.getSize();
  193. //return {
  194. // x : this.isHidden ? 9 : size.x,
  195. // y : size.y
  196. //}
  197. return { x : 9, y : 0 }
  198. },
  199. empty : function(){
  200. this.shareRecordList = null;
  201. this.fileVersionList = null;
  202. this.rightContentNode.empty();
  203. },
  204. reload : function(){
  205. this.destory();
  206. },
  207. destory : function(){
  208. this.maskNode.destroy();
  209. this.app.removeEvent("resize", this.resetNodeSizeFun );
  210. //this.app.node.removeEvent("mousedown", this.hideFun);
  211. this.node.destory();
  212. },
  213. openRecentFiles : function(){
  214. var _self = this;
  215. this.empty();
  216. new Element("div.rightTitleNode", {
  217. "text" : "打开",
  218. "styles" : this.css.rightTitleNode
  219. }).inject( this.rightContentNode );
  220. var listTitle = new Element("div.listTitle", {
  221. "text" : "最近修改的文件",
  222. "styles" : this.css.listTitle
  223. }).inject( this.rightContentNode );
  224. var documentArea = new Element("div.listArea", {
  225. "styles" : this.css.documentArea
  226. }).inject( this.rightContentNode );
  227. this.app.restActions.listNextMindWithFilter( "(0)", 5, { orderField : "updateTime", orderType : "DESC" }, function( json ){
  228. (json.data || []).each( function( d ){
  229. var documentNode = new Element("div.documentNode", {
  230. "styles" : this.css.documentNode
  231. }).inject( documentArea );
  232. documentNode.addEvents( {
  233. "mouseover" : function(){
  234. documentNode.setStyles( this.css.documentNode_over )
  235. }.bind(this),
  236. "mouseout" : function(){
  237. documentNode.setStyles( this.css.documentNode )
  238. }.bind(this),
  239. "click" : function(){
  240. this.openMinder( d );
  241. this.hide();
  242. }.bind(this)
  243. });
  244. var iconNode = Element("div.documentIconNode", {
  245. "styles" : this.css.documentIconNode
  246. }).inject( documentNode );
  247. var rightNode = Element("div.documentRightNode", {
  248. "styles" : this.css.documentRightNode
  249. }).inject( documentNode );
  250. Element("div.documentTextNode", {
  251. "text" : d.name,
  252. "styles" : this.css.documentTextNode
  253. }).inject( rightNode );
  254. Element("div.documentMemoNode", {
  255. "text" : "修改于"+d.updateTime,
  256. "styles" : this.css.documentMemoNode
  257. }).inject( rightNode );
  258. }.bind(this));
  259. if( !json.data || json.data.length == 0 ){
  260. new Element("div.listItemTextNode", {
  261. "text" : "没有找到最近修改的文件",
  262. "styles" : this.css.listItemTextNode
  263. }).inject( documentArea );
  264. }else{
  265. var action = new Element("div.listItemActionNode", {
  266. "text" : "打开列表,查看更多文件",
  267. "styles" : this.css.listItemActionNode,
  268. "events" : {
  269. "mouseover" : function(){
  270. this.setStyles( _self.css.listItemActionNode_over )
  271. },
  272. "mouseout" : function(){
  273. this.setStyles( _self.css.listItemActionNode )
  274. },
  275. "click" : function(ev){
  276. _self.openMinderList(ev);
  277. _self.hide();
  278. }
  279. }
  280. }).inject( documentArea );
  281. action.setStyle("margin-top", "10px");
  282. }
  283. }.bind(this));
  284. // var actionArea = new Element("div.rightActionArea", {
  285. // "styles" : this.css.rightActionArea
  286. // }).inject( this.rightContentNode );
  287. // this.createActionNode( actionArea, "import", "打开本地文件", "上传本地脑图文件,并用脑图编辑", function(){
  288. // this.app.openSaveAsDialog();
  289. // this.hide();
  290. // }.bind(this) );
  291. },
  292. openMinderList : function( documentData ){
  293. var appId = "Minder";
  294. if (this.app.desktop.apps[appId]){
  295. this.app.desktop.apps[appId].setCurrent();
  296. }else {
  297. this.app.desktop.openApplication(null, "Minder", {
  298. "appId" : appId
  299. });
  300. }
  301. },
  302. openMinder : function( documentData ){
  303. var appId = "MinderEditor"+documentData.id;
  304. if (this.app.desktop.apps[appId]){
  305. this.app.desktop.apps[appId].setCurrent();
  306. }else {
  307. this.app.desktop.openApplication(null, "MinderEditor", {
  308. "appId" : appId,
  309. "folderId" : documentData.folderId,
  310. "id" : documentData.id,
  311. "isEdited" : true,
  312. "isNew" : false
  313. });
  314. }
  315. },
  316. openCreate : function(){
  317. this.app.openNewMinderDialog();
  318. this.hide();
  319. },
  320. openSaveAs : function(){
  321. this.empty();
  322. new Element("div.rightTitleNode", {
  323. "text" : "另存为",
  324. "styles" : this.css.rightTitleNode
  325. }).inject( this.rightContentNode );
  326. var actionArea = new Element("div.rightActionArea", {
  327. "styles" : this.css.rightActionArea
  328. }).inject( this.rightContentNode );
  329. this.createActionNode( actionArea, "saveas", "另存为", "保存副本到文件夹", function(){
  330. this.app.openSaveAsDialog();
  331. this.hide();
  332. }.bind(this) );
  333. this.createActionNode( actionArea, "edit", "重命名", "重命名此文件", function(){
  334. this.app.openRenameDialog();
  335. this.hide();
  336. }.bind(this) );
  337. this.createActionNode( actionArea, "download", "导出", "导出图片到本地", function(){
  338. // this.app.openExportDialog();
  339. this.exportAsImage();
  340. this.hide();
  341. }.bind(this));
  342. },
  343. exportAsImage : function(){
  344. var title = this.app.minder.getRoot().getText();
  345. var converter = new MWF.xApplication.MinderEditor.Converter(this.app, this.app.minder, {
  346. "background": "#ffffff",
  347. "zoom": 2
  348. });
  349. converter.toPng(null, null, function( img ){
  350. var id = this.app.data.id;
  351. var formData = new FormData();
  352. formData.append('file', img, title+".png");
  353. formData.append('site', id);
  354. debugger;
  355. MWF.xDesktop.uploadImageByScale( id, "mindInfo", -1, formData, img,
  356. function(json){
  357. var url = o2.Actions.load("x_file_assemble_control").FileAction.action.actions.downloadStream.uri.replace( "{id}", json.data.id );
  358. url = o2.filterUrl( o2.Actions.load("x_file_assemble_control").FileAction.action.getAddress() + url);
  359. window.open(url);
  360. }.bind(this)
  361. );
  362. }.bind(this), function(){
  363. this.app.notice("抱歉,脑图中有外网图片,无法导出","error")
  364. }.bind(this))
  365. },
  366. openFileVersion : function(){
  367. var _self = this;
  368. this.empty();
  369. new Element("div.rightTitleNode", {
  370. "text" : "历史版本",
  371. "styles" : this.css.rightTitleNode
  372. }).inject( this.rightContentNode );
  373. //var listTitle = new Element("div.listTitle", {
  374. // "text" : "分享记录",
  375. // "styles" : this.css.listTitle
  376. //}).inject( this.rightContentNode );
  377. var listArea = this.fileVersionList = new Element("div.listArea", {
  378. "styles" : this.css.listArea
  379. }).inject( this.rightContentNode );
  380. if( this.app.data.id ){
  381. this.app.restActions.listVersionsWithMindId( this.app.data.id, function( json ){
  382. (json.data || []).each( function( d ){
  383. var listItemNode = new Element("div.listItemNode", {
  384. "styles" : this.css.listItemNode
  385. }).inject( listArea );
  386. new Element("div.listItemTextNode", {
  387. "text" : d.creator.split("@")[0] + "创建于" + d.createTime ,
  388. "styles" : this.css.listItemTextNode
  389. }).inject( listItemNode );
  390. if( this.app.userName == d.creator ){
  391. new Element("div.listItemActionNode", {
  392. "text" : "还原",
  393. "styles" : this.css.listItemActionNode,
  394. "events" : {
  395. "mouseover" : function(){
  396. this.setStyles( _self.css.listItemActionNode_over )
  397. },
  398. "mouseout" : function(){
  399. this.setStyles( _self.css.listItemActionNode )
  400. },
  401. "click" : function(ev){
  402. _self.restoreVersion(ev, d );
  403. }
  404. }
  405. }).inject( listItemNode );
  406. }
  407. this.setFileVersionListHeight();
  408. }.bind(this));
  409. if( !json.data || json.data.length == 0 ){
  410. new Element("div.listItemTextNode", {
  411. "text" : "没有找到历史版本",
  412. "styles" : this.css.listItemTextNode
  413. }).inject( listArea );
  414. }
  415. }.bind(this))
  416. }else{
  417. new Element("div.listItemTextNode", {
  418. "text" : "没有找到历史版本",
  419. "styles" : this.css.listItemTextNode
  420. }).inject( listArea );
  421. }
  422. },
  423. restoreVersion : function( ev, data ){
  424. this.app.restActions.viewMindVersionWithId( data.id, function( json ){
  425. this.app.isMovingCenter = true;
  426. this.app.data.content = json.data.content ? JSON.parse(json.data.content) : { content : { data : {} } };
  427. this.app.minder.importJson(this.app.data.content);
  428. }.bind(this))
  429. },
  430. openShare : function(){
  431. var _self = this;
  432. this.empty();
  433. new Element("div.rightTitleNode", {
  434. "text" : "共享",
  435. "styles" : this.css.rightTitleNode
  436. }).inject( this.rightContentNode );
  437. var actionArea = new Element("div.rightActionArea", {
  438. "styles" : this.css.rightActionArea
  439. }).inject( this.rightContentNode );
  440. this.createActionNode( actionArea, "share", "分享", "邀请其他人查看文件", function(){
  441. this.app.openShareDialog();
  442. this.hide();
  443. }.bind(this));
  444. var listTitle = new Element("div.listTitle", {
  445. "text" : "分享记录",
  446. "styles" : this.css.listTitle
  447. }).inject( this.rightContentNode );
  448. this.documentArea = this.shareRecordList = new Element("div.documentArea", {
  449. "styles" : this.css.documentArea
  450. }).inject( this.rightContentNode );
  451. if( this.app.data.id ){
  452. this.loadShareRecordList()
  453. }else{
  454. new Element("div.listItemTextNode", {
  455. "text" : "没有找到分享记录",
  456. "styles" : this.css.listItemTextNode
  457. }).inject( this.documentArea );
  458. }
  459. },
  460. loadShareRecordList : function(){
  461. var _self = this;
  462. this.documentArea.empty();
  463. this.app.restActions.listShareRecordsWithMindId( this.app.data.id, function( json ){
  464. //(json.data || []).each( function( d ){
  465. //var listItemNode = new Element("div.listItemNode", {
  466. // "styles" : this.css.listItemNode
  467. //}).inject( this.listArea );
  468. //
  469. //new Element("div.listItemTextNode", {
  470. // "text" : d.source.split("@")[0] + "于" + d.createTime + "分享给" + d.target.split("@")[0],
  471. // "styles" : this.css.listItemTextNode
  472. //}).inject( listItemNode );
  473. //
  474. //if( this.app.userName == d.source ){
  475. // new Element("div.listItemActionNode", {
  476. // "text" : "取消分享",
  477. // "styles" : this.css.listItemActionNode,
  478. // "events" : {
  479. // "mouseover" : function(){
  480. // this.setStyles( _self.css.listItemActionNode_over )
  481. // },
  482. // "mouseout" : function(){
  483. // this.setStyles( _self.css.listItemActionNode )
  484. // },
  485. // "click" : function(ev){
  486. // _self.cancelShare(ev, d );
  487. // }
  488. // }
  489. // }).inject( listItemNode );
  490. //}
  491. (json.data || []).each( function( d ){
  492. var documentNode = new Element("div.documentNode", {
  493. "styles" : this.css.documentNode
  494. }).inject( this.documentArea );
  495. documentNode.addEvents( {
  496. "mouseover" : function(){
  497. documentNode.setStyles( this.css.documentNode_over )
  498. }.bind(this),
  499. "mouseout" : function(){
  500. documentNode.setStyles( this.css.documentNode )
  501. }.bind(this)
  502. });
  503. //var iconNode = Element("div.documentIconNode", {
  504. // "styles" : this.css.documentIconNode
  505. //}).inject( documentNode );
  506. var rightNode = Element("div.documentRightNode", {
  507. "styles" : this.css.documentRightNode
  508. }).inject( documentNode );
  509. Element("div.documentTextNode", {
  510. "text" : d.source.split("@")[0] + "分享给" + d.target.split("@")[0],
  511. "styles" : this.css.documentTextNode
  512. }).inject( rightNode );
  513. var documentBottomNode = Element("div.documentBottomNode", {
  514. "styles" : this.css.documentBottomNode
  515. }).inject( rightNode );
  516. Element("div.documentMemoNode", {
  517. "text" : "于"+ d.createTime,
  518. "styles" : this.css.documentMemoNode
  519. }).inject( documentBottomNode );
  520. if( this.app.userName == d.source ){
  521. new Element("div.documentActionNode", {
  522. "text" : "取消分享",
  523. "styles" : this.css.documentActionNode,
  524. "events" : {
  525. "mouseover" : function(){
  526. this.setStyles( _self.css.documentActionNode_over )
  527. },
  528. "mouseout" : function(){
  529. this.setStyles( _self.css.documentActionNode )
  530. },
  531. "click" : function(ev){
  532. _self.cancelShare(ev, d );
  533. }
  534. }
  535. }).inject( documentBottomNode );
  536. }
  537. this.setShareRecordListHeight();
  538. }.bind(this));
  539. if( !json.data || json.data.length == 0 ){
  540. new Element("div.listItemTextNode", {
  541. "text" : "没有找到分享记录",
  542. "styles" : this.css.listItemTextNode
  543. }).inject( this.documentArea );
  544. }
  545. }.bind(this))
  546. },
  547. cancelShare : function( ev, data ){
  548. var _self = this;
  549. this.app.confirm("warn", ev, "取消分享确认", "是否取消对"+data.target.split("@")[0]+"的分享?", 350, 120, function () {
  550. _self.app.restActions.cancelShareMind( data.id , {}, function(){
  551. _self.loadShareRecordList();
  552. _self.app.notice( "取消分享成功!" )
  553. });
  554. this.close();
  555. }, function () {
  556. this.close();
  557. });
  558. },
  559. createActionNode : function( actionArea, image, text, memo, action ){
  560. var actionNode = Element("div.rightActionNode", {
  561. "styles" : this.css.rightActionNode
  562. }).inject( actionArea );
  563. actionNode.addEvents( {
  564. "mouseover" : function(){
  565. actionNode.setStyles( this.css.rightActionNode_over )
  566. }.bind(this),
  567. "mouseout" : function(){
  568. actionNode.setStyles( this.css.rightActionNode )
  569. }.bind(this),
  570. "click" : function(){
  571. action()
  572. }.bind(this)
  573. });
  574. var iconNode = Element("div.rightActionIconNode", {
  575. "styles" : this.css.rightActionIconNode
  576. }).inject( actionNode );
  577. if(image)iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/"+image+".png)");
  578. var rightNode = Element("div.rightActionRightNode", {
  579. "styles" : this.css.rightActionRightNode
  580. }).inject( actionNode );
  581. Element("div.rightActionTextNode", {
  582. "text" : text,
  583. "styles" : this.css.rightActionTextNode
  584. }).inject( rightNode );
  585. Element("div.rightActionMemoNode", {
  586. "text" : memo,
  587. "styles" : this.css.rightActionMemoNode
  588. }).inject( rightNode );
  589. }
  590. });