Commits

Rune Halvorsen committed c794527

Cleanup. Hooked up more parts of the web ui

  • Participants
  • Parent commits 0af67b2

Comments (0)

Files changed (3)

File site/static/index.coffee

 signedUpFor = null # the event, if any, we are signed up for
 changeUpdateTimeout = 3000 # How long to wait after tags change before polling.
 coffeeClient = new window.CoffeeClient("http://localhost:8080")
-pollTimerId = null
+pendingEvent = null
+timerId = null
 handledEvents = []
 
 init = ->
 String.prototype.strip = ->
     @.replace(/^\s+|\s+$/g)
 
-window.addEventListener "load", init, false
+window.addEventListener("load", init, false)
 
 saveSettings = ->
     showView("mainview")
     startPolling()
 
 startPolling = ->
-    window.setInterval(checkForEvents, 3000)
+    timerId = window.setInterval(checkForEvents, 3000)
 
 checkForEvents = ->
     tags = ["foo1"] #(e.strip() for e in document.querySelector("#tags").value.split(","))
     coffeeClient.joinEvent(null, tag, "jsrune")
   
 onCheckForEvents = (eventdata) ->
-    opera.postError("Gots events! " + JSON.stringify(eventdata))
+    #opera.postError("Gots events! " + JSON.stringify(eventdata))
     showInvites(eventdata.events) if eventdata?.events?.length
 
 acceptInvite = (event) ->
-    "pass"
+    showView("countdownview")
 
 declineInvite = (event) ->
-    removeInvite(event.target)
-
-removeInvite = (ele) ->
-    Unbose(ele).parent().remove()
+    Unbose(event.target).ancestors(".invite").remove()
 
 showInvites = (events) ->    
     for event in events when event.id not in handledEvents
         handledEvents.push(event.id)
         showInvite(event)
-    showView("mainview")
+        showView("mainview")
 
 showInvite = (event) ->
     ele = Unbose.fromZen("""
-      div.invite>button.yes+button.no+br+span
+      div.invite>h3+p+button.yes+button.no
     """)
+    ele.find("h3").text(event.tag)
     ele.find("button").nth(0).on("click", acceptInvite).text("Join")    
     ele.find("button").nth(1).on("click", declineInvite).text("Decline")
-    whostring = if event.participants.length is 1 then event.participants[0] else "#{event.participants.length} people"
-    ele.find("span").text("#{whostring} from group #{event.tag} going for coffee in #{Math.round(event.timedelta/60000)} minutes")
-    ele.find("span").attr("title", event.participants.join(", "))    
+    [head..., tail] = event.participants
+    whostring = "" + (if head.length then "#{head.join(", ")} and " else "") + tail
+    ele.find("p").text("#{whostring} going for coffee in #{Math.round(event.timedelta/60000)} minutes")
+    ele.find("p").attr("title", event.participants.join(", "))    
     Unbose("#mainview").append(ele)
 
 showView = (view) ->

File site/static/index.js

 (function() {
-  var acceptInvite, changeUpdateTimeout, checkForEvents, coffeeClient, declineInvite, handledEvents, init, joinEvent, onCheckForEvents, pollTimerId, removeInvite, saveSettings, showInvite, showInvites, showView, signedUpFor, startPolling, watchedTags;
+  var acceptInvite, changeUpdateTimeout, checkForEvents, coffeeClient, declineInvite, handledEvents, init, joinEvent, onCheckForEvents, pendingEvent, saveSettings, showInvite, showInvites, showView, signedUpFor, startPolling, timerId, watchedTags;
   var __indexOf = Array.prototype.indexOf || function(item) {
     for (var i = 0, l = this.length; i < l; i++) {
       if (this[i] === item) return i;
     }
     return -1;
-  };
+  }, __slice = Array.prototype.slice;
   watchedTags = "";
   signedUpFor = null;
   changeUpdateTimeout = 3000;
   coffeeClient = new window.CoffeeClient("http://localhost:8080");
-  pollTimerId = null;
+  pendingEvent = null;
+  timerId = null;
   handledEvents = [];
   init = function() {
     Unbose("#savesettings").on("click", saveSettings);
     return startPolling();
   };
   startPolling = function() {
-    return window.setInterval(checkForEvents, 3000);
+    return timerId = window.setInterval(checkForEvents, 3000);
   };
   checkForEvents = function() {
     var tags;
   };
   onCheckForEvents = function(eventdata) {
     var _ref;
-    opera.postError("Gots events! " + JSON.stringify(eventdata));
     if (eventdata != null ? (_ref = eventdata.events) != null ? _ref.length : void 0 : void 0) {
       return showInvites(eventdata.events);
     }
   };
   acceptInvite = function(event) {
-    return "pass";
+    return showView("countdownview");
   };
   declineInvite = function(event) {
-    return removeInvite(event.target);
-  };
-  removeInvite = function(ele) {
-    return Unbose(ele).parent().remove();
+    return Unbose(event.target).ancestors(".invite").remove();
   };
   showInvites = function(events) {
-    var event, _i, _len, _ref;
+    var event, _i, _len, _ref, _results;
+    _results = [];
     for (_i = 0, _len = events.length; _i < _len; _i++) {
       event = events[_i];
       if (_ref = event.id, __indexOf.call(handledEvents, _ref) < 0) {
         handledEvents.push(event.id);
         showInvite(event);
+        _results.push(showView("mainview"));
       }
     }
-    return showView("mainview");
+    return _results;
   };
   showInvite = function(event) {
-    var ele, whostring;
-    ele = Unbose.fromZen("div.invite>button.yes+button.no+br+span");
+    var ele, head, tail, whostring, _i, _ref;
+    ele = Unbose.fromZen("div.invite>h3+p+button.yes+button.no");
+    ele.find("h3").text(event.tag);
     ele.find("button").nth(0).on("click", acceptInvite).text("Join");
     ele.find("button").nth(1).on("click", declineInvite).text("Decline");
-    whostring = event.participants.length === 1 ? event.participants[0] : "" + event.participants.length + " people";
-    ele.find("span").text("" + whostring + " from group " + event.tag + " going for coffee in " + (Math.round(event.timedelta / 60000)) + " minutes");
-    ele.find("span").attr("title", event.participants.join(", "));
+    _ref = event.participants, head = 2 <= _ref.length ? __slice.call(_ref, 0, _i = _ref.length - 1) : (_i = 0, []), tail = _ref[_i++];
+    whostring = "" + (head.length ? "" + (head.join(", ")) + " and " : "") + tail;
+    ele.find("p").text("" + whostring + " going for coffee in " + (Math.round(event.timedelta / 60000)) + " minutes");
+    ele.find("p").attr("title", event.participants.join(", "));
     return Unbose("#mainview").append(ele);
   };
   showView = function(view) {

File site/static/style.css

 
 .view {
     border: solid thin black;
+}
+
+.invite {
+    border: solid thin black;
+}
+
+.invite h3, .invite p {
+    margin: 0;
+}
+
+.invite button {
+    width: 100px;
 }