You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.0 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Imgorg.AlbumTree = Ext.extend(Ext.tree.TreePanel,{
  16. initComponent: function() {
  17. Ext.apply(this,{
  18. loader: new Ext.ux.tree.DirectTreeLoader({
  19. api: Imgorg.ss.Albums
  20. }),
  21. root: new Ext.tree.TreeNode({
  22. text:'dummynode',
  23. expanded: true,
  24. leaf: false,
  25. cls:'album-node'
  26. }),
  27. rootVisible: false,
  28. clearOnLoad: false,
  29. autoScroll: true,
  30. containerScroll: true,
  31. enableDrop: true,
  32. dropConfig: {
  33. ddGroup: 'organizerDD',
  34. notifyDrop: this.onNotifyDrop.createDelegate(this)
  35. }
  36. });
  37. Imgorg.AlbumTree.superclass.initComponent.call(this);
  38. this.loader.load(this.root);
  39. this.editor = new Ext.tree.TreeEditor(this, {
  40. allowBlank: false,
  41. blankText: 'A name is required',
  42. selectOnFocus: true
  43. });
  44. this.editor.on('complete', this.onEditComplete, this);
  45. this.on('contextmenu', this.onContextMenu, this);
  46. },
  47. onContextMenu: function(node, e) {
  48. e.stopEvent();
  49. if(!this.contMenu) {
  50. this.contMenu = new Ext.menu.Menu({
  51. items: [{
  52. text: 'Remove',
  53. handler: function() {
  54. var node = this.currentNode;
  55. node.unselect();
  56. Ext.fly(node.ui.elNode).ghost('l', {
  57. callback: function() {
  58. Imgorg.ss.Albums.remove({
  59. album: node.id
  60. });
  61. node.remove();
  62. }, scope: node, duration: 0.4
  63. });
  64. },
  65. scope: this
  66. }]
  67. });
  68. }
  69. this.currentNode = node;
  70. this.contMenu.showAt(e.getXY());
  71. },
  72. onNotifyDrop: function(src, e, data) {
  73. var nodes = data.nodes;
  74. var nodeIds = [];
  75. for (var i = 0;i < nodes.length;i++) {
  76. nodeIds.push(nodes[i].id);
  77. }
  78. this.addToAlbum(nodeIds, this.dropZone.dragOverData.target.attributes.id);
  79. return true; // cancell repair anim
  80. },
  81. addToAlbum: function(nodes, album) {
  82. Imgorg.ss.Images.addToAlbum({
  83. images: nodes,
  84. album: album
  85. });
  86. },
  87. addAlbum: function() {
  88. var root = this.root;
  89. var node = root.appendChild(new Ext.tree.TreeNode({
  90. text:'Album',
  91. cls:'album-node',
  92. allowDrag:false
  93. }));
  94. this.getSelectionModel().select(node);
  95. var ge = this.editor;
  96. setTimeout(function(){
  97. ge.editNode = node;
  98. ge.startEdit(node.ui.textNode);
  99. }, 10);
  100. },
  101. onEditComplete: function(editor, newVal, oldVal) {
  102. var n = editor.editNode;
  103. Imgorg.ss.Albums.addOrUpdate({node: n.id, text: newVal, id: n.attributes.id});
  104. }
  105. });
  106. Ext.reg('img-albumtree', Imgorg.AlbumTree);
  107. Ext.ns('Ext.ux.tree');
  108. Ext.ux.tree.DirectTreeLoader = Ext.extend(Ext.tree.TreeLoader,{
  109. baseAttrs: {
  110. cls:'album-node'
  111. },
  112. load : function(node, callback){
  113. this.requestData(node, callback);
  114. },
  115. requestData : function(node, callback){
  116. if(this.fireEvent("beforeload", this, node, callback) !== false){
  117. this.api.loadtree({
  118. node: node.id
  119. }, this.processResponse.createDelegate(this, [node, callback], true));
  120. }else{
  121. // if the load is cancelled, make sure we notify
  122. // the node that we are done
  123. if(typeof callback == "function"){
  124. callback();
  125. }
  126. }
  127. },
  128. processResponse : function(res, trans, node, callback){
  129. try {
  130. node.beginUpdate();
  131. for(var i = 0, len = res.length; i < len; i++){
  132. var n = this.createNode(res[i]);
  133. if(n){
  134. node.appendChild(n);
  135. }
  136. }
  137. node.endUpdate();
  138. if(typeof callback == "function"){
  139. callback(this, node);
  140. }
  141. }catch(e){
  142. this.handleFailure(res);
  143. }
  144. }
  145. });