From a61632eda584b38478010da87698fe6e2c9a2417 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Sat, 7 Jun 2014 14:02:57 +0200 Subject: [PATCH] Implemented central click handler for buddy list clicks. --- src/styles/components/_buddylist.scss | 3 + static/js/directives/buddylist.js | 6 +- static/js/services/buddylist.js | 84 +++++++++++++++++---------- static/partials/buddy.html | 2 +- static/partials/buddyactions.html | 4 +- 5 files changed, 60 insertions(+), 39 deletions(-) diff --git a/src/styles/components/_buddylist.scss b/src/styles/components/_buddylist.scss index 1d000e03..8eeaff88 100644 --- a/src/styles/components/_buddylist.scss +++ b/src/styles/components/_buddylist.scss @@ -223,6 +223,9 @@ .#{$fa-css-prefix} { font-size: 2em; } + i.fa { + pointer-events: none; + } } .buddy .buddysessions { diff --git a/static/js/directives/buddylist.js b/static/js/directives/buddylist.js index b7b23542..50426f1e 100644 --- a/static/js/directives/buddylist.js +++ b/static/js/directives/buddylist.js @@ -61,6 +61,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { }; + /* $scope.doAudioConference = function(id) { $scope.updateAutoAccept(id); @@ -71,7 +72,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { } }) - }; + };*/ $scope.setRoomStatus = function(status) { if (status !== $scope.enabled) { @@ -83,9 +84,6 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { } }; - //XXX(longsleep): Debug leftover ?? Remove this. - window.doAudioConference = $scope.doAudioConference; - var buddylist = $scope.buddylist = buddyList.buddylist($element, $scope, {}); var onJoined = _.bind(buddylist.onJoined, buddylist); var onLeft = _.bind(buddylist.onLeft, buddylist); diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index 9253309d..692df29e 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -157,22 +157,24 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! $element.on("mouseenter mouseleave", ".buddy", _.bind(function(event) { // Hover handler for on Buddy actions. var buddyElement = $(event.currentTarget); - this.hover(buddyElement, event.type === "mouseenter" ? true : false, buddyElement.scope().session.Id); + this.hover(buddyElement, event.type === "mouseenter" ? true : false); }, this)); $element.on("click", ".buddy", _.bind(function(event) { + console.log("click event", event); var buddyElement = $(event.currentTarget); - buddyElement.scope().doDefault(); + //buddyElement.scope().doDefault(); + this.click(buddyElement, event.target); }, this)); - $element.on("click", ".fa.contact", _.bind(function(event) { + /*$element.on("click", ".fa.contact", _.bind(function(event) { event.stopPropagation(); var buddyElement = $(event.currentTarget); buddyElement.scope().doDefaultContact(); - }, this)); + }, this));*/ $element.attr("data-xthreshold", "10"); $element.on("swipeleft", ".buddy", _.bind(function(event) { event.preventDefault(); var buddyElement = $(event.currentTarget); - this.hover(buddyElement, !buddyElement.hasClass("hovered"), buddyElement.scope().session.Id); + this.hover(buddyElement, !buddyElement.hasClass("hovered")); }, this)); $window.setInterval(_.bind(this.soundLoop, this), 500); @@ -211,35 +213,17 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! Buddylist.prototype.onBuddyScopeCreated = function(scope, data) { + // Init scope with our stuff. scope.element = null; scope.contact = null; scope.display = {}; - var session = scope.session = buddySession.create(data); - - scope.doDefault = function() { - var id = scope.session.Id; - //if (scope.status.isMixer) { - // return scope.doAudioConference(id); - //} - return scope.doCall(id); - }; - scope.doDefaultContact = function() { - var contact = scope.contact; - if (contact) { - return scope.doContactRemove(contact.Userid); - } else { - var id = scope.session.Id; - return scope.doContactRequest(id); - } - }; + scope.session = buddySession.create(data); scope.$on("$destroy", function() { //console.log("destroyed"); scope.element = null; scope.killed = true; }); - //console.log("on buddy scope", session.Userid, session); - }; Buddylist.prototype.onBuddySessionUserid = function(scope, sourceSession) { @@ -666,9 +650,50 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; - Buddylist.prototype.hover = function(buddyElement, hover, id) { + Buddylist.prototype.click = function(buddyElement, target) { + + //console.log("click handler", buddyElement, target); + var action = $(target).data("action"); + if (!action) { + // Make call the default action. + action = "call"; + } + + var scope = buddyElement.scope(); + var session = scope.session; + var sessionData = session.get() + var contact = scope.contact; + var id; + if (!sessionData) { + // TODO(longsleep): Find session with help of contact. + console.log("No sessions for this buddy.", session, contact); + } else { + id = sessionData.Id; + } + //console.log("id", id); + switch (action) { + case "call": + scope.doCall(id); + break; + case "chat": + scope.doChat(id); + break; + case "contact": + if (contact) { + scope.doContactRemove(contact.Userid); + } else { + scope.doContactRequest(id); + } + break; + } + + }; + + Buddylist.prototype.hover = function(buddyElement, hover) { - //console.log("hover handler", event, hover, id); + //console.log("hover handler", buddyElement, hover); + var scope = buddyElement.scope(); + var id = scope.session.Id; var buddy = $(buddyElement); var actionElements = this.actionElements; var elem; @@ -689,11 +714,6 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! if (elem) { buddy.addClass("hovered"); } else { - var scope = buddyData.get(id); - if (!scope) { - console.warn("No scope for buddy", id); - return; - } var template = buddyActions; //if (scope.status.autoCalls && _.indexOf(scope.status.autoCalls, "conference") !== -1) { // template = buddyActionsForAudioMixer; diff --git a/static/partials/buddy.html b/static/partials/buddy.html index d0075eea..d566c41d 100644 --- a/static/partials/buddy.html +++ b/static/partials/buddy.html @@ -1,5 +1,5 @@
{{session.Id|displayName}}
-
({{session.count}}) {{display.subLine}}
+
({{session.count}}) {{display.subLine}}
diff --git a/static/partials/buddyactions.html b/static/partials/buddyactions.html index 78e31a09..df4aa7a0 100644 --- a/static/partials/buddyactions.html +++ b/static/partials/buddyactions.html @@ -1,7 +1,7 @@
- - + +