| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- var galTreeHandlerClass = function(config) {
- config = config || {};
- Ext.apply(config,{
- id: 'gal-tree-handler'
- });
- galTreeHandlerClass.superclass.constructor.call(this,config);
- };
- Ext.extend(galTreeHandlerClass,Ext.Component,{
- tree: null
- ,data: {}
- ,windows: {}
- ,getMenu: function(t,node,e) {
- this.tree = t;
- this.data = node.attributes && node.attributes.data ? node.attributes.data : {};
- var m = [];
- switch (node.attributes.type) {
- case 'root':
- m = this.getRootMenu(node,e);
- break;
- case 'gallery-album':
- m = this.getAlbumMenu(node,e);
- break;
- case 'gallery-item':
- m = this.getItemMenu(node,e);
- break;
- }
- return m;
- }
- /* custom methods here */
- ,getItemMenu: function(node,e) {
- return [{
- text: _('gallery.item_update')
- ,handler: this.updateItem
- ,scope: this
- },'-',{
- text: _('gallery.item_remove')
- ,handler: this.removeItem
- ,scope: this
- }];
- }
- ,getAlbumMenu: function(node,e) {
- return [{
- text: _('gallery.album_create')
- ,handler: this.createAlbum
- ,scope: this
- },'-',{
- text: _('gallery.album_update')
- ,handler: this.updateAlbum
- ,scope: this
- },{
- text: _('gallery.upload')
- ,menu: {
- items: [{
- text: _('gallery.item_upload')
- ,handler: this.uploadItem
- ,scope: this
- },{
- text: _('gallery.multi_item_upload')
- ,handler: this.uploadMultiItems
- ,scope: this
- },{
- text: _('gallery.batch_upload')
- ,handler: this.batchUpload
- ,scope: this
- },{
- text: _('gallery.zip_upload')
- ,handler: this.zipUpload
- ,scope: this
- }]
- }
- },'-',{
- text: _('gallery.album_remove')
- ,handler: this.removeAlbum
- ,scope: this
- }];
- }
- ,getRootMenu: function(node,e) {
- return [{
- text: _('gallery.album_create')
- ,handler: this.createAlbum
- ,scope: this
- }];
- }
- ,createAlbum: function(btn,e) {
- var r;
- if (this.data.id) {
- var n = this.tree.cm.activeNode.attributes.data;
- r = {
- 'parent': n.id
- ,parent_name: n.name
- };
- } else {
- r = {'parent':0,parent_name:_('none')};
- }
- if (!this.windows.createAlbum) {
- this.windows.createAlbum = MODx.load({
- xtype: 'gal-window-album-create'
- ,record: r
- ,listeners: {
- 'success': {fn:function() { this.tree.refreshParentNode(); },scope:this}
- }
- });
- }
- this.windows.createAlbum.fp.getForm().reset();
- this.windows.createAlbum.setValues(r);
- this.windows.createAlbum.show(e.target);
- }
- ,updateAlbum: function(btn,e) {
- var id = this.data.id ? this.data.id : 0;
- location.href = '?a='+MODx.action['gallery:index']+'&album='+id+'&action=album/update';
- }
- ,removeAlbum: function(btn,e) {
- MODx.msg.confirm({
- text: _('gallery.album_remove_confirm')
- ,url: GAL.config.connector_url
- ,params: {
- action: 'mgr/album/remove'
- ,id: this.tree.cm.activeNode.attributes.data.id
- }
- ,listeners: {
- 'success': {fn:function(r) { this.tree.refreshParentNode(); },scope:this}
- }
- });
- }
- ,updateItem: function(btn,e) {
- this.windows.updateItem = MODx.load({
- xtype: 'gal-window-item-update'
- ,listeners: {
- 'success': {fn:function() { this.tree.refreshParentNode(); },scope:this}
- }
- });
- this.windows.updateItem.setValues(this.data);
- this.windows.updateItem.show(e.target);
- }
- ,removeItem: function(btn,e) {
- MODx.msg.confirm({
- text: _('gallery.item_delete_confirm')
- ,url: GAL.config.connector_url
- ,params: {
- action: 'mgr/item/remove'
- ,id: this.data.id
- }
- ,listeners: {
- 'success': {fn:function(r) { this.tree.refreshParentNode(); },scope:this}
- }
- });
- }
- ,uploadMultiItems: function(btn,e) {
- var r = {
- album: this.data.id
- ,active: true
- };
- if (!this.windows.uploadMultiItems) {
- this.windows.uploadMultiItems = MODx.load({
- xtype: 'gal-window-multi-item-upload'
- ,album: this.data.id
- ,record: r
- ,listeners: {
- 'success': {fn:function() { this.tree.refreshParentNode(); },scope:this}
- }
- });
- }
- this.windows.uploadMultiItems.fp.getForm().reset();
- this.windows.uploadMultiItems.setValues(r);
- this.windows.uploadMultiItems.show(e.target);
- }
- ,uploadItem: function(btn,e) {
- var r = {
- album: this.data.id
- ,active: true
- };
- if (!this.windows.uploadItem) {
- this.windows.uploadItem = MODx.load({
- xtype: 'gal-window-item-upload'
- ,record: r
- ,listeners: {
- 'success': {fn:function() { this.tree.refreshParentNode(); },scope:this}
- }
- });
- }
- this.windows.uploadItem.fp.getForm().reset();
- this.windows.uploadItem.setValues(r);
- this.windows.uploadItem.show(e.target);
- }
- ,batchUpload: function(btn,e) {
- var r = {
- album: this.data.id
- ,active: true
- };
- if (!this.windows.batchUpload) {
- this.windows.batchUpload = MODx.load({
- xtype: 'gal-window-batch-upload'
- ,record: r
- ,listeners: {
- 'success': {fn:function() { this.tree.refreshParentNode(); },scope:this}
- }
- });
- } else {
- this.windows.batchUpload.fp.getForm().reset();
- }
- this.windows.batchUpload.setValues(r);
- this.windows.batchUpload.show(e.target);
- }
- ,zipUpload: function(btn,e) {
- var r = {
- album: this.data.id
- ,active: true
- };
- if (!this.windows.zipUpload) {
- this.windows.zipUpload = MODx.load({
- xtype: 'gal-window-zip-upload'
- ,record: r
- ,listeners: {
- 'success': {fn:function() { this.tree.refreshParentNode(); },scope:this}
- }
- });
- } else {
- this.windows.zipUpload.fp.getForm().reset();
- }
- this.windows.zipUpload.setValues(r);
- this.windows.zipUpload.show(e.target);
- }
- ,handleDrop: function(t,dropEvent) {
- this.tree = t;
- var dropNode = dropEvent.dropNode;
- var target = dropEvent.target;
- if (!target.attributes.type) return false;
- if (target.attributes.type == 'gallery-album' && dropNode.attributes.type == 'gallery-item' && dropEvent.point != 'append') return false;
- if (dropNode.attributes.type == 'gallery-album' && target.attributes.type == 'gallery-item') return false;
- return true;
- }
- });
- Ext.reg('gal-tree-handler',galTreeHandlerClass);
- var galTreeHandler = new galTreeHandlerClass();
- var galItemDropHandlerClass = function(config) {
- config = config || {};
- Ext.apply(config,{
- id: 'gallery-item-drop-handler'
- });
- galItemDropHandlerClass.superclass.constructor.call(this,config);
- };
- Ext.extend(galItemDropHandlerClass,Ext.Component,{
- handle: function(target,opt) {
- var na = target.node.attributes;
- var cfg = {
- ddTargetEl: opt.ddTargetEl
- ,cfg: opt.cfg
- ,iframe: opt.cfg.iframe
- ,iframeEl: opt.cfg.iframeEl
- ,onInsert: opt.cfg.onInsert
- ,panel: opt.cfg.panel
- ,classKey: 'modSnippet'
- ,pk: GAL.snippetGalleryItem
- ,name: 'GalleryItem'
- };
- GAL.elProps = {
- id: na.data.id
- };
- MODx.loadInsertElement(cfg);
- setTimeout("galTreeWorkaround(GAL.elProps);",600);
- return true;
- }
- });
- var galItemDropHandler = new galItemDropHandlerClass();
- var galAlbumDropHandlerClass = function(config) {
- config = config || {};
- Ext.apply(config,{
- id: 'gallery-album-drop-handler'
- });
- galAlbumDropHandlerClass.superclass.constructor.call(this,config);
- };
- Ext.extend(galAlbumDropHandlerClass,Ext.Component,{
- handle: function(target,opt) {
- var na = target.node.attributes;
- var cfg = {
- ddTargetEl: opt.ddTargetEl
- ,cfg: opt.cfg
- ,iframe: opt.cfg.iframe
- ,iframeEl: opt.cfg.iframeEl
- ,onInsert: opt.cfg.onInsert
- ,panel: opt.cfg.panel
- ,classKey: 'modSnippet'
- ,pk: GAL.snippetGallery
- ,name: 'Gallery'
- };
- GAL.elProps = {
- album: na.data.id
- };
- MODx.loadInsertElement(cfg);
- setTimeout("galTreeWorkaround(GAL.elProps);",600);
- return true;
- }
- });
- var galAlbumDropHandler = new galAlbumDropHandlerClass();
- /* because im an idiot and forgot win show events in the insert element window */
- function galTreeWorkaround(props) {
- var w = Ext.getCmp('modx-window-insert-element');
- w.modps = [];
- if (w) {
- for (var k in props) {
- var fld = Ext.getCmp('modx-iprop-'+k);
- if (fld) {
- fld.setValue(props[k]);
- w.changeProp(k);
- }
- }
- }
- };
- /* because im an idiot and prevented drag/drop of non-leaf nodes in modx core */
- setTimeout('galleryFixLeafDrag();',1200);
- function galleryFixLeafDrag() {
- var t = Ext.getCmp('modx-file-tree');
- if (t) {
- t.on('startdrag',function(t,n,e) {
- if (n.attributes.type == 'gallery-album') {
- n.attributes.leaf = true;
- }
- },this);
- }
- }
|