[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('datasource-io', function (Y, NAME) { 9 10 /** 11 * Provides a DataSource implementation which can be used to retrieve data via the IO Utility. 12 * 13 * @module datasource 14 * @submodule datasource-io 15 */ 16 17 /** 18 * IO subclass for the DataSource Utility. 19 * @class DataSource.IO 20 * @extends DataSource.Local 21 * @constructor 22 */ 23 var DSIO = function() { 24 DSIO.superclass.constructor.apply(this, arguments); 25 }; 26 27 28 ///////////////////////////////////////////////////////////////////////////// 29 // 30 // DataSource.IO static properties 31 // 32 ///////////////////////////////////////////////////////////////////////////// 33 Y.mix(DSIO, { 34 /** 35 * Class name. 36 * 37 * @property NAME 38 * @type String 39 * @static 40 * @final 41 * @value "dataSourceIO" 42 */ 43 NAME: "dataSourceIO", 44 45 46 ///////////////////////////////////////////////////////////////////////////// 47 // 48 // DataSource.IO Attributes 49 // 50 ///////////////////////////////////////////////////////////////////////////// 51 52 ATTRS: { 53 /** 54 * Pointer to IO Utility. 55 * 56 * @attribute io 57 * @type Y.io 58 * @default Y.io 59 */ 60 io: { 61 value: Y.io, 62 cloneDefaultValue: false 63 }, 64 65 /** 66 * Default IO Config. 67 * 68 * @attribute ioConfig 69 * @type Object 70 * @default null 71 */ 72 ioConfig: { 73 value: null 74 } 75 } 76 }); 77 78 Y.extend(DSIO, Y.DataSource.Local, { 79 /** 80 * Internal init() handler. 81 * 82 * @method initializer 83 * @param config {Object} Config object. 84 * @private 85 */ 86 initializer: function(config) { 87 this._queue = {interval:null, conn:null, requests:[]}; 88 }, 89 90 /** 91 * IO success callback. 92 * 93 * @method successHandler 94 * @param id {String} Transaction ID. 95 * @param response {String} Response. 96 * @param e {EventFacade} Event facade. 97 * @private 98 */ 99 successHandler: function (id, response, e) { 100 var defIOConfig = this.get("ioConfig"), 101 payload = e.details[0]; 102 103 delete Y.DataSource.Local.transactions[e.tId]; 104 105 payload.data = response; 106 this.fire("data", payload); 107 108 Y.log("Received IO data response for \"" + e.request + "\"", "info", "datasource-io"); 109 110 if (defIOConfig && defIOConfig.on && defIOConfig.on.success) { 111 defIOConfig.on.success.apply(defIOConfig.context || Y, arguments); 112 } 113 }, 114 115 /** 116 * IO failure callback. 117 * 118 * @method failureHandler 119 * @param id {String} Transaction ID. 120 * @param response {String} Response. 121 * @param e {EventFacade} Event facade. 122 * @private 123 */ 124 failureHandler: function (id, response, e) { 125 var defIOConfig = this.get("ioConfig"), 126 payload = e.details[0]; 127 128 delete Y.DataSource.Local.transactions[e.tId]; 129 130 payload.error = new Error("IO data failure"); 131 Y.log("IO data failure", "error", "datasource-io"); 132 133 payload.data = response; 134 this.fire("data", payload); 135 136 Y.log("Received IO data failure for \"" + e.request + "\"", "info", "datasource-io"); 137 138 if (defIOConfig && defIOConfig.on && defIOConfig.on.failure) { 139 defIOConfig.on.failure.apply(defIOConfig.context || Y, arguments); 140 } 141 }, 142 143 /** 144 * @property _queue 145 * @description Object literal to manage asynchronous request/response 146 * cycles enabled if queue needs to be managed (asyncMode/ioConnMode): 147 * <dl> 148 * <dt>interval {Number}</dt> 149 * <dd>Interval ID of in-progress queue.</dd> 150 * <dt>conn</dt> 151 * <dd>In-progress connection identifier (if applicable).</dd> 152 * <dt>requests {Object[]}</dt> 153 * <dd>Array of queued request objects: {request:request, callback:callback}.</dd> 154 * </dl> 155 * @type Object 156 * @default {interval:null, conn:null, requests:[]} 157 * @private 158 */ 159 _queue: null, 160 161 /** 162 * Passes query string to IO. Fires <code>response</code> event when 163 * response is received asynchronously. 164 * 165 * @method _defRequestFn 166 * @param e {EventFacade} Event Facade with the following properties: 167 * <dl> 168 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd> 169 * <dt>request (Object)</dt> <dd>The request.</dd> 170 * <dt>callback (Object)</dt> <dd>The callback object with the following properties: 171 * <dl> 172 * <dt>success (Function)</dt> <dd>Success handler.</dd> 173 * <dt>failure (Function)</dt> <dd>Failure handler.</dd> 174 * </dl> 175 * </dd> 176 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> 177 * </dl> 178 * @protected 179 */ 180 _defRequestFn: function(e) { 181 var uri = this.get("source"), 182 io = this.get("io"), 183 defIOConfig = this.get("ioConfig"), 184 request = e.request, 185 cfg = Y.merge(defIOConfig, e.cfg, { 186 on: Y.merge(defIOConfig, { 187 success: this.successHandler, 188 failure: this.failureHandler 189 }), 190 context: this, 191 "arguments": e 192 }); 193 194 // Support for POST transactions 195 if(Y.Lang.isString(request)) { 196 if(cfg.method && (cfg.method.toUpperCase() === "POST")) { 197 cfg.data = cfg.data ? cfg.data+request : request; 198 } 199 else { 200 uri += request; 201 } 202 } 203 Y.DataSource.Local.transactions[e.tId] = io(uri, cfg); 204 return e.tId; 205 } 206 }); 207 208 Y.DataSource.IO = DSIO; 209 210 211 }, '3.17.2', {"requires": ["datasource-local", "io-base"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |