Skip to content

Commit f6a73ef

Browse files
committed
Working on storing model definitions and adding model tests
1 parent 19295ba commit f6a73ef

File tree

7 files changed

+136
-2
lines changed

7 files changed

+136
-2
lines changed

dist/air.js

+24
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ air.each(['post', 'put', 'delete'], function(method){
186186
};
187187
});
188188

189+
// JSONP requests
190+
air.jsonp = function(url, callback) {
191+
var callbackName = 'air_jsonp_callback_' + Math.round(100000 * Math.random());
192+
window[callbackName] = function(data) {
193+
delete window[callbackName];
194+
document.body.removeChild(script);
195+
callback(data);
196+
};
197+
198+
var script = document.createElement('script');
199+
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName;
200+
document.body.appendChild(script);
201+
};
202+
189203
// Serialize an array of form elements or a set of
190204
// key/values into a query string
191205
air.param = function(obj) {
@@ -292,6 +306,7 @@ air.App = function(name, options) {
292306
this.routes = this.options.routes || [];
293307
this.controllers = this.options.controllers || {};
294308
this.views = this.options.views || {};
309+
this.modelDefinitions = this.options.models || {};
295310
};
296311

297312
air.App.prototype.controller = function(name, methods) {
@@ -328,6 +343,15 @@ air.App.prototype.init = function() {
328343
this.router.init();
329344
};
330345

346+
air.App.prototype.model = function(name, params) {
347+
if (!params) {
348+
return new air.Model(name, this.modelDefinitions[name]);
349+
} else {
350+
/* Store the model definition if needed */
351+
this.modelDefinitions[name] = params;
352+
}
353+
};
354+
331355
// Router
332356
// ------
333357
air.Router = function(appName, routes) {

dist/air.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/air.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ <h2 id="model">Model</h2>
792792
split = value.split(<span class="hljs-string">' '</span>);
793793
httpMethod = split[<span class="hljs-number">0</span>];
794794
url = split[<span class="hljs-number">1</span>];
795-
self[property] = <span class="hljs-keyword">this</span>.endpointMethod(httpMethod, url);
795+
self[property] = self.endpointMethod(httpMethod, url);
796796
}
797797
});
798798
};</pre></div></div>

src/App.js

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ air.App = function(name, options) {
66
this.routes = this.options.routes || [];
77
this.controllers = this.options.controllers || {};
88
this.views = this.options.views || {};
9+
this.modelDefinitions = this.options.models || {};
910
};
1011

1112
air.App.prototype.controller = function(name, methods) {
@@ -41,3 +42,12 @@ air.App.prototype.init = function() {
4142
this.router = new air.Router(this.name, this.routes);
4243
this.router.init();
4344
};
45+
46+
air.App.prototype.model = function(name, params) {
47+
if (!params) {
48+
return new air.Model(name, this.modelDefinitions[name]);
49+
} else {
50+
/* Store the model definition if needed */
51+
this.modelDefinitions[name] = params;
52+
}
53+
};

src/Utilities.js

+14
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ air.each(['post', 'put', 'delete'], function(method){
146146
};
147147
});
148148

149+
// JSONP requests
150+
air.jsonp = function(url, callback) {
151+
var callbackName = 'air_jsonp_callback_' + Math.round(100000 * Math.random());
152+
window[callbackName] = function(data) {
153+
delete window[callbackName];
154+
document.body.removeChild(script);
155+
callback(data);
156+
};
157+
158+
var script = document.createElement('script');
159+
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName;
160+
document.body.appendChild(script);
161+
};
162+
149163
// Serialize an array of form elements or a set of
150164
// key/values into a query string
151165
air.param = function(obj) {

0 commit comments

Comments
 (0)