LeftToolbar.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. MWF.xDesktop.requireApp("MinderEditor", "lp."+MWF.language, null, false);
  2. MWF.xDesktop.requireApp("MinderEditor", "Commands", null, false);
  3. MWF.xApplication.MinderEditor.LeftToolbar = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function (container, editor, minder, app ) {
  10. this.container = container;
  11. this.app = app;
  12. this.lp = MWF.xApplication.MinderEditor.LP;
  13. this.actions = this.app.restActions;
  14. this.editor = editor;
  15. this.minder = minder;
  16. if( this.editor.commands ){
  17. this.commands = this.editor.commands;
  18. }else{
  19. this.commands = new MWF.xApplication.MinderEditor.Commands( this.editor );
  20. this.commands.load();
  21. }
  22. this.path = "../x_component_MinderEditor/$LeftToolbar/";
  23. this.cssPath = this.path+this.options.style+"/css.wcss";
  24. this._loadCss();
  25. },
  26. load: function (callback) {
  27. this.creat();
  28. //this.navMoveNode.click();
  29. },
  30. destroy: function(){
  31. this.node.destroy();
  32. delete this;
  33. },
  34. getHtml : function(){
  35. var items;
  36. var tools = this.editor.options.tools;
  37. if( tools && tools.left ){
  38. items = tools.left;
  39. }else{
  40. items = [ "zoom", "camera", "resetlayout", "move", "expandLevel", "selectAll", "preview", "template", "theme", "search" ];
  41. }
  42. var html = "";
  43. var disableTools = this.editor.options.disableTools || [];
  44. disableTools.each( function( tool ){
  45. items.erase( tool )
  46. });
  47. this.itemCount = 0;
  48. items.each( function( item ){
  49. if( item != "zoom" )this.itemCount++;
  50. switch( item ){
  51. case "zoom":
  52. this.hasZoom = true;
  53. html += "<div item='zoom'></div>";
  54. break;
  55. case "camera" :
  56. html += "<div item='camera' styles='navButton'></div>";
  57. break;
  58. case "resetlayout" :
  59. html += "<div item='resetlayout' styles='" + "navButton" + "'></div>";
  60. break;
  61. case "move" :
  62. html += "<div item='move' styles='navButton' itemevent='click'></div>";
  63. break;
  64. case "expandLevel" :
  65. html += "<div item='expandLevel' styles='navButton'></div>";
  66. break;
  67. case "selectAll" :
  68. html += "<div item='selectAll' styles='" + "navButton" + "'></div>";
  69. break;
  70. case "preview" :
  71. html += "<div item='preview' subtype='button' itemevent='click' styles='navButton'></div>"+
  72. "<div item='preview' subtype='container'></div>";
  73. break;
  74. case "template" :
  75. html += "<div item='template' styles='navButton'></div>";
  76. break;
  77. case "theme" :
  78. html += "<div item='theme' styles='navButton'></div>";
  79. break;
  80. case "search" :
  81. html += "<div item='search' subtype='button' itemevent='click' styles='navButton'></div>"+
  82. "<div item='search' subtype='container'></div>";
  83. break;
  84. }
  85. }.bind(this));
  86. return html;
  87. },
  88. setSize : function(){
  89. var reduce = 0;
  90. if( !this.hasZoom ) reduce = 131;
  91. reduce += ( 9 - this.itemCount ) * 27;
  92. if( reduce > 0 ){
  93. var height = this.node.getSize().y - 10;
  94. this.node.setStyle("height", height - reduce );
  95. }
  96. },
  97. creat: function(){
  98. this.node = new Element("div",{ "styles" : this.css.nav }).inject(this.container);
  99. this.node.set("html",this.getHtml());
  100. this.setSize();
  101. this.node.getElements("[styles]").each(function (el) {
  102. if (!el.get("item")) {
  103. el.setStyles(this.css[el.get("styles")]);
  104. }
  105. }.bind(this));
  106. this.commands.addContainer( "lefttoolbar", this.node, this.css );
  107. //this.navCameraNode = new Element("div",{ "styles" : this.css.navButton , "title" : this.lp.navCamera }).inject(this.node);
  108. //new Element("div",{ "styles" : this.css.navCameraIcon }).inject(this.navCameraNode);
  109. //this.navCameraNode.addEvent("click",function(){
  110. // this.minder.execCommand('camera', this.minder.getRoot(), 600);
  111. // //this.editor.moveToCenter()
  112. //}.bind(this));
  113. //
  114. //this.navExpandNode = new Element("div",{ "styles" : this.css.navButton , "title" : "展开节点" }).inject(this.node);
  115. //new Element("div",{ "styles" : this.css.navExpandIcon }).inject(this.navExpandNode);
  116. //this.navExpandNode.addEvent("click",function(ev){
  117. // this.showExpandNode( ev );
  118. // ev.stopPropagation();
  119. //}.bind(this));
  120. //this.navTrigger = new Element("div",{ "styles" : this.css.navButton , "title" : this.lp.navTrigger }).inject(this.node);
  121. //new Element("div",{ "styles" : this.css.navTriggerIcon }).inject(this.navTrigger);
  122. //this.navTrigger.addEvent( "click", function(){
  123. // this.toggleOpenPreViewer();
  124. //}.bind(this) );
  125. //this.createrPreViewer();
  126. //this.navMoveNode = new Element("div",{ "styles" : this.css.navButton , "title" : this.lp.allowDrag }).inject(this.node);
  127. //this.navMoveNode.setStyles( this.css.navButton_over );
  128. //this.moveOpen = true;
  129. //new Element("div",{ "styles" : this.css.navMoveIcon }).inject(this.navMoveNode);
  130. //this.navMoveNode.addEvent("click",function(){
  131. // this.moveOpen = !this.moveOpen;
  132. // if( this.moveOpen ){
  133. // this.navMoveNode.setStyles( this.css.navButton_over );
  134. // }else{
  135. // this.navMoveNode.setStyles( this.css.navButton );
  136. // }
  137. // this.minder.execCommand('hand');
  138. //}.bind(this));
  139. //this.navTemplateNode = new Element("div",{ "styles" : this.css.navButton , "title" : this.lp.changeTemplate }).inject(this.node);
  140. //new Element("div",{ "styles" : this.css.navTemplateIcon }).inject(this.navTemplateNode);
  141. //this.navTemplateNode.addEvent("click",function( ev ){
  142. // this.selectTemplate( ev );
  143. // ev.stopPropagation();
  144. //}.bind(this));
  145. //this.navSearchNode = new Element("div",{ "styles" : this.css.navButton , "title" : this.lp.search }).inject(this.node);
  146. //new Element("div",{ "styles" : this.css.navSearchIcon }).inject(this.navSearchNode);
  147. //
  148. //this.navSearchNode.addEvent("click",function(){
  149. // if( !this.isShowedSearch ){
  150. // this.showSearch();
  151. // }else{
  152. // this.hideSearch();
  153. // }
  154. //}.bind(this));
  155. //this.app.content.addEvent('keydown', function(e) {
  156. // if (e.code == 70 && e.control && !e.shift) {
  157. // this.navSearchNode.click();
  158. // e.preventDefault();
  159. // }
  160. //}.bind(this));
  161. //this.minder.on('searchNode', function() {
  162. // this.navSearchNode.click();
  163. //});
  164. //this.navExpand = new Element("div",{ "styles" : this.css.navButton , "title" : "展开" }).inject(this.node);
  165. //new Element("div",{ "styles" : this.css.navExpandIcon }).inject(this.navExpand);
  166. }
  167. //setMoveOpen : function( flag ){
  168. // this.navMoveNode.setStyles( flag ? this.css.navButton_over : this.css.navButton );
  169. // this.moveOpen = flag ? true : false;
  170. //},
  171. //showSearch: function(){
  172. // this.isShowedSearch = true;
  173. // if( !this.searchBar ){
  174. // this.searchBar = new MWF.xApplication.MinderEditor.SearchBar( this, this.node, this.minder, this.app, this.css );
  175. // this.searchBar.load();
  176. // }else{
  177. // this.searchBar.show()
  178. // }
  179. // this.navSearchNode.setStyles( this.css.navButton_over );
  180. //},
  181. //hideSearch: function(){
  182. // this.isShowedSearch = false;
  183. // this.searchBar.hide();
  184. // this.navSearchNode.setStyles( this.css.navButton );
  185. //}
  186. //selectTemplate: function(){
  187. // this.templateOpen = !this.templateOpen;
  188. // if( this.templateOpen ){
  189. // if( this.templateSelectNode ){
  190. // this.templateSelectNode.setStyle("display","block")
  191. // }else{
  192. // this.createTemplateSelectNode();
  193. // }
  194. // this.navTemplateNode.setStyles( this.css.navButton_over );
  195. // }else{
  196. // this.hideTemplateSelectNode();
  197. // }
  198. //},
  199. //hideTemplateSelectNode: function(){
  200. // this.templateOpen = false;
  201. // this.navTemplateNode.setStyles( this.css.navButton );
  202. // if( this.templateSelectNode ){
  203. // this.templateSelectNode.setStyle("display","none");
  204. // }
  205. //},
  206. //createTemplateSelectNode: function(){
  207. // this.templateSelectNode = new Element("div",{
  208. // styles : this.css.templateSelectNode
  209. // }).inject(this.node);
  210. //
  211. // this.minderTemplate = new Element("div",{
  212. // styles : this.css.minderTemplate,
  213. // title : this.lp.minderTemplate
  214. // }).inject(this.templateSelectNode);
  215. // this.minderTemplate.addEvents({
  216. // "mouseover" : function(){ this.minderTemplate.setStyles( this.css.minderTemplate_over )}.bind(this),
  217. // "mouseout" : function(){ this.minderTemplate.setStyles( this.css.minderTemplate )}.bind(this),
  218. // "click" : function(){
  219. // this.editor.templateChanged = true;
  220. // this.minder.execCommand('template', "default");
  221. // this.hideTemplateSelectNode();
  222. // //this.editor.moveToCenter();
  223. // }.bind(this)
  224. // });
  225. //
  226. // this.fishboneTemplate = new Element("div",{
  227. // styles : this.css.fishboneTemplate,
  228. // title : this.lp.fishBoneTemplate
  229. // }).inject(this.templateSelectNode);
  230. // this.fishboneTemplate.addEvents({
  231. // "mouseover" : function(){ this.fishboneTemplate.setStyles( this.css.fishboneTemplate_over )}.bind(this),
  232. // "mouseout" : function(){ this.fishboneTemplate.setStyles( this.css.fishboneTemplate )}.bind(this),
  233. // "click" : function(){
  234. // //this.minder.on("execCommand", function (e) {
  235. // // if (e.commandName === "template" ) {
  236. // // this.editor.moveToCenter();
  237. // // }
  238. // //}.bind(this));
  239. // this.editor.templateChanged = true;
  240. // this.minder.execCommand('template', "fish-bone");
  241. // this.hideTemplateSelectNode();
  242. // //this.editor.moveToCenter();
  243. // }.bind(this)
  244. // });
  245. //
  246. // this.app.content.addEvent("click",function(){
  247. // this.hideTemplateSelectNode();
  248. // }.bind(this))
  249. //},
  250. //showExpandNode: function(){
  251. // this.expandNodeOpen = !this.expandNodeOpen;
  252. // if( this.expandNodeOpen ){
  253. // if( this.expandArea ){
  254. // this.expandArea.setStyle("display","block")
  255. // }else{
  256. // this.createExpandArea();
  257. // }
  258. // this.navExpandNode.setStyles( this.css.navButton_over );
  259. // }else{
  260. // this.hideExpandArea();
  261. // }
  262. //},
  263. //hideExpandArea: function(){
  264. // this.expandNodeOpen = false;
  265. // this.navExpandNode.setStyles( this.css.navButton );
  266. // if( this.expandArea ){
  267. // this.expandArea.setStyle("display","none");
  268. // }
  269. //},
  270. //createExpandArea: function(){
  271. // var deepestLevel = this.editor.deepestLevel || 6;
  272. //
  273. // this.expandArea = new Element("div",{
  274. // styles : this.css.expandArea
  275. // }).inject(this.node);
  276. // this.expandArea.setStyle("height",this.css.expandNode.height * (deepestLevel+1));
  277. //
  278. // var expandAllNode = new Element("div",{
  279. // styles : this.css.expandNode,
  280. // text : "展开所有节点"
  281. // }).inject(this.expandArea);
  282. // expandAllNode.addEvents({
  283. // "mouseover" : function(){ this.node.setStyles( this.navi.css.expandNode_over )}.bind( { navi : this, node : expandAllNode} ),
  284. // "mouseout" : function(){ this.node.setStyles( this.navi.css.expandNode )}.bind({ navi : this, node : expandAllNode}),
  285. // "click" : function(){
  286. // this.navi.minder.execCommand('expandtolevel', deepestLevel);
  287. // this.navi.hideExpandArea();
  288. // }.bind({ navi : this, node : expandAllNode})
  289. // })
  290. //
  291. // for( var i=1; i<=deepestLevel; i++ ){
  292. // var expandNode = new Element("div",{
  293. // styles : this.css.expandNode,
  294. // text : "展开到"+i+"级节点"
  295. // }).inject(this.expandArea);
  296. // expandNode.addEvents({
  297. // "mouseover" : function(){ this.node.setStyles( this.navi.css.expandNode_over )}.bind( { navi : this, node : expandNode} ),
  298. // "mouseout" : function(){ this.node.setStyles( this.navi.css.expandNode )}.bind({ navi : this, node : expandNode}),
  299. // "click" : function(){
  300. // this.navi.minder.execCommand('expandtolevel', this.level);
  301. // this.navi.hideExpandArea();
  302. // }.bind({ navi : this, node : expandNode, level : i})
  303. // })
  304. // }
  305. //
  306. // this.app.content.addEvent("click",function(){
  307. // this.hideExpandArea();
  308. // }.bind(this))
  309. //}
  310. });