gal.browser.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. GAL.Browser = function(config) {
  2. if (GAL.browserOpen) return false;
  3. GAL.browserOpen = true;
  4. config = config || {};
  5. Ext.applyIf(config,{
  6. onSelect: function(data) {}
  7. ,scope: this
  8. ,cls: 'modx-browser'
  9. });
  10. GAL.Browser.superclass.constructor.call(this,config);
  11. this.config = config;
  12. this.win = new GAL.BrowserWindow(config);
  13. this.win.reset();
  14. };
  15. Ext.extend(GAL.Browser,Ext.Component,{
  16. show: function(el) { this.win.show(el); }
  17. ,hide: function() { this.win.hide(); }
  18. });
  19. Ext.reg('gal-browser',GAL.Browser);
  20. GAL.BrowserWindow = function(config) {
  21. config = config || {};
  22. this.ident = Ext.id();
  23. this.view = MODx.load({
  24. xtype: 'gal-view-album-items'
  25. ,cls: 'modx-pb-view-ct'
  26. ,album: config.album || 0
  27. ,listeners: {'select':{fn:this.onSelect,scope:this}}
  28. });
  29. this.view.pagingBar = new Ext.PagingToolbar({
  30. pageSize: 24
  31. ,store: this.view.store
  32. ,displayInfo: true
  33. ,autoLoad: true
  34. });
  35. this.tree = MODx.load({
  36. xtype: 'gal-tree-album'
  37. ,scope: this
  38. ,ident: this.ident
  39. ,rootVisible: config.rootVisible == null ? true : config.rootVisible
  40. ,listeners: {
  41. 'click': {fn:function(node,e) {
  42. this.load(node.attributes.pk);
  43. return false;
  44. e.stopPropagation();
  45. e.preventDefault();
  46. },scope: this}
  47. }
  48. ,tbar: []
  49. });
  50. Ext.applyIf(config,{
  51. title: _('gallery.browser')
  52. ,cls: 'modx-pb-win'
  53. ,layout: 'border'
  54. ,minWidth: 500
  55. ,minHeight: 300
  56. ,width: '90%'
  57. ,height: 500
  58. ,modal: false
  59. ,closeAction: 'hide'
  60. ,border: false
  61. ,items: [{
  62. id: this.ident+'-browser-tree'
  63. ,cls: 'modx-pb-browser-tree'
  64. ,region: 'west'
  65. ,width: 250
  66. ,height: '100%'
  67. ,items: this.tree
  68. ,border: false
  69. ,autoScroll: true
  70. },{
  71. id: this.ident+'-browser-view'
  72. ,cls: 'modx-pb-view-ct'
  73. ,region: 'center'
  74. ,autoScroll: true
  75. ,width: 450
  76. ,items: this.view
  77. ,border: false
  78. ,tbar: this.getToolbar()
  79. ,bbar: [this.view.pagingBar]
  80. },{
  81. html: ''
  82. ,id: 'gal-album-items-detail'
  83. ,region: 'east'
  84. ,split: true
  85. ,autoScroll: true
  86. ,width: '20%'
  87. ,minWidth: 150
  88. ,maxWidth: 250
  89. ,height: 450
  90. ,border: false
  91. }]
  92. ,buttons: [{
  93. id: this.ident+'-ok-btn'
  94. ,text: _('ok')
  95. ,handler: this.onSelect
  96. ,scope: this
  97. },{
  98. text: _('cancel')
  99. ,handler: this.hide
  100. ,scope: this
  101. }]
  102. ,keys: {
  103. key: 27
  104. ,handler: this.hide
  105. ,scope: this
  106. }
  107. });
  108. GAL.BrowserWindow.superclass.constructor.call(this,config);
  109. this.config = config;
  110. this.addEvents({
  111. 'select': true
  112. });
  113. };
  114. Ext.extend(GAL.BrowserWindow,Ext.Window,{
  115. returnEl: null
  116. ,filter : function(){
  117. var filter = Ext.getCmp('filter');
  118. this.view.store.filter('name', filter.getValue(),true);
  119. this.view.select(0);
  120. }
  121. ,setReturn: function(el) {
  122. this.returnEl = el;
  123. }
  124. ,load: function(id) {
  125. this.view.run({album: id});
  126. }
  127. ,sortImages : function(){
  128. var v = Ext.getCmp('sortSelect').getValue();
  129. this.view.store.sort(v, v == 'name' ? 'asc' : 'desc');
  130. this.view.select(0);
  131. }
  132. ,reset: function(){
  133. if(this.rendered){
  134. Ext.getCmp('filter').reset();
  135. this.view.getEl().dom.scrollTop = 0;
  136. }
  137. this.view.store.clearFilter();
  138. this.view.select(0);
  139. }
  140. ,getToolbar: function() {
  141. return [{
  142. text: _('filter')+':'
  143. },{
  144. xtype: 'textfield'
  145. ,id: 'filter'
  146. ,selectOnFocus: true
  147. ,width: 100
  148. ,listeners: {
  149. 'render': {fn:function(){
  150. Ext.getCmp('filter').getEl().on('keyup', function(){
  151. this.filter();
  152. }, this, {buffer:500});
  153. }, scope:this}
  154. }
  155. }, ' ', '-', {
  156. text: _('sort_by')+':'
  157. }, {
  158. id: 'sortSelect'
  159. ,xtype: 'combo'
  160. ,typeAhead: true
  161. ,triggerAction: 'all'
  162. ,width: 100
  163. ,editable: false
  164. ,mode: 'local'
  165. ,displayField: 'desc'
  166. ,valueField: 'name'
  167. ,lazyInit: false
  168. ,value: 'name'
  169. ,store: new Ext.data.SimpleStore({
  170. fields: ['name', 'desc'],
  171. data : [['name',_('name')],['createdon',_('createdon')],['rank',_('rank')]]
  172. })
  173. ,listeners: {
  174. 'select': {fn:this.sortImages, scope:this}
  175. }
  176. },'-',{
  177. icon: MODx.config.template_url+'images/restyle/icons/refresh.png'
  178. ,cls: 'x-btn-icon'
  179. ,tooltip: {text: _('tree_refresh')}
  180. ,handler: this.load
  181. ,scope: this
  182. }];
  183. }
  184. ,onSelect: function(data) {
  185. var selNode = this.view.getSelectedNodes()[0];
  186. var callback = this.config.onSelect || this.onSelectHandler;
  187. var lookup = this.view.lookup;
  188. var scope = this.config.scope;
  189. this.hide(this.config.animEl || null,function(){
  190. if(selNode && callback){
  191. var data = lookup[selNode.id];
  192. Ext.callback(callback,scope || this,[data]);
  193. this.fireEvent('select',data);
  194. if (window.top.opener) {
  195. window.top.close();
  196. window.top.opener.focus();
  197. }
  198. }
  199. },scope);
  200. }
  201. ,onSelectHandler: function(data) {
  202. Ext.get(this.returnEl).dom.value = unescape(data.url);
  203. }
  204. });
  205. Ext.reg('gal-browser-window',GAL.BrowserWindow);