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.

130 lines
4.3 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.ImageDv = Ext.extend(Ext.DataView,{
  16. tpl: new Ext.XTemplate(
  17. '<tpl for=".">',
  18. '<div class="thumb-wrap" id="{id}">',
  19. '<div class="thumb"><img src="images/thumbs/{filename}" class="thumb-img"></div>',
  20. '<span class="x-editable">{filename:ellipsis(15)}</span></div>',
  21. '</tpl>'
  22. ),
  23. initComponent: function() {
  24. Ext.apply(this, {
  25. itemSelector: 'div.thumb-wrap',
  26. style: 'overflow:auto',
  27. multiSelect: true,
  28. overClass: 'x-view-over',
  29. emptyText: 'No images to display',
  30. plugins: [new Ext.DataView.DragSelector({
  31. dragSafe: true
  32. }), new Ext.DataView.LabelEditor({
  33. allowBlank: false,
  34. alignment: 'c-c',
  35. dataIndex: 'filename'
  36. })],
  37. store: new Ext.data.DirectStore({
  38. directFn: Imgorg.ss.Images.load,
  39. root: '',
  40. fields: ['filename', 'url', 'id', 'size']
  41. })
  42. });
  43. this.addEvents('viewitem');
  44. Imgorg.ImageDv.superclass.initComponent.call(this);
  45. this.on({// hacks to force the labeleditor to stop editing when we get a click elsewhere
  46. click: function() {
  47. this.plugins[1].completeEdit();
  48. },
  49. containerclick: function(dv, e) {
  50. this.plugins[1].completeEdit();
  51. },
  52. contextmenu: this.onContextMenu,
  53. containercontextmenu: this.onContextMenu,
  54. scope: this
  55. });
  56. this.store.on('update', this.syncRename, this);
  57. },
  58. afterRender: function() {
  59. Imgorg.ImageDv.superclass.afterRender.call(this);
  60. this.el.unselectable(); // messy if they can select the text of the file names
  61. },
  62. onContextMenu: function(e, node) {
  63. e.stopEvent();
  64. if(!this.contMenu) {
  65. this.contMenu = new Ext.menu.Menu({
  66. items: [{
  67. text: 'View in Tab(s)',
  68. handler: function() {
  69. this.fireEvent('viewitem', this, node);
  70. },
  71. scope: this
  72. },{
  73. text: 'Add to Album',
  74. handler: this.selectAlbum,
  75. scope: this
  76. },{
  77. text: 'Tag',
  78. handler: this.tag,
  79. scope: this
  80. },{
  81. text: 'Remove',
  82. handler: this.removeImages,
  83. scope: this
  84. }]
  85. });
  86. }
  87. this.currentNode = node;
  88. this.contMenu.showAt(e.getXY());
  89. },
  90. selectAlbum: function() {
  91. if (!this.albumWin) {
  92. this.albumWin = new Imgorg.AlbumWin();
  93. }
  94. this.albumWin.selectedRecords = this.getSelectedRecords();
  95. this.albumWin.show(this.currentNode);
  96. },
  97. tag: function() {
  98. Imgorg.TagWin.selectedRecords = this.getSelectedRecords();
  99. Imgorg.TagWin.show(this.currentNode);
  100. },
  101. syncRename: function(store, rec, op) {
  102. if (op == 'edit') {
  103. Imgorg.ss.Images.rename({image: rec.data.id, name: rec.data.filename, url: rec.data.url});
  104. }
  105. },
  106. removeImages: function() {
  107. var recs = this.getSelectedRecords();
  108. var imageIds = [];
  109. for (var i = 0;i < recs.length;i++) {
  110. imageIds.push(recs[i].data.id);
  111. this.store.remove(recs[i]);
  112. }
  113. Imgorg.ss.Images.remove({images: imageIds});
  114. }
  115. });
  116. Ext.reg('img-dv', Imgorg.ImageDv);