diff --git a/static/js/controllers/contactsmanagercontroller.js b/static/js/controllers/contactsmanagercontroller.js index 51e354d2..2384bb1f 100644 --- a/static/js/controllers/contactsmanagercontroller.js +++ b/static/js/controllers/contactsmanagercontroller.js @@ -21,11 +21,30 @@ define([], function() { // ContactsmanagerController - return ["$scope", "$modalInstance", "contactData", "data", "contacts", function($scope, $modalInstance, contactData, data, contacts) { + return ["$scope", "$modalInstance", "contactData", "data", "contacts", 'buddySession', function($scope, $modalInstance, contactData, data, contacts, buddySession) { $scope.header = data.header; $scope.contacts = []; $scope.search = {}; + $scope.tmp = {}; + $scope.tmp.displayName = data.contact && data.contact.Status.displayName; + $scope.contact = data.contact; + $scope.session = null; + + if(data.contact) { + var sessions = buddySession.sessions(); + for (var id in sessions) { + if (sessions.hasOwnProperty(id) && sessions[id].Userid === $scope.contact.Userid) { + $scope.session = sessions[id] && sessions[id].sessions[id]; + //console.log('contact manager session', $scope.session); + } + } + } + + var totalUnnamed = 0; + $scope.unnamed = function() { + return totalUnnamed += 1; + }; var updateContacts = function() { $scope.contacts = contactData.getAll(); @@ -35,9 +54,32 @@ define([], function() { updateContacts(); }); - $scope.removeContact = function(id) { - contacts.remove(id); + var setContactInfo = function(contact) { + contact.Status.displayName = $scope.tmp.displayName; + contacts.update({Id: contact.Id, Success: contact.Success, Token: contact.Token, Userid: contact.Userid}, contact.Status); + }; + + $scope.removeContact = function() { + contacts.remove($scope.contact.Userid); updateContacts(); + $modalInstance.close(); + }; + + $scope.syncContactInfo = function() { + $scope.tmp.displayName = $scope.session.Status.displayName; + }; + + $scope.edit = function(contact) { + $modalInstance.close(contact); + }; + + $scope.save = function() { + setContactInfo(data.contact); + $modalInstance.close(); + }; + + $scope.cancel = function(contact) { + $modalInstance.dismiss(); }; }]; diff --git a/static/js/directives/contactrequest.js b/static/js/directives/contactrequest.js index ef5358a7..9e9d5d3a 100644 --- a/static/js/directives/contactrequest.js +++ b/static/js/directives/contactrequest.js @@ -53,7 +53,7 @@ define(['jquery', 'underscore'], function($, _) { var buddy = buddyData.lookup($scope.id); var status = {}; if (buddy) { - $.extend(status, buddy.status); + status = angular.isObject(buddy.status) ? angular.extend(status, buddy.status) : buddy.status; } $scope.addContact(request, status); } diff --git a/static/js/directives/settings.js b/static/js/directives/settings.js index 83cf2805..503bbb5a 100644 --- a/static/js/directives/settings.js +++ b/static/js/directives/settings.js @@ -85,15 +85,49 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t }; $scope.openContactsManager = function() { - dialogs.create( - "/contactsmanager/main.html", - "ContactsmanagerController", - { - header: translation._("Contacts Manager") - }, { - wc: "contactsmanager" - } - ) + var dlgMain = null; + var dlgEdit = null; + + var main = function() { + return dialogs.create( + "/contactsmanager/main.html", + "ContactsmanagerController", + { + header: translation._("Contacts Manager") + }, { + wc: "contactsmanager" + } + ); + }; + + var edit = function(contact) { + return dialogs.create( + "/contactsmanager/edit.html", + "ContactsmanagerController", + { + header: translation._("Edit Contact"), + contact: contact, + }, { + wc: "contactsmanager" + } + ); + }; + + function setupContactsManager() { + dlgMain = main(); + dlgMain.result.then(function(contact) { + if(contact && contact.Id) { + setupContactsManagerEdit(contact); + } + }); + } + function setupContactsManagerEdit(contact) { + dlgEdit = edit(contact); + dlgEdit.result.finally(function(final) { + setupContactsManager(); + }); + } + setupContactsManager(); }; $scope.checkDefaultMediaSources = function() { diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index ba7e4afe..ffd5cfd0 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -129,7 +129,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; // buddyList - return ["$window", "$compile", "playSound", "buddyData", "buddySession", "buddyPicture", "fastScroll", "mediaStream", "animationFrame", "$q", function($window, $compile, playSound, buddyData, buddySession, buddyPicture, fastScroll, mediaStream, animationFrame, $q) { + return ["$window", "$compile", "playSound", "buddyData", "buddySession", "buddyPicture", "fastScroll", "mediaStream", "animationFrame", "$q", '$timeout', function($window, $compile, playSound, buddyData, buddySession, buddyPicture, fastScroll, mediaStream, animationFrame, $q, $timeout) { var buddyTemplate = $compile(templateBuddy); var buddyActions = $compile(templateBuddyActions); @@ -585,7 +585,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! scope.contact = contact; var sessionData = scope.session.get(); if (sessionData) { - if (contact.Status === null && sessionData.Status) { + if (angular.isString(contact.Status) && sessionData.Status) { // Update contact status with session.Status var status = contact.Status = _.extend({}, sessionData.Status); // Remove status message. @@ -602,7 +602,10 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! console.log("Injected status into contact", contact); } this.updateDisplay(sessionData.Id, scope, contact, "status"); - scope.$apply(); + // keep asyc nature but eliminate $apply conflicts + $timeout(function() { + scope.$apply(); + }, 0, false); } } else { // Create new scope for contact. diff --git a/static/js/services/contactdata.js b/static/js/services/contactdata.js index 5f6074af..94fd425e 100644 --- a/static/js/services/contactdata.js +++ b/static/js/services/contactdata.js @@ -54,8 +54,8 @@ define(['underscore', 'jquery'], function(underscore, $) { Id: "contact-"+id, Userid: userid, Token: token, - Status: null - } + Status: status + }; return contact; }, addByData: function(data) { diff --git a/static/js/services/contacts.js b/static/js/services/contacts.js index c6d0b212..d6b06951 100644 --- a/static/js/services/contacts.js +++ b/static/js/services/contacts.js @@ -18,7 +18,7 @@ * along with this program. If not, see . * */ -define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmanager.html'], function(underscore, $, Modernizr, sjcl, templateContactsManager) { +define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmanager.html', 'text!partials/contactsmanageredit.html'], function(underscore, $, Modernizr, sjcl, templateContactsManager, templateContactsManagerEdit) { var Database = function(name) { this.version = 3; @@ -124,6 +124,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana // Inject our templates. $templateCache.put('/contactsmanager/main.html', templateContactsManager); + $templateCache.put('/contactsmanager/edit.html', templateContactsManagerEdit); var Contacts = function() { @@ -261,6 +262,12 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana } }; + Contacts.prototype.update = function(request, status) { + console.log("contact update", status); + this.remove(request.Userid); + this.add(request, status); + }; + return new Contacts(); }]; diff --git a/static/partials/contactsmanager.html b/static/partials/contactsmanager.html index 2e442f64..c5d8c267 100644 --- a/static/partials/contactsmanager.html +++ b/static/partials/contactsmanager.html @@ -14,10 +14,12 @@
- {{contact.Status.displayName}} + {{contact.Status.displayName}} + Unnamed Contact {{i}} - + + diff --git a/static/partials/contactsmanageredit.html b/static/partials/contactsmanageredit.html new file mode 100644 index 00000000..c50fc366 --- /dev/null +++ b/static/partials/contactsmanageredit.html @@ -0,0 +1,37 @@ +
+ + + +