summaryrefslogtreecommitdiffstats
path: root/ExtDirectAPI.js
blob: b793e906390b3a80b9d96e5687a3c2a0b69ea3cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
  This file is part of Badaap Comic Reader.
  
  Copyright (c) 2012 Jeroen Walter
  
  Badaap Comic Reader is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Badaap Comic Reader is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Badaap Comic Reader.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
  This class uses a SYNCHRONOUS AJAX request to ensure that the Ext.Direct provider is initialized BEFORE the models and stores and other classes 
  use one of the remote API calls.
*/
Ext.app.REMOTING_API = {};

Ext.define('ExtDirectAPI', {
     extend: 'Ext.Base',
     
     requires: [
      'Ext.direct.Manager',
      'Ext.direct.RemotingProvider',
      'Ext.Ajax',
      'Ext.direct.RemotingEvent'
     ],

  },
  // Class create function, this is (and must be) called before all model classes with an Ext.DirectProxy are instantiated.
  function()
  {
    Ext.namespace( 'Ext.app' );
    
    // Retrieve the remote api via SYNCHRONOUS request. This is very important, otherwise the remote api is not yet initialized when the Ext.Direct proxies of the models are instantiated.
    Ext.Ajax.request({
    async: false,
    url: 'ExtDirectAPI.php?json',
    method: 'GET',
    
    success: function(response)
      {
        eval("Ext.app.REMOTING_API = " + response.responseText);
        
        // Disable batch requests, makes debugging easier.
        Ext.app.REMOTING_API.enableBuffer = false;
        
        /* doesn't work ?
        Ext.app.REMOTING_API.listeners = {
          exception: function(e) { alert(e); }
        };
        */
        Ext.Direct.addProvider( Ext.app.REMOTING_API );
      }
    });
  }
);