diff --git a/static/js/controllers/contactsmanagercontroller.js b/static/js/controllers/contactsmanagercontroller.js
index 955a17dc..8fba15df 100644
--- a/static/js/controllers/contactsmanagercontroller.js
+++ b/static/js/controllers/contactsmanagercontroller.js
@@ -21,71 +21,43 @@
define([], function() {
// ContactsmanagerController
- return ["$scope", "$modalInstance", "contactData", "data", "contacts", 'buddyData', 'safeApply', function($scope, $modalInstance, contactData, data, contacts, buddyData, safeApply) {
+ return ["$scope", "$modalInstance", "contactData", "data", "contacts", 'dialogs', 'translation', function($scope, $modalInstance, contactData, data, contacts, dialogs, translation) {
$scope.header = data.header;
$scope.contacts = [];
- $scope.search = {};
- $scope.contact = null;
- $scope.buddySyncable = false;
-
- var setContactInfo = function(contact) {
- contacts.update(contact.Userid, contact.Status);
- };
- var updateContacts = function() {
- $scope.contacts = contactData.getAll();
- safeApply($scope);
+ $scope.openContactsManagerEdit = function(contact) {
+ return dialogs.create(
+ "/contactsmanager/edit.html",
+ "ContactsmanagereditController",
+ {
+ header: translation._("Edit Contact"),
+ contact: contact,
+ }, {
+ wc: "contactsmanager"
+ }
+ );
+ };
+
+ var updateContacts = function(async) {
+ if (async) {
+ $scope.$apply(function(scope) {
+ $scope.contacts = contactData.getAll();
+ });
+ } else {
+ $scope.contacts = contactData.getAll();
+ }
};
updateContacts();
contacts.e.on('contactadded', function() {
- updateContacts();
+ updateContacts(true);
});
contacts.e.on('contactupdated', function() {
updateContacts();
});
contacts.e.on('contactremoved', function() {
+ // Don't call updateContacts with async true: $modalInstance.$close() is called right before, triggering a $digest.
updateContacts();
});
- // Values to check include 0, so check for number to get around incorrect 'false' type conversion
- if (angular.isNumber(data.contactIndex)) {
- $scope.contact = $scope.contacts[data.contactIndex];
- var scope = buddyData.lookup($scope.contact.Userid, false, false);
- if(scope) {
- var session = scope.session.get();
- $scope.buddySyncable = session.Type ? true : false;
- }
- }
- var tmp = {
- displayName: $scope.contact ? $scope.contact.Status.displayName : null
- };
-
- $scope.removeContact = function() {
- // async, see contactremoved callback
- contacts.remove($scope.contact.Userid);
- $modalInstance.close();
- };
-
- $scope.syncContactInfo = function() {
- var scope = buddyData.lookup($scope.contact.Userid, false, false);
- if(scope) {
- var session = scope.session.get();
- $scope.contact.Status.displayName = session.Status.displayName;
- }
- };
-
- $scope.save = function() {
- setContactInfo($scope.contact);
- $modalInstance.close();
- };
-
- $scope.cancel = function(contact) {
- $scope.contact.Status.displayName = tmp.displayName;
- $modalInstance.dismiss();
- };
-
- $scope.edit = function(index) {
- $scope.$broadcast('openEditContact', index);
- };
}];
});
diff --git a/static/js/controllers/contactsmanagereditcontroller.js b/static/js/controllers/contactsmanagereditcontroller.js
new file mode 100644
index 00000000..cc4b01bb
--- /dev/null
+++ b/static/js/controllers/contactsmanagereditcontroller.js
@@ -0,0 +1,67 @@
+/*
+ * Spreed WebRTC.
+ * Copyright (C) 2013-2014 struktur AG
+ *
+ * This file is part of Spreed WebRTC.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+define([], function() {
+
+ // ContactsmanagereditController
+ return ["$scope", "$modalInstance", "data", "contacts", 'buddyData', function($scope, $modalInstance, data, contacts, buddyData) {
+ $scope.header = data.header;
+ $scope.contact = data.contact ? data.contact : null;
+ $scope.buddySyncable = false;
+
+ var originalDisplayName = null;
+ var setContactInfo = function(contact) {
+ contacts.update(contact);
+ };
+ if ($scope.contact) {
+ originalDisplayName = $scope.contact.Status.displayName;
+ var scope = buddyData.lookup($scope.contact.Userid, false, false);
+ if (scope) {
+ var session = scope.session.get();
+ $scope.buddySyncable = session && session.Type ? true : false;
+ }
+ }
+
+ $scope.removeContact = function() {
+ contacts.remove($scope.contact.Userid);
+ $modalInstance.close();
+ };
+
+ $scope.syncContactInfo = function() {
+ var scope = buddyData.lookup($scope.contact.Userid, false, false);
+ if (scope) {
+ var session = scope.session.get();
+ $scope.contact.Status.displayName = session.Status.displayName;
+ }
+ };
+
+ $scope.save = function() {
+ setContactInfo($scope.contact);
+ $modalInstance.close();
+ };
+
+ $scope.cancel = function(contact) {
+ $scope.contact.Status.displayName = originalDisplayName;
+ $modalInstance.dismiss();
+ };
+
+ }];
+
+});
diff --git a/static/js/controllers/controllers.js b/static/js/controllers/controllers.js
index f85da201..e0d385d2 100644
--- a/static/js/controllers/controllers.js
+++ b/static/js/controllers/controllers.js
@@ -26,7 +26,8 @@ define([
'controllers/chatroomcontroller',
'controllers/roomchangecontroller',
'controllers/usersettingscontroller',
- 'controllers/contactsmanagercontroller',], function(_, MediastreamController, StatusmessageController, ChatroomController, RoomchangeController, UsersettingsController, ContactsmanagerController) {
+ 'controllers/contactsmanagercontroller',
+ 'controllers/contactsmanagereditcontroller'], function(_, MediastreamController, StatusmessageController, ChatroomController, RoomchangeController, UsersettingsController, ContactsmanagerController, ContactsmanagereditController) {
var controllers = {
MediastreamController: MediastreamController,
@@ -34,7 +35,8 @@ define([
ChatroomController: ChatroomController,
RoomchangeController: RoomchangeController,
UsersettingsController: UsersettingsController,
- ContactsmanagerController: ContactsmanagerController
+ ContactsmanagerController: ContactsmanagerController,
+ ContactsmanagereditController: ContactsmanagereditController
};
var initialize = function(angModule) {
diff --git a/static/js/directives/contactsmanager.js b/static/js/directives/contactsmanager.js
deleted file mode 100644
index cc70ef1d..00000000
--- a/static/js/directives/contactsmanager.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Spreed WebRTC.
- * Copyright (C) 2013-2014 struktur AG
- *
- * This file is part of Spreed WebRTC.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-define(['underscore', 'jquery'], function(_, $) {
-
- // contactsmanager
- return [function() {
-
- var controller = ['$scope', 'dialogs', 'translation', function($scope, dialogs, translation) {
-
- var editContactDialog = function(index) {
- return dialogs.create(
- "/contactsmanager/edit.html",
- "ContactsmanagerController",
- {
- header: translation._("Edit Contact"),
- contactIndex: index,
- }, {
- wc: "contactsmanager"
- }
- );
- };
-
- $scope.$on('openEditContact', function(event, index) {
- editContactDialog(index);
- });
- }];
-
- return {
- scope: true,
- restrict: "A",
- controller: controller,
- };
-
- }];
-
-});
diff --git a/static/js/directives/directives.js b/static/js/directives/directives.js
index 4aa68ea1..de5d0458 100644
--- a/static/js/directives/directives.js
+++ b/static/js/directives/directives.js
@@ -42,8 +42,7 @@ define([
'directives/pdfcanvas',
'directives/odfcanvas',
'directives/presentation',
- 'directives/youtubevideo',
- 'directives/contactsmanager',], function(_, onEnter, onEscape, statusMessage, buddyList, buddyPictureCapture, buddyPictureUpload, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page, contactRequest, defaultDialog, pdfcanvas, odfcanvas, presentation, youtubevideo, contactsmanager) {
+ 'directives/youtubevideo',], function(_, onEnter, onEscape, statusMessage, buddyList, buddyPictureCapture, buddyPictureUpload, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page, contactRequest, defaultDialog, pdfcanvas, odfcanvas, presentation, youtubevideo) {
var directives = {
onEnter: onEnter,
@@ -67,8 +66,7 @@ define([
pdfcanvas: pdfcanvas,
odfcanvas: odfcanvas,
presentation: presentation,
- youtubevideo: youtubevideo,
- contactsmanager: contactsmanager
+ youtubevideo: youtubevideo
};
var initialize = function(angModule) {
diff --git a/static/js/directives/settings.js b/static/js/directives/settings.js
index 80e5fc53..5465bd50 100644
--- a/static/js/directives/settings.js
+++ b/static/js/directives/settings.js
@@ -51,17 +51,6 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
}
});
- $scope.openContactsManager = function() {
- return dialogs.create(
- "/contactsmanager/main.html",
- "ContactsmanagerController",
- {
- header: translation._("Contacts Manager")
- }, {
- wc: "contactsmanager"
- }
- );
- };
$scope.saveSettings = function() {
var form = $scope.settingsform;
if (form.$valid && form.$dirty) {
@@ -96,49 +85,15 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
};
$scope.openContactsManager = function() {
- 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();
+ return dialogs.create(
+ "/contactsmanager/main.html",
+ "ContactsmanagerController",
+ {
+ header: translation._("Contacts Manager")
+ }, {
+ wc: "contactsmanager"
+ }
+ );
};
$scope.checkDefaultMediaSources = function() {
diff --git a/static/js/services/contacts.js b/static/js/services/contacts.js
index 9e91039d..db13501d 100644
--- a/static/js/services/contacts.js
+++ b/static/js/services/contacts.js
@@ -267,23 +267,10 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
}
};
- Contacts.prototype.update = function(userid, status) {
- var updateContact = _.bind(function(contact) {
- contact.Status = angular.extend(contact.Status, status);
- this.e.triggerHandler("contactupdated", contact);
- this.put(contact);
- //console.log("contact update", contact);
- }, this);
- this.database.all("contacts", _.bind(function(data) {
- var d = this.decrypt(data.contact);
- if (d) {
- var contact = contactData.addByData(d);
- if (contact.Userid === userid) {
- //console.log('found contact in database', contact);
- updateContact(contact);
- }
- }
- }, this));
+ Contacts.prototype.update = function(contact) {
+ this.put(contact);
+ //console.log("contact update", contact);
+ this.e.triggerHandler("contactupdated", contact);
};
return new Contacts();
diff --git a/static/js/services/safeapply.js b/static/js/services/safeapply.js
index b27d3f01..6e913128 100644
--- a/static/js/services/safeapply.js
+++ b/static/js/services/safeapply.js
@@ -22,7 +22,7 @@ define([], function() {
return ["$rootScope", function($rootScope) {
return function($scope, fn) {
- var phase = $scope.$root ? $scope.$root.$$phase : $scope.$$phase;
+ var phase = $scope.$root.$$phase;
if (phase == '$apply' || phase == '$digest') {
if (fn) {
$scope.$eval(fn);
diff --git a/static/partials/contactsmanager.html b/static/partials/contactsmanager.html
index 8d099676..2269880d 100644
--- a/static/partials/contactsmanager.html
+++ b/static/partials/contactsmanager.html
@@ -1,4 +1,4 @@
-
+
{{_('You have no contacts.')}}
@@ -17,7 +17,7 @@
{{contact.Userid|displayName}}
-
+
|