1 var Class = require("../lib/mootools/mootools-node.js").Class; 2 3 var DriverAbstract = require('../lib/DriverAbstract.js').DriverAbstract; 4 5 var Event = require('../lib/core/event/Event.js').Event; 6 var ErrorEvent = require('../lib/core/event/ErrorEvent.js').ErrorEvent; 7 var OpalLoader = require('../lib/core/opal/OpalLoader.js').OpalLoader; 8 var OpalRequest = require('../lib/core/opal/OpalRequest.js').OpalRequest; 9 10 /** 11 * Implementation of driver which making remote calls through OPAL intraface. 12 * Dispatches event: DriverAbstract.LOADED on successfull data retrieving otherwise dispatches DriverAbstract.ERROR 13 * @class DriverRemote class 14 * @extends DriverAbstract 15 * @requires Class 16 * @requires DriverAbstract 17 * @requires OpalLoader 18 * @requires OpalRequest 19 * @requires Event 20 * @requires ErrorEvent 21 * @param {Object} params Parameters which will be passed to OPAL call. 22 */ 23 var DriverRemote = function(){ 24 25 /** @ignore */ 26 this.Extends = DriverAbstract; 27 28 /** 29 * @property 30 * @private 31 */ 32 this._params = null; 33 34 /** 35 * @property 36 * @private 37 */ 38 this._loader = null; 39 40 /** @ignore */ 41 this.initialize = function(params){ 42 if(!params || typeof params != "object" || params.constructor != Object){ 43 throw DriverRemote.Exception.WRONG_PARAMS; 44 } 45 this._params = params; 46 this._loader = new OpalLoader(); 47 }; 48 49 /** 50 * Makes remote call through OPAL interface. Implements DriverAbstract interface. 51 * @public 52 * @throws {DriverRemote.Exception.OPAL_WRONG_PARAMS} if given params are invalid for OPAL (see:{@link OpalRequest}) 53 */ 54 this.load = function(){ 55 try{ 56 var opalRequest = new OpalRequest(this._params); 57 }catch(e){ 58 throw DriverRemote.Exception.OPAL_WRONG_PARAMS; 59 } 60 //FIXME: do wywalenia 61 opalRequest.setGatewayHost('rtx.m4r2.onet'); 62 63 this._loader.addEventListener(OpalLoader.LOADED, this._onLoad, this); 64 this._loader.addEventListener(OpalLoader.ERROR, this._onError, this); 65 66 this._loader.load(opalRequest); 67 }; 68 69 /** 70 * @private 71 */ 72 this._onLoad = function(e){ 73 this.dispatchEvent(new Event(DriverAbstract.LOADED, e.data)); 74 }; 75 76 /** 77 * @private 78 */ 79 this._onError = function(e){ 80 //TODO dodac sprawdzanie typu bledu i nadawanie kodu i msg dla emitowanego ErrorEvent 81 //FIXME to wogole jest "popsute" bo nie przekazuje bledu z opala dalej 82 this.dispatchEvent(new ErrorEvent(DriverAbstract.ERROR, e.data)); 83 }; 84 }; 85 86 DriverRemote = new Class(new DriverRemote()); 87 /** 88 * Namespace for exeptions messages. 89 * @constant 90 * @static 91 * @namespace 92 */ 93 DriverRemote.Exception = {}; 94 /** 95 * @constant 96 * @static 97 */ 98 DriverRemote.Exception.WRONG_PARAMS = 'Given param has to be an object'; 99 /** 100 * @static 101 * @constant 102 */ 103 DriverRemote.Exception.OPAL_WRONG_PARAMS = 'Given configuration is not valid'; 104 105 exports.DriverRemote = DriverRemote;