This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentitybase.js.html
214 lines (168 loc) · 6.74 KB
/
entitybase.js.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: entitybase.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: entitybase.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* Represents base query-building logic
* @namespace LGI.Guide
* @class EntityBase
* @extends Collection
*/
function EntityBase() {
Collection.call(this);
this.filters = [];
this._queryModificationActions = [];
this._requestURL = '';
this._request = new Request();
}
EntityBase.prototype = Object.create(Collection.prototype);
/**
* Adds limitation to response data length. For example "a.limit(10);"
* @method EntityBase#limit
* @param {number} limitTo Number of maximum data elements in response.
*/
EntityBase.prototype.limit = function (limitTo) {
this._addURLModification('maxBatchSize=' + limitTo);
return this;
};
/**
* Determines list of fields to be retrieved from server. For example by "a.shows(LGI.Guide.channel.id, LGI.Guide.channel.name);"
* @method EntityBase#fields
* @param {string} multipleArgs You can add unlimited number of strings as multiple parameters.
*/
EntityBase.prototype.fields = function (multipleArgs) {
this._addURLModification('show=' + Array.prototype.slice.call(arguments).join(','));
return this;
};
/**
* Sets sorting field and order. For example "a.sort(LGI.Guide.broadcast.startTime);"
* @order EntityBase#sort
* @param {string} field Field to sort records by.
* @param {string} [order="asc"] Determines order we want to sort records with - ascendant (asc) or descendant (desc).
*/
EntityBase.prototype.sort = function (field, order) {
if (typeof order === 'undefined' || order === null) {
order = 'asc';
}
if (order === 'asc' || order === 'desc') {
this._addURLModification('sort=' + field + '(' + order + ')');
} else {
throw new Error('Invalid sort option, expecting "asc" or "desc"');
}
return this;
};
/**
* Filters data by some of entity properties. For example "a.filter(LGI.Guide.channel.id.equalTo(1));"
* @method EntityBase#filter
* @param {string} multipleArgs You can add unlimited number of strings as multiple parameters.
*/
EntityBase.prototype.filter = function (multipleArgs) {
for (var i = 0; i < arguments.length; i++) {
this._addURLModification(arguments[i]);
this.filters.push(arguments[i]);
}
return this;
};
/**
* Retrieves one page of data.
* @method EntityBase#findOne
* @param {Function} callback Callback to execute and pass response to.
*/
EntityBase.prototype.findOne = function (callback) {
this._buildURLFromElements();
this._request.execute(this._requestURL, this._createScopedCallback(callback), 1);
return this;
};
/**
* Retrieves next page of data.
* @method EntityBase#findNext
* @param {Function} callback Callback to execute and pass response to.
*/
EntityBase.prototype.findNext = function (callback) {
this._request.execute(this._request.nextBatchLink || this._buildURLFromElements(), this._createScopedCallback(callback), 1);
return this;
};
/**
* Retrieves all pages of data one by one and then executes callback.
* @method EntityBase#findAll
* @param {Function} callback Callback to execute and pass response to.
*/
EntityBase.prototype.findAll = function (callback) {
this._buildURLFromElements();
this._request.execute(this._requestURL, this._createScopedCallback(callback));
return this;
};
EntityBase.prototype._addURLModification = function (modificationObject) {
this._queryModificationActions.push(modificationObject);
};
EntityBase.prototype._buildURLFromElements = function () {
this._requestURL = LGI.Guide.config.APIURL;
if (this._URLprefix !== undefined) {
this._requestURL += this._URLprefix;
}
if (LGI.Guide.config.region !== '') {
this._requestURL += LGI.Guide.config.region + '/';
}
this._requestURL += this._baseURL;
for (var i = 0; i < this._queryModificationActions.length; i++) {
//If processing is an action object - execute actionFunction on current URL
if (this._queryModificationActions[i].actionFunction) {
this._requestURL = this._executeModificationAction(this._queryModificationActions[i]);
} else {
//If this is just a string - concat
var joinSymbol = '&';
if (i === 0) {
joinSymbol = '';
}
this._requestURL += joinSymbol + this._queryModificationActions[i];
}
}
return this._requestURL;
};
EntityBase.prototype._executeModificationAction = function (actionObject) {
return actionObject.actionFunction.apply(actionObject.context, [this._requestURL, actionObject.stringValue]);
}
EntityBase.prototype._processData = function (data) {
this.add(data);
};
EntityBase.prototype._processResponse = function (response) {
this.filters = response.filter || this.filters;
this.sortings = response.order || this.sortings;
};
EntityBase.prototype._createScopedCallback = function (callback) {
var scopedCallback = function (data, response) {
this._processData(data);
this._processResponse(response);
if (callback !== undefined) {
callback.bind(this)(data);
}
};
return scopedCallback.bind(this);
};</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-utils.html">utils</a></li></ul><h3>Classes</h3><ul><li><a href="AbstractField.html">AbstractField</a></li><li><a href="Broadcast.html">Broadcast</a></li><li><a href="Channel.html">Channel</a></li><li><a href="Collection.html">Collection</a></li><li><a href="EntityBase.html">EntityBase</a></li><li><a href="NumericField.html">NumericField</a></li><li><a href="PrependField.html">PrependField</a></li><li><a href="Region.html">Region</a></li><li><a href="Request.html">Request</a></li><li><a href="TextField.html">TextField</a></li><li><a href="Video.html">Video</a></li></ul><h3>Namespaces</h3><ul><li><a href="LGI.Guide.config.html">config</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Mon Aug 25 2014 16:57:51 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
</body>
</html>