Changeset b6dee7


Ignore:
Timestamp:
02/16/2009 11:22:36 PM (16 years ago)
Author:
Damien Churchill <damoc@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
1ff29a
Parents:
911d958
Message:

update to allow for passing in a methods list when initialising

File:
1 edited

Legend:

Unmodified
Added
Removed
  • deluge/ui/web/js/rpc.js

    r911d958 rb6dee7  
    5353                this.url = url
    5454                if (this.options.methods.length == 0) {
    55                         var methodNames = this._execute('system.listMethods', {async: false});
    56                         var components = new Hash();
     55                        this._setMethods(this._execute('system.listMethods', {async: false}));
     56                } else {
     57                        this._setMethods(this.options.methods);
     58                }
     59        },
     60       
     61       
     62        /*
     63        Property: _setMethods
     64                Internal method for settings the methods up
    5765
    58                         methodNames.forEach(function(method) {
    59                                 var parts = method.split('.');
    60                                 var component = $pick(components[parts[0]], new Hash());
    61                                 var fn = function() {
    62                                         var options = this._parseargs(arguments);
    63                                         return this._execute(method, options);
    64                                 }.bind(this);
    65                                 component[parts[1]] = fn;
    66                                 components[parts[0]] = component;
    67                         }, this);
    68                        
    69                         components.each(function(methods, name) {
    70                                 this[name] = methods;
    71                         }, this);
    72                 }
     66        Arguments:
     67                methodNames - A list of the method names available.
     68
     69        */
     70        _setMethods: function(methodNames) {
     71                var components = new Hash();
     72
     73                methodNames.forEach(function(method) {
     74                        var parts = method.split('.');
     75                        var component = $pick(components[parts[0]], new Hash());
     76                        var fn = function() {
     77                                var options = this._parseargs(arguments);
     78                                return this._execute(method, options);
     79                        }.bind(this);
     80                        component[parts[1]] = fn;
     81                        components[parts[0]] = component;
     82                }, this);
     83               
     84                components.each(function(methods, name) {
     85                        this[name] = methods;
     86                }, this);
    7387        },
    7488
Note: See TracChangeset for help on using the changeset viewer.