Linux за българи: Форуми

Програмиране => Web development => Темата е започната от: VladSun в Mar 17, 2010, 13:03



Титла: [ExtJS] "Централизирани" събития
Публикувано от: VladSun в Mar 17, 2010, 13:03
Да споделя опит - трябваше ми прихващане на определени събития на *всички* инстанции на определен клас. Същото нещо е описано в http://www.extjs.com/deploy/dev/docs/output/Ext.data.DataProxy.html:

Цитат
And new in Ext version 3, attach centralized event-listeners upon the DataProxy class itself! This is a great place to implement a messaging system to centralize your application's user-feedback and error-handling.
// Listen to all "beforewrite" event fired by all proxies.

Ext.data.DataProxy.on('beforewrite', function(proxy, action) {
    console.log('beforewrite: ', action);
});

Ето как се решава този проблем:
Код
GeSHi (Javascript):
  1. Ext.namespace('Ext.App');
  2.  
  3. Ext.App.Module = function (config)
  4. {
  5. this.addEvents
  6. (
  7. 'beforeConfigure',
  8. 'afterConfigure'
  9. );
  10.  
  11. Ext.App.Module.superclass.constructor.call(this, config);
  12. Ext.App.Module.relayEvents(this, ['beforeConfigure', 'afterConfigure']);
  13. }
  14.  
  15. Ext.extend(Ext.App.Module, Ext.util.Observable,
  16. {
  17. initModule : function ()
  18. {
  19. this.fireEvent('beforeConfigure', this);
  20. // ... configure Module
  21. this.fireEvent('afterConfigure', this);
  22. }
  23. });
  24.  
  25. Ext.apply(Ext.App.Module, Ext.util.Observable.prototype);
  26. Ext.util.Observable.call(Ext.App.Module);