mirror of
https://github.com/danbee/tube-status-server
synced 2025-03-04 08:39:12 +00:00
It lives!
This commit is contained in:
parent
eaf6625fe7
commit
b84145b85f
@ -1,11 +1,15 @@
|
|||||||
define(['jquery',
|
define(['jquerymobile',
|
||||||
'underscore',
|
|
||||||
'jquerymobile',
|
|
||||||
'backbone',
|
'backbone',
|
||||||
'mustache'],
|
'mustache',
|
||||||
function($, _, a, Backbone, Mustache) {
|
'collections/lines',
|
||||||
|
'views/line_list'],
|
||||||
|
function(a, Backbone, Mustache, LinesCollection, LineList) {
|
||||||
return {
|
return {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
lines = new LinesCollection;
|
||||||
|
lineList = new LineList({ collection: lines });
|
||||||
|
|
||||||
|
lines.fetch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,11 +1,23 @@
|
|||||||
require(['backbone', 'models/line'], function(Backbone, Line) {
|
define(['backbone', 'models/line'], function(Backbone, Line) {
|
||||||
|
|
||||||
|
var MySync = function (method, collection, options) {
|
||||||
|
options.timeout = 10000; // required, or the application won't pick up on 404 responses
|
||||||
|
options.dataType = "jsonp";
|
||||||
|
return Backbone.sync(method, collection, options);
|
||||||
|
};
|
||||||
|
|
||||||
var LinesCollection = Backbone.Collection.extend({
|
var LinesCollection = Backbone.Collection.extend({
|
||||||
url: "http://api.tubeupdates.com/?method=get.status",
|
url: "http://api.tubeupdates.com/?method=get.status",
|
||||||
|
|
||||||
|
model: Line,
|
||||||
|
|
||||||
|
sync: MySync,
|
||||||
|
|
||||||
parse: function(data) {
|
parse: function(data) {
|
||||||
return data.response.lines;
|
return data.response.lines;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return LinesCollection;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
require(['backbone'], function(Backbone) {
|
define(['backbone'], function(Backbone) {
|
||||||
|
|
||||||
var Line = Backbone.Model.extend({
|
var Line = Backbone.Model.extend({
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return Line;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
<li id="{{ id }}">{{ name }} ({{ status }})</li>
|
<li id="{{ id }}">{{{ name }}} ({{ status }})</li>
|
||||||
|
|||||||
@ -1,15 +1,32 @@
|
|||||||
define(['backbone',
|
define(['backbone',
|
||||||
'text',
|
'text',
|
||||||
|
'mustache',
|
||||||
'models/line',
|
'models/line',
|
||||||
'collections/lines',
|
'collections/lines',
|
||||||
'text!templates/line.mustache'],
|
'text!templates/line.mustache'],
|
||||||
function(Backbone,
|
function(Backbone,
|
||||||
Text,
|
Text,
|
||||||
|
Mustache,
|
||||||
Line,
|
Line,
|
||||||
LineCollection,
|
LineCollection,
|
||||||
lineTemplate) {
|
lineTemplate) {
|
||||||
|
|
||||||
var LineList = Backbone.View.extend({
|
var LineList = Backbone.View.extend({
|
||||||
|
initialize: function() {
|
||||||
|
var view = this;
|
||||||
|
this.collection.on("reset", function() {
|
||||||
|
view.render();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
render: function() {
|
||||||
|
var html = "";
|
||||||
|
this.collection.models.forEach(function(model) {
|
||||||
|
html += Mustache.render(lineTemplate, model.toJSON());
|
||||||
|
});
|
||||||
|
this.$el.html(html).listview("refresh");
|
||||||
|
},
|
||||||
|
|
||||||
el: '#line-list'
|
el: '#line-list'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user