album.tree.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. GAL.tree.Album = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. id: 'gal-tree-album'
  5. ,url: GAL.config.connector_url
  6. ,action: 'mgr/album/getNodes'
  7. ,tbar: [{
  8. text: _('gallery.album_create')
  9. ,cls: 'primary-button'
  10. ,handler: function(btn,e) { this.createAlbum(btn,e,true); }
  11. ,scope: this
  12. },'-',{
  13. text: _('gallery.refresh')
  14. ,handler: this.refresh
  15. ,scope: this
  16. }]
  17. ,sortAction: 'mgr/album/sort'
  18. ,rootVisible: false
  19. });
  20. GAL.tree.Album.superclass.constructor.call(this,config);
  21. };
  22. Ext.extend(GAL.tree.Album,MODx.tree.Tree,{
  23. windows: {}
  24. ,createAlbum: function(btn,e,b) {
  25. b = b || false;
  26. var r;
  27. if (this.cm.activeNode && !b) {
  28. var n = this.cm.activeNode.attributes;
  29. r = {
  30. 'parent': n.pk
  31. ,parent_name: n.name
  32. };
  33. } else {
  34. r = {'parent':0,parent_name:_('none')};
  35. }
  36. if (!this.windows.createAlbum) {
  37. this.windows.createAlbum = MODx.load({
  38. xtype: 'gal-window-album-create'
  39. ,record: r
  40. ,listeners: {
  41. 'success': {fn:function() { this.refresh(); },scope:this}
  42. }
  43. });
  44. }
  45. this.windows.createAlbum.fp.getForm().reset();
  46. this.windows.createAlbum.setValues(r);
  47. this.windows.createAlbum.show(e.target);
  48. }
  49. ,updateAlbum: function(btn,e) {
  50. var id = this.cm.activeNode ? this.cm.activeNode.attributes.pk : 0;
  51. location.href = '?a='+GAL.action+'&album='+id+'&action=album/update';
  52. }
  53. ,removeAlbum: function(btn,e) {
  54. if (!this.cm.activeNode) return false;
  55. MODx.msg.confirm({
  56. text: _('gallery.album_remove_confirm')
  57. ,url: this.config.url
  58. ,params: {
  59. action: 'mgr/album/remove'
  60. ,id: this.cm.activeNode.attributes.pk
  61. }
  62. ,listeners: {
  63. 'success': {fn:function(r) { this.refresh(); },scope:this}
  64. }
  65. });
  66. }
  67. ,_handleDrag: function(dropEvent) {
  68. var encNodes = this.encode();
  69. MODx.Ajax.request({
  70. url: this.config.url
  71. ,params: {
  72. data: encNodes
  73. ,action: this.config.sortAction
  74. }
  75. ,listeners: {
  76. 'success': {fn:function(r) {
  77. this.reloadNode(dropEvent.target.parentNode);
  78. },scope:this}
  79. ,'failure': {fn:function(r) {
  80. MODx.form.Handler.errorJSON(r);
  81. return false;
  82. },scope:this}
  83. }
  84. });
  85. }
  86. ,_handleDrop: function(e) {
  87. var target = e.target;
  88. var source = e.dropNode;
  89. var ap = true;
  90. return target.getDepth() <= source.getDepth() && ap;
  91. }
  92. });
  93. Ext.reg('gal-tree-album',GAL.tree.Album);