Browse Source

Use separate controllers for contactsmanager and contactsmanageredit.

pull/104/head
Evan Theurer 11 years ago
parent
commit
1364593c67
  1. 72
      static/js/controllers/contactsmanagercontroller.js
  2. 67
      static/js/controllers/contactsmanagereditcontroller.js
  3. 6
      static/js/controllers/controllers.js
  4. 54
      static/js/directives/contactsmanager.js
  5. 6
      static/js/directives/directives.js
  6. 45
      static/js/directives/settings.js
  7. 17
      static/js/services/contacts.js
  8. 2
      static/js/services/safeapply.js
  9. 4
      static/partials/contactsmanager.html

72
static/js/controllers/contactsmanagercontroller.js

@ -21,71 +21,43 @@
define([], function() { define([], function() {
// ContactsmanagerController // 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.header = data.header;
$scope.contacts = []; $scope.contacts = [];
$scope.search = {}; $scope.openContactsManagerEdit = function(contact) {
$scope.contact = null; return dialogs.create(
$scope.buddySyncable = false; "/contactsmanager/edit.html",
"ContactsmanagereditController",
var setContactInfo = function(contact) { {
contacts.update(contact.Userid, contact.Status); header: translation._("Edit Contact"),
contact: contact,
}, {
wc: "contactsmanager"
}
);
}; };
var updateContacts = function() {
var updateContacts = function(async) {
if (async) {
$scope.$apply(function(scope) {
$scope.contacts = contactData.getAll(); $scope.contacts = contactData.getAll();
safeApply($scope); });
} else {
$scope.contacts = contactData.getAll();
}
}; };
updateContacts(); updateContacts();
contacts.e.on('contactadded', function() { contacts.e.on('contactadded', function() {
updateContacts(); updateContacts(true);
}); });
contacts.e.on('contactupdated', function() { contacts.e.on('contactupdated', function() {
updateContacts(); updateContacts();
}); });
contacts.e.on('contactremoved', function() { contacts.e.on('contactremoved', function() {
// Don't call updateContacts with async true: $modalInstance.$close() is called right before, triggering a $digest.
updateContacts(); 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);
};
}]; }];
}); });

67
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 <http://www.gnu.org/licenses/>.
*
*/
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();
};
}];
});

6
static/js/controllers/controllers.js

@ -26,7 +26,8 @@ define([
'controllers/chatroomcontroller', 'controllers/chatroomcontroller',
'controllers/roomchangecontroller', 'controllers/roomchangecontroller',
'controllers/usersettingscontroller', '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 = { var controllers = {
MediastreamController: MediastreamController, MediastreamController: MediastreamController,
@ -34,7 +35,8 @@ define([
ChatroomController: ChatroomController, ChatroomController: ChatroomController,
RoomchangeController: RoomchangeController, RoomchangeController: RoomchangeController,
UsersettingsController: UsersettingsController, UsersettingsController: UsersettingsController,
ContactsmanagerController: ContactsmanagerController ContactsmanagerController: ContactsmanagerController,
ContactsmanagereditController: ContactsmanagereditController
}; };
var initialize = function(angModule) { var initialize = function(angModule) {

54
static/js/directives/contactsmanager.js

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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,
};
}];
});

6
static/js/directives/directives.js

@ -42,8 +42,7 @@ define([
'directives/pdfcanvas', 'directives/pdfcanvas',
'directives/odfcanvas', 'directives/odfcanvas',
'directives/presentation', 'directives/presentation',
'directives/youtubevideo', '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) {
'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) {
var directives = { var directives = {
onEnter: onEnter, onEnter: onEnter,
@ -67,8 +66,7 @@ define([
pdfcanvas: pdfcanvas, pdfcanvas: pdfcanvas,
odfcanvas: odfcanvas, odfcanvas: odfcanvas,
presentation: presentation, presentation: presentation,
youtubevideo: youtubevideo, youtubevideo: youtubevideo
contactsmanager: contactsmanager
}; };
var initialize = function(angModule) { var initialize = function(angModule) {

45
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() { $scope.saveSettings = function() {
var form = $scope.settingsform; var form = $scope.settingsform;
if (form.$valid && form.$dirty) { if (form.$valid && form.$dirty) {
@ -96,10 +85,6 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
}; };
$scope.openContactsManager = function() { $scope.openContactsManager = function() {
var dlgMain = null;
var dlgEdit = null;
var main = function() {
return dialogs.create( return dialogs.create(
"/contactsmanager/main.html", "/contactsmanager/main.html",
"ContactsmanagerController", "ContactsmanagerController",
@ -111,36 +96,6 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
); );
}; };
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() { $scope.checkDefaultMediaSources = function() {
if ($scope.master.settings.microphoneId && !$scope.mediaSources.hasAudioId($scope.master.settings.microphoneId)) { if ($scope.master.settings.microphoneId && !$scope.mediaSources.hasAudioId($scope.master.settings.microphoneId)) {
$scope.master.settings.microphoneId = null; $scope.master.settings.microphoneId = null;

17
static/js/services/contacts.js

@ -267,23 +267,10 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
} }
}; };
Contacts.prototype.update = function(userid, status) { Contacts.prototype.update = function(contact) {
var updateContact = _.bind(function(contact) {
contact.Status = angular.extend(contact.Status, status);
this.e.triggerHandler("contactupdated", contact);
this.put(contact); this.put(contact);
//console.log("contact update", contact); //console.log("contact update", contact);
}, this); this.e.triggerHandler("contactupdated", contact);
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));
}; };
return new Contacts(); return new Contacts();

2
static/js/services/safeapply.js

@ -22,7 +22,7 @@ define([], function() {
return ["$rootScope", function($rootScope) { return ["$rootScope", function($rootScope) {
return function($scope, fn) { return function($scope, fn) {
var phase = $scope.$root ? $scope.$root.$$phase : $scope.$$phase; var phase = $scope.$root.$$phase;
if (phase == '$apply' || phase == '$digest') { if (phase == '$apply' || phase == '$digest') {
if (fn) { if (fn) {
$scope.$eval(fn); $scope.$eval(fn);

4
static/partials/contactsmanager.html

@ -1,4 +1,4 @@
<div default-dialog contactsmanager> <div default-dialog>
<div class="row head"> <div class="row head">
<div class="col-xs-7" ng-if="contacts.length === 0"> <div class="col-xs-7" ng-if="contacts.length === 0">
<p>{{_('You have no contacts.')}}</p> <p>{{_('You have no contacts.')}}</p>
@ -17,7 +17,7 @@
<span>{{contact.Userid|displayName}}</span> <span>{{contact.Userid|displayName}}</span>
</td> </td>
<td class="action"> <td class="action">
<button class="btn btn-primary" ng-click="edit($index)">{{_('Edit')}}</button> <button class="btn btn-primary" ng-click="openContactsManagerEdit(contact)">{{_('Edit')}}</button>
</td> </td>
</tr> </tr>
</tbody> </tbody>

Loading…
Cancel
Save