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.

222 lines
7.1 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.ImageThumbPanel = Ext.extend(Ext.Panel, {
  16. minWidth: 80,
  17. title: 'All Photos',
  18. initComponent: function() {
  19. this.tfId = 'tag-filter-'+Ext.id();
  20. var sliderValue = 0;
  21. var p = Ext.state.Manager.getProvider();
  22. if (p) {
  23. sliderValue = Ext.num(p.get('sliderValue'), 0);
  24. }
  25. Ext.apply(this,{
  26. layout:'fit',
  27. cls: 'images-view',
  28. items:Ext.apply({
  29. xtype: 'img-dv',
  30. itemId: 'imgorg-dv'
  31. },this.dvConfig||{}),
  32. bbar:['Tags:',{
  33. xtype: 'img-tagmulticombo',
  34. id: this.tfId,
  35. listeners: {
  36. select: function(combo, record, idx) {
  37. var vals = combo.getValue();
  38. this.tagFilter(vals);
  39. return true;
  40. },
  41. clearall: function(combo) {
  42. this.clearFilter();
  43. },
  44. scope: this
  45. }
  46. },'->',{
  47. xtype: 'slider',
  48. itemId: 'size-slider',
  49. width: 200,
  50. style: 'margin-right:20px;',
  51. value: sliderValue,
  52. plugins: new Ext.slider.Tip({
  53. getText: function(slider){
  54. return String.format('<b>{0}%</b>', 100+slider.getValue()*3);
  55. }
  56. }),
  57. listeners: {
  58. change: this.onChange,
  59. scope: this
  60. }
  61. }]
  62. });
  63. Imgorg.ImageThumbPanel.superclass.initComponent.call(this);
  64. this.on('activate', this.onActivate, this);
  65. },
  66. afterRender: function() {
  67. Imgorg.ImageThumbPanel.superclass.afterRender.call(this);
  68. this.view = this.getComponent('imgorg-dv');
  69. (function() {
  70. this.dragZone = new ImageDragZone(this.view, {
  71. containerScroll:true,
  72. ddGroup: 'organizerDD'
  73. });
  74. }).defer(100, this);
  75. },
  76. onActivate: function() {
  77. this.reload();
  78. var p = Ext.state.Manager.getProvider();
  79. if (p) {
  80. sliderValue = Ext.num(p.get('sliderValue'), 0);
  81. var slider = this.getBottomToolbar().getComponent('size-slider');
  82. slider.setValue(sliderValue);
  83. this.onChange(slider);
  84. }
  85. },
  86. onChange: function(slider, e) {
  87. var p = Ext.state.Manager.getProvider();
  88. if (p) {
  89. p.set('sliderValue', slider.getValue());
  90. }
  91. Ext.util.CSS.updateRule('.images-view .thumb img','height',this.minWidth+slider.getValue()*3);
  92. },
  93. tagFilter: function(vals) {
  94. if (this.view.store.lastOptions.params) {
  95. var album = this.view.store.lastOptions.params.album;
  96. }
  97. this.view.store.load({
  98. params: {
  99. tags: vals,
  100. album: album
  101. }
  102. });
  103. },
  104. clearFilter: function() {
  105. var album = this.view.store.lastOptions.params.album;
  106. this.view.store.load({
  107. params: {
  108. album: album
  109. }
  110. });
  111. Ext.getCmp(this.tfId).reset();
  112. },
  113. albumFilter: function(album) {
  114. this.getComponent('imgorg-dv').store.load({
  115. params: {
  116. album: album.id
  117. }
  118. });
  119. },
  120. reload: function() {
  121. this.view.store.reload();
  122. }
  123. });
  124. Ext.reg('img-thumbpanel', Imgorg.ImageThumbPanel);
  125. ImageDragZone = function(view, config){
  126. this.view = view;
  127. ImageDragZone.superclass.constructor.call(this, view.getEl(), config);
  128. };
  129. Ext.extend(ImageDragZone, Ext.dd.DragZone, {
  130. // We don't want to register our image elements, so let's
  131. // override the default registry lookup to fetch the image
  132. // from the event instead
  133. getDragData : function(e){
  134. var target = e.getTarget('.thumb-wrap');
  135. if(target){
  136. var view = this.view;
  137. if(!view.isSelected(target)){
  138. view.onClick(e);
  139. }
  140. var selNodes = view.getSelectedNodes();
  141. var dragData = {
  142. nodes: selNodes
  143. };
  144. if(selNodes.length == 1){
  145. dragData.ddel = target;
  146. dragData.single = true;
  147. }else{
  148. var div = document.createElement('div'); // create the multi element drag "ghost"
  149. div.className = 'multi-proxy';
  150. for(var i = 0, len = selNodes.length; i < len; i++){
  151. div.appendChild(selNodes[i].firstChild.firstChild.cloneNode(true)); // image nodes only
  152. if((i+1) % 3 == 0){
  153. div.appendChild(document.createElement('br'));
  154. }
  155. }
  156. var count = document.createElement('div'); // selected image count
  157. count.innerHTML = i + ' images selected';
  158. div.appendChild(count);
  159. dragData.ddel = div;
  160. dragData.multi = true;
  161. }
  162. return dragData;
  163. }
  164. return false;
  165. },
  166. // this method is called by the TreeDropZone after a node drop
  167. // to get the new tree node (there are also other way, but this is easiest)
  168. getTreeNode : function(){
  169. var treeNodes = [];
  170. var nodeData = this.view.getRecords(this.dragData.nodes);
  171. for(var i = 0, len = nodeData.length; i < len; i++){
  172. var data = nodeData[i].data;
  173. treeNodes.push(new Ext.tree.TreeNode({
  174. text: data.name,
  175. icon: '../view/'+data.url,
  176. data: data,
  177. leaf:true,
  178. cls: 'image-node'
  179. }));
  180. }
  181. return treeNodes;
  182. },
  183. // the default action is to "highlight" after a bad drop
  184. // but since an image can't be highlighted, let's frame it
  185. afterRepair:function(){
  186. for(var i = 0, len = this.dragData.nodes.length; i < len; i++){
  187. Ext.fly(this.dragData.nodes[i]).frame('#8db2e3', 1);
  188. }
  189. this.dragging = false;
  190. },
  191. // override the default repairXY with one offset for the margins and padding
  192. getRepairXY : function(e){
  193. if(!this.dragData.multi){
  194. var xy = Ext.Element.fly(this.dragData.ddel).getXY();
  195. xy[0]+=3;xy[1]+=3;
  196. return xy;
  197. }
  198. return false;
  199. }
  200. });