[ Index ]
 

Code source de Seagull 0.6.1

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/js/html_ajax/ -> Request.js (source)

   1  /**
   2   * Class that contains everything needed to make a request
   3   * This includes:
   4   *    The url were calling
   5   *    If were calling a remote method, the class and method name
   6   *    The payload, unserialized
   7   *    The timeout for async calls
   8   *    The callback method
   9   *    Optional event handlers: onError, Load, Send
  10   *    A serializer instance
  11   *
  12   * @category    HTML
  13   * @package    AJAX
  14   * @author    Joshua Eichorn <josh@bluga.net>
  15   * @copyright    2005 Joshua Eichorn
  16   * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
  17   *
  18   * See Main.js for author/license details
  19   */
  20  function HTML_AJAX_Request(serializer) {
  21      this.serializer = serializer;
  22  }
  23  HTML_AJAX_Request.prototype = {
  24  
  25      // Instance of a serializer
  26      serializer: null,
  27  
  28      // Is this an async request
  29      isAsync: false,
  30  
  31      // HTTP verb
  32      requestType: 'POST',
  33  
  34      // The actual URL the request is sent to
  35      requestUrl: '',
  36  
  37      // Remote Class
  38      className: null,
  39  
  40      // Remote Method
  41      methodName: null,
  42  
  43      // Timeout in milliseconds for requests
  44      timeout: 20000,
  45  
  46      // unserialized data, for rpc calls use add args, to send raw data just set this directly
  47      args: null,
  48  
  49      // async callback method
  50      callback: null,
  51  
  52      // Queue to push this request too
  53      queue: 'default',
  54  
  55      // default priority
  56      priority: 0,
  57  
  58      // a hash of headers to add to add to this request
  59      customHeaders: {},
  60  
  61      // true if this request will be sent using iframes
  62      iframe: false,
  63  
  64      // is this a grab request? if so we need to proxy for iframes
  65      grab: false,
  66  
  67      // true if this request should expect a multipart response
  68      multipart: false,
  69  
  70      // remote callback
  71      phpCallback: false,
  72  
  73      /**
  74       * Add an argument for the remote method
  75       * @param string argument name
  76       * @param mixed value
  77       * @return void
  78       * @throws Error code 1004
  79       */
  80      addArg: function(name, value) 
  81      {
  82          if ( !this.args ) {
  83              this.args = [];
  84          }
  85          if (!/[^a-zA-Z_0-9]/.test(name) ) {
  86              this.args[name] = value;
  87          } else {
  88              throw new Error('Invalid parameter name ('+name+')');
  89          }
  90      },
  91  
  92      /**
  93       * Get the payload in a serialized manner
  94       */
  95      getSerializedPayload: function() {
  96          return this.serializer.serialize(this.args);
  97      },
  98  
  99      /**
 100       * Get the content type
 101       */
 102      getContentType: function() {
 103          return this.serializer.contentType;
 104      },
 105  
 106      /**
 107       * Get the complete url, adding in any needed get params for rpc
 108       */
 109      completeUrl: function() {
 110          if (this.className || this.methodName) {
 111              this.addGet('c', this.className);
 112              this.addGet('m', this.methodName);
 113          }
 114          if (this.phpCallback) {
 115              if (HTML_AJAX_Util.getType(this.phpCallback) == 'array') {
 116                  this.phpCallback = this.phpCallback.join('.');
 117              }
 118              this.addGet('cb', this.phpCallback);
 119          }
 120          if (this.multipart) {
 121              this.addGet('multipart', '1');
 122          }
 123          return this.requestUrl;
 124      },
 125  
 126      /**
 127       * Compare to another request by priority
 128       */
 129      compareTo: function(other) {
 130          if (this.priority == other.priority) {
 131              return 0;
 132          }
 133          return (this.priority > other.priority ? 1 : -1);
 134      },
 135  
 136      /**
 137       * Add a GET argument
 138       */
 139      addGet: function(name, value) {
 140          var url = new String(this.requestUrl);
 141          url += (url.indexOf('?') < 0 ? '?' : '&') + escape(name) + '=' + escape(value);
 142          this.requestUrl = url;
 143      }
 144  }


Généré le : Fri Mar 30 01:27:52 2007 par Balluche grâce à PHPXref 0.7