Permalink
Browse files

Modified fronted code

  • Loading branch information...
1 parent 00509b1 commit bf8f1e262b4b4255b8c094d4806b382bb6002333 @HalfdanJ HalfdanJ committed Oct 9, 2011
Showing with 73 additions and 17 deletions.
  1. +41 −7 html/coffee/main.coffee
  2. +4 −4 html/index.html
  3. +28 −6 html/javascripts/main.js
View
@@ -1,14 +1,33 @@
$ ()->
+ jsonUrl = "http://illutron.johan.cc/"
+
window.Person = Backbone.Model.extend({
defaults: ->
{
- "name": "-"
+ "member": "-"
}
+
+ url: ->
+ u = jsonUrl + '/members'+'/'
+ u = u + this.get("id")
+ u
})
window.PeopleList = Backbone.Collection.extend({
model: Person
+ #url: "http://jive.local:8000/api/latest/"
+ url: jsonUrl+ "members/"
+
+ sync: (method, model, options) ->
+ options.timeout = 10000
+ options.dataType = "jsonp"
+ Backbone.sync(method, model, options)
+
+ # initialize: ->
+ # this.bind("add", this.changed)
+ #
+
})
window.People = new PeopleList
@@ -23,25 +42,40 @@ $ ()->
render: ->
$(this.el).html(this.template(this.model.toJSON()))
this
-
-
+
})
- window.AppView = Backbone.View.extend(
+ window.AppView = Backbone.View.extend(
el: $("#app")
initialize: ->
+ People.bind('add', this.addPerson, this);
+ People.bind('reset', this.addAll, this);
+
+ People.fetch()
+
+
+ setInterval( (-> window.People.each( (person) -> person.fetch() )) , 5000);
+
this
render: -> this
-
+
+ addAll: ->
+ People.each(this.addPerson);
+
+
addPerson: (person) ->
+ #alert person.url()
view = new PersonView(model: person)
@$("#people-list").append view.render().el
)
window.App = new AppView;
- window.App.addPerson new Person({"name":"Benjamin"})
-
+ #window.App.addPerson new Person({"name":"Benjamin"})
+
+
+
+
View
@@ -2,7 +2,7 @@
<html>
<head>
- <title>Illutron Checkin</title>
+ <title>Illutron Dashboard</title>
<link href="stylesheets/screen.css" media="all" rel="stylesheet" type="text/css"/>
<script src="vendor/json/json2.js"></script>
<script src="vendor/jquery-1.6.4.min.js"></script>
@@ -25,9 +25,9 @@
<!-- Templates -->
<script type="text/template" id="person-template">
- <div class="personbox activeperson">
- <img src="http://www.illutron.dk/pictures/0000/3748/benjamin_custom100x100_.jpg?1311535360">
- <p class="person-name"><%= name %></p>
+ <div class="personbox <%= on_illutron == 1 ? 'activeperson' : '' %>">
+ <img src="http://illutron.johan.cc<%= image %>">
+ <p class="person-name"><%= id %> - <%= member %></p>
</div>
</script>
View
@@ -1,14 +1,28 @@
(function() {
$(function() {
+ var jsonUrl;
+ jsonUrl = "http://illutron.johan.cc/";
window.Person = Backbone.Model.extend({
defaults: function() {
return {
- "name": "-"
+ "member": "-"
};
+ },
+ url: function() {
+ var u;
+ u = jsonUrl + '/members' + '/';
+ u = u + this.get("id");
+ return u;
}
});
window.PeopleList = Backbone.Collection.extend({
- model: Person
+ model: Person,
+ url: jsonUrl + "members/",
+ sync: function(method, model, options) {
+ options.timeout = 10000;
+ options.dataType = "jsonp";
+ return Backbone.sync(method, model, options);
+ }
});
window.People = new PeopleList;
window.PersonView = Backbone.View.extend({
@@ -25,11 +39,22 @@
window.AppView = Backbone.View.extend({
el: $("#app"),
initialize: function() {
+ People.bind('add', this.addPerson, this);
+ People.bind('reset', this.addAll, this);
+ People.fetch();
+ setInterval((function() {
+ return window.People.each(function(person) {
+ return person.fetch();
+ });
+ }), 5000);
return this;
},
render: function() {
return this;
},
+ addAll: function() {
+ return People.each(this.addPerson);
+ },
addPerson: function(person) {
var view;
view = new PersonView({
@@ -38,9 +63,6 @@
return this.$("#people-list").append(view.render().el);
}
});
- window.App = new AppView;
- return window.App.addPerson(new Person({
- "name": "Benjamin"
- }));
+ return window.App = new AppView;
});
}).call(this);

0 comments on commit bf8f1e2

Please sign in to comment.