album.items.view.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. GAL.view.AlbumItems = function(config) {
  2. config = config || {};
  3. this._initTemplates();
  4. Ext.applyIf(config,{
  5. url: GAL.config.connector_url
  6. ,fields: ['id','album','name','description','mediatype','url','createdon','createdby','filename','filesize','thumbnail','image','image_width','image_height','tags','active','rank','absoluteImage','relativeImage','menu']
  7. ,ident: 'galbit'
  8. ,id: 'gal-album-items-view'
  9. ,baseParams: {
  10. action: 'mgr/item/getList'
  11. ,album: config.album
  12. }
  13. ,loadingText: _('loading')
  14. ,tpl: this.templates.thumb
  15. ,enableDD: true
  16. ,multiSelect: true
  17. ,itemSelector: 'div.modx-browser-thumb-wrap'
  18. ,listeners: {
  19. 'selectionchange': {fn:this.showDetails, scope:this, buffer:100}
  20. ,'dblclick': config.onSelect || {fn:Ext.emptyFn,scope:this}
  21. }
  22. ,prepareData: this.formatData.createDelegate(this)
  23. });
  24. GAL.view.AlbumItems.superclass.constructor.call(this,config);
  25. this.on('selectionchange',this.showDetails,this,{buffer: 100});
  26. this.addEvents('sort','select');
  27. this.on('sort',this.onSort,this);
  28. this.on('dblclick',this.onDblClick,this);
  29. };
  30. Ext.extend(GAL.view.AlbumItems,MODx.DataView,{
  31. templates: {}
  32. ,windows: {}
  33. ,onSort: function(o) {
  34. MODx.Ajax.request({
  35. url: this.config.url
  36. ,params: {
  37. action: 'mgr/item/sort'
  38. ,album: this.config.album
  39. ,source: o.source.id
  40. ,target: o.target.id
  41. }
  42. });
  43. }
  44. ,onDblClick: function(d,idx,n) {
  45. var node = this.getSelectedNodes()[0];
  46. if (!node) return false;
  47. if (this.config.inPanel) {
  48. this.cm.activeNode = node;
  49. this.updateItem(node,n);
  50. } else {
  51. var data = this.lookup[node.id];
  52. this.fireEvent('select',data);
  53. }
  54. }
  55. ,updateItem: function(btn,e) {
  56. var node = this.cm.activeNode;
  57. var data = this.lookup[node.id];
  58. if (!data) return false;
  59. /* We'll need a "fresh" window when using Tiny for the description field,
  60. * so we don't check if it exists but just load a new window.
  61. */
  62. this.windows.updateItem = MODx.load({
  63. xtype: 'gal-window-item-update'
  64. ,listeners: {
  65. 'success': {fn:function() { this.store.reload(); },scope:this}
  66. }
  67. });
  68. this.windows.updateItem.setValues(data);
  69. this.windows.updateItem.show(e.target);
  70. }
  71. ,setAsCover:function(btn,e) {
  72. var node = this.cm.activeNode;
  73. var data = this.lookup[node.id];
  74. if (!data) return false;
  75. MODx.Ajax.request({
  76. url: this.config.url
  77. ,params: {
  78. action: 'mgr/album/setCoverItem'
  79. ,id: data.id
  80. ,albumid: data.album
  81. }
  82. ,listeners: {
  83. 'success': {fn:function(r) {
  84. var panel=Ext.getCmp('gal-panel-album');
  85. panel.getForm().setValues(r.object);
  86. },scope:this}
  87. }
  88. });
  89. }
  90. ,deleteItem: function(btn,e) {
  91. var node = this.cm.activeNode;
  92. var data = this.lookup[node.id];
  93. if (!data) return false;
  94. MODx.msg.confirm({
  95. text: _('gallery.item_delete_confirm')
  96. ,url: this.config.url
  97. ,params: {
  98. action: 'mgr/item/remove'
  99. ,id: data.id
  100. }
  101. ,listeners: {
  102. 'success': {fn:function(r) { this.store.reload(); },scope:this}
  103. }
  104. });
  105. }
  106. ,deleteMultiple: function(btn,e) {
  107. var recs = this.getSelectedRecords();
  108. if (!recs) return false;
  109. var ids = '';
  110. for (var i=0;i<recs.length;i++) {
  111. ids += ','+recs[i].id;
  112. }
  113. MODx.msg.confirm({
  114. text: _('gallery.item_delete_multiple_confirm')
  115. ,url: this.config.url
  116. ,params: {
  117. action: 'mgr/item/removeMultiple'
  118. ,ids: ids.substr(1)
  119. }
  120. ,listeners: {
  121. 'success': {fn:function(r) { this.store.reload(); },scope:this}
  122. }
  123. });
  124. return true;
  125. }
  126. ,run: function(p) {
  127. p = p || {};
  128. var v = {};
  129. Ext.apply(v,this.store.baseParams);
  130. Ext.apply(v,p);
  131. this.pagingBar.changePage(1);
  132. this.store.baseParams = v;
  133. this.store.load();
  134. }
  135. ,sortBy: function(sel) {
  136. this.store.baseParams.sorter = sel.getValue();
  137. this.store.reload();
  138. return true;
  139. }
  140. ,sortDir: function(sel) {
  141. this.store.baseParams.dir = sel.getValue();
  142. this.store.reload();
  143. }
  144. ,showDetails : function(){
  145. var selNode = this.getSelectedNodes();
  146. var detailEl = Ext.getCmp('gal-album-items-detail').body;
  147. if(selNode && selNode.length > 0){
  148. selNode = selNode[0];
  149. var data = this.lookup[selNode.id];
  150. if (data) {
  151. detailEl.hide();
  152. this.templates.details.overwrite(detailEl, data);
  153. detailEl.slideIn('l', {stopFx:true,duration:'.2'});
  154. }
  155. }else{
  156. detailEl.update('');
  157. }
  158. }
  159. ,formatData: function(data) {
  160. var formatSize = function(data){
  161. if(data.size < 1024) {
  162. return data.size + ' '+_('gallery.bytes');
  163. } else {
  164. return (Math.round(((data.size*10) / 1024))/10) + " KB";
  165. }
  166. };
  167. data.shortName = Ext.util.Format.ellipsis(data.name, 16);
  168. data.sizeString = formatSize(data);
  169. data.releasedon = new Date(data.releasedon).format("m/d/Y g:i a");
  170. this.lookup['gal-item-'+data.id] = data;
  171. return data;
  172. }
  173. ,_initTemplates: function() {
  174. this.templates.thumb = new Ext.XTemplate(
  175. '<tpl for=".">'
  176. ,'<div class="modx-browser-thumb-wrap modx-pb-thumb-wrap <tpl if="!active">gal-item-inactive</tpl>" id="gal-item-{id}">'
  177. ,'<div class="modx-browser-thumb gal-item-thumb">'
  178. ,'<img src="{thumbnail}" title="{name}" />'
  179. ,'</div>'
  180. ,'<span>{shortName}</span>'
  181. ,'</div>'
  182. ,'</tpl>'
  183. );
  184. this.templates.thumb.compile();
  185. this.templates.details = new Ext.XTemplate(
  186. '<div class="details">'
  187. ,'<tpl for=".">'
  188. ,'<div class="modx-browser-detail-thumb modx-pb-detail-thumb"><img src="{image}" alt="{shortName}" onclick="Ext.getCmp(\'gal-album-items-view\').showScreenshot(\'{id}\'); return false;" /></div>'
  189. ,'<div class="modx-browser-details-info modx-pb-details-info">'
  190. ,'<span class="gal-detail-active">'
  191. ,'<tpl if="active"><span class="green">'+_('gallery.active')+'</span></tpl>'
  192. ,'<tpl if="!active"><span class="red">'+_('gallery.inactive')+'</span></tpl>'
  193. ,'</span>'
  194. ,'<h4>{shortName}</h4><br />'
  195. ,'<tpl if="description"><p>{description}</p><br /></tpl>'
  196. ,'<b>'+_('id')+':</b><span>{id}</span>'
  197. ,'<b>'+_('gallery.file_name')+':</b><span>{filename}</span>'
  198. ,'<b>'+_('gallery.file_size')+':</b><span>{filesize}</span>'
  199. ,'<tpl if="tags"><b>'+_('gallery.tags')+':</b><span>{tags}</span></tpl>'
  200. ,'<tpl if="url"><b>'+_('gallery.item_url')+':</b><span>{url}</span></tpl>'
  201. ,'</div>'
  202. ,'</tpl>'
  203. ,'</div>'
  204. );
  205. this.templates.details.compile();
  206. }
  207. ,showScreenshot: function(id) {
  208. var data = this.lookup['gal-item-'+id];
  209. if (!data) return false;
  210. if (!this.ssWin) {
  211. this.ssWin = new Ext.Window({
  212. layout:'fit'
  213. ,width: 600
  214. ,height: 450
  215. ,closeAction:'hide'
  216. ,plain: true
  217. ,items: [{
  218. id: 'gal-item-ss'
  219. ,html: ''
  220. }]
  221. ,buttons: [{
  222. text: _('close')
  223. ,handler: function() { this.ssWin.hide(); }
  224. ,scope: this
  225. }]
  226. });
  227. }
  228. this.ssWin.show();
  229. this.ssWin.setSize(data.image_width,data.image_height);
  230. this.ssWin.center();
  231. this.ssWin.setTitle(data.name);
  232. Ext.get('gal-item-ss').update('<img src="'+data.image+'" alt="" onclick="Ext.getCmp(\'gal-album-items-view\').ssWin.hide();" />');
  233. }
  234. ,_showContextMenu: function(v,i,n,e) {
  235. e.preventDefault();
  236. var data = this.lookup[n.id];
  237. var m = this.cm;
  238. m.removeAll();
  239. var ct = this.getSelectionCount();
  240. if (ct == 1) {
  241. m.add({
  242. text: _('gallery.item_update')
  243. ,handler: this.updateItem
  244. ,scope: this
  245. });
  246. m.add({
  247. text: _('gallery.set_as_cover')
  248. ,handler: this.setAsCover
  249. ,scope: this
  250. });
  251. m.add('-');
  252. m.add({
  253. text: _('gallery.item_delete')
  254. ,handler: this.deleteItem
  255. ,scope: this
  256. });
  257. m.show(n,'tl-c?');
  258. } else if (ct > 1) {
  259. m.add({
  260. text: _('gallery.item_delete_multiple')
  261. ,handler: this.deleteMultiple
  262. ,scope: this
  263. });
  264. m.show(n,'tl-c?');
  265. }
  266. m.activeNode = n;
  267. }
  268. });
  269. Ext.reg('gal-view-album-items',GAL.view.AlbumItems);