1
0
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:
Dan Barber 2013-01-23 11:22:11 +00:00
parent eaf6625fe7
commit b84145b85f
5 changed files with 45 additions and 8 deletions

View File

@ -1,11 +1,15 @@
define(['jquery',
'underscore',
'jquerymobile',
define(['jquerymobile',
'backbone',
'mustache'],
function($, _, a, Backbone, Mustache) {
'mustache',
'collections/lines',
'views/line_list'],
function(a, Backbone, Mustache, LinesCollection, LineList) {
return {
initialize: function() {
lines = new LinesCollection;
lineList = new LineList({ collection: lines });
lines.fetch();
}
};
});

View File

@ -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({
url: "http://api.tubeupdates.com/?method=get.status",
model: Line,
sync: MySync,
parse: function(data) {
return data.response.lines;
}
});
return LinesCollection;
});

View File

@ -1,5 +1,9 @@
require(['backbone'], function(Backbone) {
define(['backbone'], function(Backbone) {
var Line = Backbone.Model.extend({
});
return Line;
});

View File

@ -1 +1 @@
<li id="{{ id }}">{{ name }} ({{ status }})</li>
<li id="{{ id }}">{{{ name }}} ({{ status }})</li>

View File

@ -1,15 +1,32 @@
define(['backbone',
'text',
'mustache',
'models/line',
'collections/lines',
'text!templates/line.mustache'],
function(Backbone,
Text,
Mustache,
Line,
LineCollection,
lineTemplate) {
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'
});