album.panel.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. GAL.panel.Album = function(config) {
  2. config = config || {};
  3. Ext.apply(config,{
  4. id: 'gal-panel-album'
  5. ,url: GAL.config.connector_url
  6. ,baseParams: {}
  7. ,border: false
  8. ,baseCls: 'modx-formpanel'
  9. ,cls: 'container form-with-labels'
  10. ,items: [{
  11. html: '<h2>'+_('gallery.album')+'</h2>'
  12. ,border: false
  13. ,id: 'gal-album-header'
  14. ,cls: 'modx-page-header'
  15. },{
  16. xtype: 'modx-tabs'
  17. ,defaults: { border: false ,autoHeight: true }
  18. ,border: true
  19. ,activeItem: 0
  20. ,hideMode: 'offsets'
  21. ,items: [{
  22. title: _('general_information')
  23. ,border: false
  24. ,items: [{
  25. layout: 'column'
  26. ,border: false
  27. ,defaults: {
  28. layout: 'form'
  29. ,labelAlign: 'top'
  30. ,anchor: '100%'
  31. ,border: false
  32. ,cls:'main-wrapper'
  33. ,labelSeparator: ''
  34. }
  35. ,items: [{
  36. columnWidth: .6
  37. ,items: [{
  38. xtype: 'hidden'
  39. ,fieldLabel: _('id')
  40. ,name: 'id'
  41. ,submitValue: true
  42. },{
  43. xtype: 'textfield'
  44. ,fieldLabel: _('name')
  45. ,name: 'name'
  46. ,anchor: '100%'
  47. ,allowBlank: false
  48. },{
  49. xtype: 'textfield'
  50. ,fieldLabel: _('gallery.year')
  51. ,name: 'year'
  52. ,anchor: '100%'
  53. ,allowBlank: true
  54. },{
  55. xtype: 'textarea'
  56. ,fieldLabel: _('description')
  57. ,name: 'description'
  58. ,anchor: '100%'
  59. },{
  60. layout: 'column'
  61. ,border:false
  62. ,fieldLabel: _('gallery.cover_filename')
  63. ,items: [{
  64. xtype: 'textfield'
  65. ,name: 'cover_filename'
  66. ,id: 'cover_filename'
  67. ,readOnly: true
  68. ,allowBlank: true
  69. ,columnWidth: .6
  70. },{
  71. xtype:'hidden'
  72. ,name:'cover_filename_url'
  73. ,id:'cover_filename_url'
  74. },{
  75. xtype:'button'
  76. ,text: _('gallery.upload_cover')
  77. ,cls: 'primary-button'
  78. // ,height: 39
  79. ,handler: this.updateCover
  80. },{
  81. xtype:'button'
  82. ,text: _('gallery.delete_cover')
  83. // ,height: 39
  84. ,handler:function() {
  85. var panel=Ext.getCmp('gal-panel-album').getForm();
  86. panel.findField('cover_filename').setValue('');
  87. panel.findField('cover_filename_url').setValue('');
  88. }
  89. }]
  90. }]
  91. },{
  92. columnWidth: .4
  93. ,items: [{
  94. xtype: 'checkbox'
  95. ,boxLabel: _('gallery.active')
  96. ,description: MODx.expandHelp ? '' : _('gallery.active_desc')
  97. ,id: 'gallery-album-active'
  98. ,name: 'active'
  99. ,hideLabel: true
  100. ,inputValue: true
  101. },{
  102. xtype: MODx.expandHelp ? 'label' : 'hidden'
  103. ,forId: 'gallery-album-active'
  104. ,text: _('gallery.active_desc')
  105. ,cls: 'desc-under'
  106. },{
  107. xtype: 'checkbox'
  108. ,boxLabel: _('gallery.prominent')
  109. ,description: MODx.expandHelp ? '' : _('gallery.prominent_desc')
  110. ,id: 'gallery-album-prominent'
  111. ,name: 'prominent'
  112. ,hideLabel: true
  113. ,inputValue: true
  114. },{
  115. xtype: MODx.expandHelp ? 'label' : 'hidden'
  116. ,forId: 'gallery-album-prominent'
  117. ,text: _('gallery.prominent_desc')
  118. ,cls: 'desc-under'
  119. }]
  120. }]
  121. },{
  122. html: '<hr />',border: false
  123. },{
  124. xtype: 'gal-panel-album-items'
  125. ,cls: 'modx-pb-view-ct main-wrapper'
  126. ,album: config.album
  127. ,anchor: '100%'
  128. }]
  129. }]
  130. /*,{
  131. title: 'Context Access'
  132. ,layout: 'form'
  133. ,items: [{
  134. html: '<p>Manage the Contexts that have access to this album.</p><br />'
  135. ,border: false
  136. }]
  137. }*/
  138. }]
  139. ,listeners: {
  140. 'setup': {fn:this.setup,scope:this}
  141. ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
  142. ,'success': {fn:this.success,scope:this}
  143. }
  144. });
  145. GAL.panel.Album.superclass.constructor.call(this,config);
  146. };
  147. Ext.extend(GAL.panel.Album,MODx.FormPanel,{
  148. initialized: false
  149. ,windows: {}
  150. ,setup: function() {
  151. if (!this.config.album || this.initialized) return;
  152. MODx.Ajax.request({
  153. url: this.config.url
  154. ,params: {
  155. action: 'mgr/album/get'
  156. ,id: this.config.album
  157. }
  158. ,listeners: {
  159. 'success': {fn:function(r) {
  160. this.getForm().setValues(r.object);
  161. Ext.getCmp('gal-album-header').getEl().update('<h2>'+_('gallery.album')+': '+r.object.name+'</h2>');
  162. this.initialized = true;
  163. },scope:this}
  164. }
  165. });
  166. }
  167. ,beforeSubmit: function(o) {
  168. Ext.apply(o.form.baseParams,{
  169. });
  170. }
  171. ,updateCover:function(btn,e) {
  172. var form=this.findParentByType('gal-panel-album');
  173. var data=form.getForm().getValues();
  174. /**
  175. * We'll need a "fresh" window when using Tiny for the description field,
  176. * so we don't check if it exists but just load a new window.
  177. */
  178. form.windows.updateCover = MODx.load({
  179. xtype: 'gal-window-cover-update'
  180. ,listeners: {
  181. 'success': function(o) {
  182. if(o.a.result.object) {
  183. var panel=Ext.getCmp('gal-panel-album');
  184. panel.getForm().setValues(o.a.result.object);
  185. }
  186. this.close();
  187. }
  188. }
  189. });
  190. form.windows.updateCover.setValues(data);
  191. var previewDivName=form.windows.updateCover.ident+'-preview';
  192. var preview=form.windows.updateCover.find('id',previewDivName);
  193. if(preview.length>0) {
  194. if(data.cover_filename_url!='') {
  195. var now=new Date();
  196. preview[0].html='<img src="'+data.cover_filename_url+'&time='+now.getTime()+'"/>';
  197. } else {
  198. preview[0].setVisible(false);
  199. }
  200. }
  201. form.windows.updateCover.show(e.target);
  202. }
  203. ,success: function(o) {
  204. Ext.getCmp('gal-btn-save').setDisabled(false);
  205. }
  206. });
  207. Ext.reg('gal-panel-album',GAL.panel.Album);
  208. GAL.panel.AlbumItems = function(config) {
  209. config = config || {};
  210. this.view = MODx.load({
  211. id: 'gal-album-items-view'
  212. ,xtype: 'gal-view-album-items'
  213. ,onSelect: {fn:function() { }, scope: this}
  214. ,containerScroll: true
  215. ,ident: this.ident
  216. ,cls: 'gal-view-album-items'
  217. ,album: config.album
  218. ,inPanel: true
  219. ,style: 'overflow: auto;'
  220. });
  221. this.view.pagingBar = new Ext.PagingToolbar({
  222. pageSize: config.pageSize || (parseInt(MODx.config.default_per_page) || 24)
  223. ,store: this.view.store
  224. ,displayInfo: true
  225. ,autoLoad: true
  226. ,items: [
  227. '-'
  228. ,_('per_page')+':'
  229. ,{
  230. xtype: 'textfield'
  231. ,value: config.pageSize || (parseInt(MODx.config.default_per_page) || 20)
  232. ,width: 40
  233. ,listeners: {
  234. 'change': {fn:function(tf,nv,ov) {
  235. if (Ext.isEmpty(nv)) return false;
  236. nv = parseInt(nv);
  237. this.view.pagingBar.pageSize = nv;
  238. this.view.store.load({params:{
  239. start:0
  240. ,limit: nv
  241. }});
  242. },scope:this}
  243. ,'render': {fn: function(cmp) {
  244. new Ext.KeyMap(cmp.getEl(), {
  245. key: Ext.EventObject.ENTER
  246. ,fn: function() {
  247. this.fireEvent('change',this.getValue());
  248. this.blur();
  249. return true;}
  250. ,scope: cmp
  251. });
  252. },scope:this}
  253. }
  254. }
  255. ,'-'
  256. ]
  257. });
  258. var dv = this.view;
  259. dv.on('render', function() {
  260. dv.dragZone = new MODx.DataView.dragZone(dv);
  261. dv.dropZone = new MODx.DataView.dropZone(dv);
  262. });
  263. Ext.applyIf(config,{
  264. id: 'gal-panel-album-items'
  265. ,cls: 'browser-win'
  266. ,layout: 'column'
  267. ,minWidth: 500
  268. ,minHeight: 350
  269. ,autoHeight: true
  270. ,modal: false
  271. ,closeAction: 'hide'
  272. ,border: false
  273. ,autoScroll: true
  274. ,items: [{
  275. id: 'gal-album-items-ct'
  276. ,cls: 'browser-view'
  277. ,region: 'center'
  278. ,width: '75%'
  279. ,minHeight: 450
  280. ,autoScroll: true
  281. ,border: false
  282. ,items: [{
  283. xtype: 'toolbar'
  284. ,items: [{
  285. xtype: 'button'
  286. ,text: _('gallery.item_upload')
  287. ,handler: this.uploadItem
  288. ,scope: this
  289. },'-',{
  290. xtype: 'button'
  291. ,text: _('gallery.multi_item_upload')
  292. ,handler: this.uploadMultiItems
  293. ,scope: this
  294. },'-',{
  295. xtype: 'button'
  296. ,text: _('gallery.batch_upload')
  297. ,handler: this.batchUpload
  298. ,scope: this
  299. },'-',{
  300. xtype: 'button'
  301. ,text: _('gallery.zip_upload')
  302. ,handler: this.zipUpload
  303. ,scope: this
  304. }]
  305. },this.view]
  306. ,bbar: [this.view.pagingBar]
  307. },{
  308. html: ''
  309. ,id: 'gal-album-items-detail'
  310. ,region: 'east'
  311. ,split: true
  312. ,autoScroll: true
  313. ,width: '25%'
  314. ,minWidth: 150
  315. // ,maxWidth: 250
  316. ,height: 450
  317. ,border: false
  318. }]
  319. });
  320. GAL.panel.AlbumItems.superclass.constructor.call(this,config);
  321. };
  322. Ext.extend(GAL.panel.AlbumItems,MODx.Panel,{
  323. windows: {}
  324. ,uploadMultiItems: function(btn,e) {
  325. var r = {
  326. album: this.config.album
  327. ,active: true
  328. };
  329. if (!this.windows.uploadMultiItems) {
  330. this.windows.uploadMultiItems = MODx.load({
  331. xtype: 'gal-window-multi-item-upload'
  332. ,album: this.config.album
  333. ,listeners: {
  334. 'success': {fn:function() { this.view.run(); },scope:this}
  335. }
  336. });
  337. }
  338. this.windows.uploadMultiItems.fp.getForm().reset();
  339. this.windows.uploadMultiItems.setValues(r);
  340. this.windows.uploadMultiItems.show(e.target);
  341. }
  342. ,uploadItem: function(btn,e) {
  343. var r = {
  344. album: this.config.album
  345. ,active: true
  346. };
  347. if (!this.windows.uploadItem) {
  348. this.windows.uploadItem = MODx.load({
  349. xtype: 'gal-window-item-upload'
  350. ,listeners: {
  351. 'success': {fn:function() { this.view.run(); },scope:this}
  352. }
  353. });
  354. }
  355. this.windows.uploadItem.fp.getForm().reset();
  356. this.windows.uploadItem.setValues(r);
  357. this.windows.uploadItem.show(e.target);
  358. }
  359. ,batchUpload: function(btn,e) {
  360. var r = {
  361. album: this.config.album
  362. ,active: true
  363. };
  364. if (!this.windows.batchUpload) {
  365. this.windows.batchUpload = MODx.load({
  366. xtype: 'gal-window-batch-upload'
  367. ,listeners: {
  368. 'success': {fn:function() { this.view.run(); },scope:this}
  369. }
  370. });
  371. } else {
  372. this.windows.batchUpload.fp.getForm().reset();
  373. }
  374. this.windows.batchUpload.setValues(r);
  375. this.windows.batchUpload.show(e.target);
  376. }
  377. ,zipUpload: function(btn,e) {
  378. var r = {
  379. album: this.config.album
  380. ,active: true
  381. };
  382. if (!this.windows.zipUpload) {
  383. this.windows.zipUpload = MODx.load({
  384. xtype: 'gal-window-zip-upload'
  385. ,listeners: {
  386. 'success': {fn:function() { this.view.run(); },scope:this}
  387. }
  388. });
  389. } else {
  390. this.windows.zipUpload.fp.getForm().reset();
  391. }
  392. this.windows.zipUpload.setValues(r);
  393. this.windows.zipUpload.show(e.target);
  394. }
  395. });
  396. Ext.reg('gal-panel-album-items',GAL.panel.AlbumItems);