MineExplorer.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //MWF.xDesktop.requireApp("Minder", "Actions.RestActions", null, false);
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  4. MWF.xDesktop.requireApp("Minder", "Common", null, false);
  5. MWF.xApplication.Minder.MineExplorer = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "defaultTreeNode" : "root",
  11. "defaultViewType" : "list"
  12. },
  13. initialize: function(node, app, options){
  14. this.setOptions(options);
  15. this.path = "../x_component_Minder/$MineExplorer/";
  16. this.cssPath = "../x_component_Minder/$MineExplorer/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.app = app;
  19. this.container = $(node);
  20. },
  21. load : function(){
  22. this.treeNode = new Element("div.treeNode",{
  23. "styles" : this.css.treeNode
  24. }).inject(this.container);
  25. this.tree = new MWF.xApplication.Minder.MineExplorer.Tree( this, this.treeNode, {
  26. style : this.options.style,
  27. defaultNode : this.options.defaultTreeNode,
  28. "minWidth" : 260,
  29. "maxWidth" : 350,
  30. onPostLoad : function(){
  31. this.resizeContent();
  32. }.bind(this)
  33. } );
  34. this.rightNode = new Element("div.rightNode",{
  35. "styles" : this.css.rightNode
  36. }).inject(this.container);
  37. //this.historyContentNode = new Element("div",{
  38. // "styles" : this.css.historyContentNode
  39. //}).inject(this.rightNode);
  40. //this.app.histroy.load( this.historyContentNode );
  41. this.toolbarNode = new Element("div",{
  42. "styles" : this.css.toolbarNode
  43. }).inject(this.rightNode);
  44. this.toolbar = new MWF.xApplication.Minder.Toolbar(this.toolbarNode, this, {
  45. viewType : this.options.defaultViewType
  46. });
  47. this.toolbar.load();
  48. this.listNode = new Element("div",{
  49. "styles" : this.css.listNode
  50. }).inject(this.rightNode);
  51. this.resizeContent();
  52. this.resizeFun = this.resizeContent.bind(this);
  53. this.app.addEvent("resize", this.resizeFun);
  54. },
  55. destroy : function(){
  56. this.container.empty();
  57. this.app.removeEvent("resize", this.resizeFun);
  58. },
  59. resizeContent : function(){
  60. var size = this.app.content.getSize();
  61. var treeSize = this.treeNode.getSize();
  62. var naviSize = this.app.naviNode.getSize();
  63. var x = size.x - treeSize.x - naviSize.x - 5;
  64. this.treeNode.setStyle("height", size.y);
  65. this.rightNode.setStyle("width", x );
  66. this.listNode.setStyle("height", size.y - 92 );
  67. this.listNode.setStyle("width", x - 43 );
  68. this.toolbarNode.setStyle("width", x );
  69. },
  70. loadList: function( filterData ){
  71. if (this.currentView) this.currentView.destroy();
  72. this.currentView = new MWF.xApplication.Minder.List( this.listNode, this.app, this, {
  73. templateUrl : this.path + this.options.style + ( this.getViewType() == "list" ? "/listItem.json" : "/tileItem.json" ),
  74. "scrollEnable" : true
  75. });
  76. this.currentView.viewType = this.getViewType();
  77. this.currentView.filterData = filterData;
  78. this.currentView.load();
  79. },
  80. getViewType : function(){
  81. return this.toolbar.getListType();
  82. },
  83. getCurrentFolderData : function(){
  84. return this.tree.getCurrentFolderData();
  85. },
  86. getCurrentFolderId : function(){
  87. return this.tree.getCurrentFolderId();
  88. },
  89. recordStatus : function(){
  90. return {
  91. defaultTreeNode : this.getCurrentFolderId(),
  92. defaultViewType : this.getViewType()
  93. }
  94. }
  95. });
  96. MWF.xApplication.Minder.MineExplorer.Tree = new Class({
  97. Extends: MWF.xApplication.Minder.Tree,
  98. Implements: [Options, Events],
  99. loadTreeNode : function( rootData ){
  100. this.treeNode = new MWF.xApplication.Minder.MineExplorer.Tree.Node( this, this.treeContentNode, rootData, {
  101. "style" : this.options.style,
  102. "isCurrent" : this.options.defaultNode == rootData.id,
  103. "minWidth" : this.options.minWidth,
  104. "maxWidth" : this.options.maxWidth
  105. });
  106. }
  107. });
  108. MWF.xApplication.Minder.MineExplorer.Tree.Node = new Class({
  109. Extends: MWF.xApplication.Minder.Tree.Node,
  110. Implements: [Options, Events],
  111. getTreeNode: function( data ){
  112. return new MWF.xApplication.Minder.MineExplorer.Tree.Node(this.tree, this.treeContentNode, data, {
  113. style :this.options.style,
  114. level : this.options.level + 1,
  115. isCurrent : this.tree.options.defaultNode == data.id,
  116. "minWidth" : this.options.minWidth,
  117. "maxWidth" : this.options.maxWidth
  118. })
  119. },
  120. setTextNodeWidth : function(){
  121. if( this.options.minWidth ){
  122. this.itemTextNode.setStyle( "min-width" , ( this.options.minWidth - this.options.level * 12 - 10 - 80 ) +"px");
  123. this.itemTextNode.setStyle( "margin-right" , "0px")
  124. }
  125. if( this.options.maxWidth ){
  126. this.itemTextNode.setStyle( "max-width" , ( this.options.maxWidth - this.options.level * 12 - 10 - 80 ) +"px");
  127. this.itemTextNode.setStyle( "margin-right" , "0px")
  128. }
  129. },
  130. _cancelCurrent : function(){
  131. if( this.toolbar )this.toolbar.setStyle("display","none");
  132. this.setTextNodeWidth();
  133. },
  134. _setCurrent: function(){
  135. this.explorer.loadList({
  136. folderId : this.data.id
  137. });
  138. if( !this.toolbar ){
  139. this.createToolbar()
  140. }else{
  141. this.toolbar.setStyle("display","");
  142. }
  143. if( this.options.minWidth ){
  144. this.itemTextNode.setStyle( "min-width" , ( this.options.minWidth - this.options.level * 12 - 10 - 80 - 50 ) +"px");
  145. this.itemTextNode.setStyle( "margin-right" , "50px")
  146. }
  147. if( this.options.maxWidth ){
  148. this.itemTextNode.setStyle( "max-width" , ( this.options.maxWidth - this.options.level * 12 - 10 - 80 - 50 ) +"px");
  149. this.itemTextNode.setStyle( "margin-right" , "50px")
  150. }
  151. this.explorer.resizeContent();
  152. },
  153. createToolbar : function(){
  154. if( this.data.id == "root" )return;
  155. this.toolbar = new Element("div",{
  156. styles : this.explorer.css.toolbar
  157. }).inject( this.itemNode );
  158. this.editAction = new Element("div.editAction",{
  159. styles : this.explorer.css.editAction,
  160. "title" : "编辑"
  161. }).inject(this.toolbar);
  162. this.editAction.addEvents({
  163. "click" : function(ev){
  164. this.edit( ev );
  165. }.bind(this),
  166. "mouseover" : function(ev){
  167. this.editAction.setStyles( this.explorer.css.editAction_over )
  168. }.bind(this),
  169. "mouseout" : function(ev){
  170. this.editAction.setStyles( this.explorer.css.editAction )
  171. }.bind(this)
  172. });
  173. this.deleteAction = new Element("div.cancelViewAction", {
  174. "styles": this.explorer.css.deleteAction,
  175. "title" : "删除"
  176. }).inject(this.toolbar);
  177. this.deleteAction.addEvent("click", function(e){
  178. this.delete(e);
  179. }.bind(this));
  180. this.deleteAction.addEvents({
  181. "mouseover" : function(ev){
  182. this.deleteAction.setStyles( this.explorer.css.deleteAction_over )
  183. }.bind(this),
  184. "mouseout" : function(ev){
  185. this.deleteAction.setStyles( this.explorer.css.deleteAction )
  186. }.bind(this)
  187. });
  188. },
  189. checkDelete : function( callback, ev ){
  190. if( this.children && this.children.length > 0 ){
  191. this.app.notice( this.app.lp.deleteFolderDisable_hasSubFolder, "error" );
  192. return false;
  193. }
  194. this.app.restActions.listNextMindWithFilter("(0)", 1, { folderId : this.data.id }, function(json){
  195. if( json.data && json.data.length > 0 ){
  196. this.app.notice( this.app.lp.deleteFolderDisable_hasFile, "error" );
  197. return false;
  198. }else if( callback ){
  199. callback();
  200. }
  201. }.bind(this));
  202. },
  203. delete : function( ev ){
  204. this.checkDelete( function(){
  205. var _self = this;
  206. var text = this.app.lp.deleteFolder.replace(/{name}/g, this.data.name );
  207. this.app.confirm("infor", ev, this.app.lp.deleteFolderTitle, text, 380, 150, function(){
  208. _self._delete();
  209. this.close();
  210. }, function(){
  211. this.close()
  212. });
  213. }.bind(this), ev );
  214. ev.stopPropagation();
  215. },
  216. _delete : function( ev ){
  217. this.app.restActions.removeFolder( this.data.id, function(){
  218. if (this.explorer.currentView) this.explorer.currentView.destroy();
  219. this.tree.reload();
  220. }.bind(this));
  221. },
  222. edit : function( ev ){
  223. var form = new MWF.xApplication.Minder.FolderForm(this.explorer, this.data, {
  224. title : "编辑目录"
  225. }, {
  226. app: this.app
  227. });
  228. form.edit();
  229. ev.stopPropagation();
  230. }
  231. });