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.

226 lines
6.8 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. Ext.onReady(function(){
  16. Ext.QuickTips.init();
  17. // Album toolbar
  18. var newIndex = 3;
  19. var tb = new Ext.Toolbar({
  20. items:[{
  21. text: 'New Album',
  22. iconCls: 'album-btn',
  23. handler: function(){
  24. var node = root.appendChild(new Ext.tree.TreeNode({
  25. text:'Album ' + (++newIndex),
  26. cls:'album-node',
  27. allowDrag:false
  28. }));
  29. tree.getSelectionModel().select(node);
  30. setTimeout(function(){
  31. ge.editNode = node;
  32. ge.startEdit(node.ui.textNode);
  33. }, 10);
  34. }
  35. }]
  36. });
  37. // set up the Album tree
  38. var tree = new Ext.tree.TreePanel({
  39. // tree
  40. animate:true,
  41. enableDD:true,
  42. containerScroll: true,
  43. ddGroup: 'organizerDD',
  44. rootVisible:false,
  45. // layout
  46. region:'west',
  47. width:200,
  48. split:true,
  49. // panel
  50. title:'My Albums',
  51. autoScroll:true,
  52. tbar: tb,
  53. margins: '5 0 5 5'
  54. });
  55. var root = new Ext.tree.TreeNode({
  56. text: 'Albums',
  57. allowDrag:false,
  58. allowDrop:false
  59. });
  60. tree.setRootNode(root);
  61. root.appendChild(
  62. new Ext.tree.TreeNode({text:'Album 1', cls:'album-node', allowDrag:false}),
  63. new Ext.tree.TreeNode({text:'Album 2', cls:'album-node', allowDrag:false}),
  64. new Ext.tree.TreeNode({text:'Album 3', cls:'album-node', allowDrag:false})
  65. );
  66. // add an inline editor for the nodes
  67. var ge = new Ext.tree.TreeEditor(tree, {/* fieldconfig here */ }, {
  68. allowBlank:false,
  69. blankText:'A name is required',
  70. selectOnFocus:true
  71. });
  72. // Set up images view
  73. var view = new Ext.DataView({
  74. itemSelector: 'div.thumb-wrap',
  75. style:'overflow:auto',
  76. multiSelect: true,
  77. plugins: new Ext.DataView.DragSelector({dragSafe:true}),
  78. store: new Ext.data.JsonStore({
  79. url: '../view/get-images.php',
  80. autoLoad: true,
  81. root: 'images',
  82. id:'name',
  83. fields:[
  84. 'name', 'url',
  85. {name: 'shortName', mapping: 'name', convert: shortName}
  86. ]
  87. }),
  88. tpl: new Ext.XTemplate(
  89. '<tpl for=".">',
  90. '<div class="thumb-wrap" id="{name}">',
  91. '<div class="thumb"><img src="../view/{url}" class="thumb-img"></div>',
  92. '<span>{shortName}</span></div>',
  93. '</tpl>'
  94. )
  95. });
  96. var images = new Ext.Panel({
  97. id:'images',
  98. title:'My Images',
  99. region:'center',
  100. margins: '5 5 5 0',
  101. layout:'fit',
  102. items: view
  103. });
  104. var layout = new Ext.Panel({
  105. layout: 'border',
  106. width:650,
  107. height:400,
  108. items: [tree, images]
  109. });
  110. layout.render('layout');
  111. var dragZone = new ImageDragZone(view, {containerScroll:true,
  112. ddGroup: 'organizerDD'});
  113. });
  114. /**
  115. * Create a DragZone instance for our JsonView
  116. */
  117. ImageDragZone = function(view, config){
  118. this.view = view;
  119. ImageDragZone.superclass.constructor.call(this, view.getEl(), config);
  120. };
  121. Ext.extend(ImageDragZone, Ext.dd.DragZone, {
  122. // We don't want to register our image elements, so let's
  123. // override the default registry lookup to fetch the image
  124. // from the event instead
  125. getDragData : function(e){
  126. var target = e.getTarget('.thumb-wrap');
  127. if(target){
  128. var view = this.view;
  129. if(!view.isSelected(target)){
  130. view.onClick(e);
  131. }
  132. var selNodes = view.getSelectedNodes();
  133. var dragData = {
  134. nodes: selNodes
  135. };
  136. if(selNodes.length == 1){
  137. dragData.ddel = target;
  138. dragData.single = true;
  139. }else{
  140. var div = document.createElement('div'); // create the multi element drag "ghost"
  141. div.className = 'multi-proxy';
  142. for(var i = 0, len = selNodes.length; i < len; i++){
  143. div.appendChild(selNodes[i].firstChild.firstChild.cloneNode(true)); // image nodes only
  144. if((i+1) % 3 == 0){
  145. div.appendChild(document.createElement('br'));
  146. }
  147. }
  148. var count = document.createElement('div'); // selected image count
  149. count.innerHTML = i + ' images selected';
  150. div.appendChild(count);
  151. dragData.ddel = div;
  152. dragData.multi = true;
  153. }
  154. return dragData;
  155. }
  156. return false;
  157. },
  158. // this method is called by the TreeDropZone after a node drop
  159. // to get the new tree node (there are also other way, but this is easiest)
  160. getTreeNode : function(){
  161. var treeNodes = [];
  162. var nodeData = this.view.getRecords(this.dragData.nodes);
  163. for(var i = 0, len = nodeData.length; i < len; i++){
  164. var data = nodeData[i].data;
  165. treeNodes.push(new Ext.tree.TreeNode({
  166. text: data.name,
  167. icon: '../view/'+data.url,
  168. data: data,
  169. leaf:true,
  170. cls: 'image-node'
  171. }));
  172. }
  173. return treeNodes;
  174. },
  175. // the default action is to "highlight" after a bad drop
  176. // but since an image can't be highlighted, let's frame it
  177. afterRepair:function(){
  178. for(var i = 0, len = this.dragData.nodes.length; i < len; i++){
  179. Ext.fly(this.dragData.nodes[i]).frame('#8db2e3', 1);
  180. }
  181. this.dragging = false;
  182. },
  183. // override the default repairXY with one offset for the margins and padding
  184. getRepairXY : function(e){
  185. if(!this.dragData.multi){
  186. var xy = Ext.Element.fly(this.dragData.ddel).getXY();
  187. xy[0]+=3;xy[1]+=3;
  188. return xy;
  189. }
  190. return false;
  191. }
  192. });
  193. // Utility functions
  194. function shortName(name){
  195. if(name.length > 15){
  196. return name.substr(0, 12) + '...';
  197. }
  198. return name;
  199. };