Browse Source

Merge pull request #104 from theurere/contacts-edit

Contacts edit
pull/111/head
Simon Eisenmann 11 years ago
parent
commit
fd0b3ada6b
  1. 25
      static/js/controllers/contactsmanagercontroller.js
  2. 67
      static/js/controllers/contactsmanagereditcontroller.js
  3. 6
      static/js/controllers/controllers.js
  4. 4
      static/js/directives/buddylist.js
  5. 4
      static/js/directives/settings.js
  6. 11
      static/js/services/buddylist.js
  7. 22
      static/js/services/contacts.js
  8. 4
      static/partials/contactsmanager.html
  9. 35
      static/partials/contactsmanageredit.html

25
static/js/controllers/contactsmanagercontroller.js

@ -21,11 +21,21 @@ @@ -21,11 +21,21 @@
define([], function() {
// ContactsmanagerController
return ["$scope", "$modalInstance", "contactData", "data", "contacts", function($scope, $modalInstance, contactData, data, contacts) {
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.openContactsManagerEdit = function(contact) {
return dialogs.create(
"/contactsmanager/edit.html",
"ContactsmanagereditController",
{
header: translation._("Edit Contact"),
contact: contact,
}, {
wc: "contactsmanager"
}
);
};
var updateContacts = function() {
$scope.contacts = contactData.getAll();
@ -34,11 +44,12 @@ define([], function() { @@ -34,11 +44,12 @@ define([], function() {
contacts.e.on('contactadded', function() {
updateContacts();
});
$scope.removeContact = function(id) {
contacts.remove(id);
contacts.e.on('contactupdated', function() {
updateContacts();
};
});
contacts.e.on('contactremoved', function() {
updateContacts();
});
}];

67
static/js/controllers/contactsmanagereditcontroller.js

@ -0,0 +1,67 @@ @@ -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([ @@ -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([ @@ -34,7 +35,8 @@ define([
ChatroomController: ChatroomController,
RoomchangeController: RoomchangeController,
UsersettingsController: UsersettingsController,
ContactsmanagerController: ContactsmanagerController
ContactsmanagerController: ContactsmanagerController,
ContactsmanagereditController: ContactsmanagereditController
};
var initialize = function(angModule) {

4
static/js/directives/buddylist.js

@ -84,6 +84,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { @@ -84,6 +84,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
var onStatus = _.bind(buddylist.onStatus, buddylist);
var onContactAdded = _.bind(buddylist.onContactAdded, buddylist);
var onContactRemoved = _.bind(buddylist.onContactRemoved, buddylist);
var onContactUpdated = _.bind(buddylist.onContactUpdated, buddylist);
mediaStream.api.e.on("received.userleftorjoined", function(event, dataType, data) {
if (dataType === "Left") {
onLeft(data);
@ -119,6 +120,9 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { @@ -119,6 +120,9 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
contacts.e.on("contactremoved", function(event, data) {
onContactRemoved(data);
});
contacts.e.on("contactupdated", function(event, data) {
onContactUpdated(data);
});
}];

4
static/js/directives/settings.js

@ -85,7 +85,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -85,7 +85,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
};
$scope.openContactsManager = function() {
dialogs.create(
return dialogs.create(
"/contactsmanager/main.html",
"ContactsmanagerController",
{
@ -93,7 +93,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -93,7 +93,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
}, {
wc: "contactsmanager"
}
)
);
};
$scope.checkDefaultMediaSources = function() {

11
static/js/services/buddylist.js

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!partials/buddyactions.html', 'text!partials/buddyactionsforaudiomixer.html'], function(_, Modernizr, AvlTree, templateBuddy, templateBuddyActions, templateBuddyActionsForAudioMixer) {
define(['angular', 'underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!partials/buddyactions.html', 'text!partials/buddyactionsforaudiomixer.html'], function(angular, _, Modernizr, AvlTree, templateBuddy, templateBuddyActions, templateBuddyActionsForAudioMixer) {
var BuddyTree = function() {
@ -450,6 +450,15 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -450,6 +450,15 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
};
Buddylist.prototype.onContactUpdated = function(data) {
var scope = buddyData.get(data.Userid);
if (scope && scope.contact) {
scope.contact.Status = angular.extend(scope.contact.Status, data.Status);
}
this.updateDisplay(data.Id, scope, data, "status");
//console.log("onContactUpdated", 'data', data, 'scope', scope);
};
Buddylist.prototype.onStatus = function(data) {
//console.log("onStatus", data);

22
static/js/services/contacts.js

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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(_, $, Modernizr, sjcl, templateContactsManager, templateContactsManagerEdit) {
var Database = function(name) {
this.version = 3;
@ -36,6 +36,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -36,6 +36,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
console.info("Created contacts database.")
};
request.onsuccess = _.bind(that.onsuccess, that);
request.onerror = _.bind(that.onerror, that);
};
Database.prototype.init = function(db) {
var createOrUpdateStore = function(name, obj) {
@ -124,6 +125,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -124,6 +125,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() {
@ -155,6 +157,13 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -155,6 +157,13 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
};
Contacts.prototype.put = function(contact) {
this.database.put("contacts", {
id: this.id(contact.Userid),
contact: this.encrypt(contact)
});
}
Contacts.prototype.open = function(userid, suserid) {
if (this.database && (!userid || this.userid !== userid)) {
@ -241,10 +250,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -241,10 +250,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
var contact = contactData.addByRequest(request, status);
this.e.triggerHandler("contactadded", contact);
if (this.database) {
this.database.put("contacts", {
id: this.id(contact.Userid),
contact: this.encrypt(contact)
})
this.put(contact);
}
};
@ -260,6 +266,12 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -260,6 +266,12 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
}
};
Contacts.prototype.update = function(contact) {
this.put(contact);
//console.log("contact update", contact);
this.e.triggerHandler("contactupdated", contact);
};
return new Contacts();
}];

4
static/partials/contactsmanager.html

@ -14,10 +14,10 @@ @@ -14,10 +14,10 @@
<div class="buddyPicture"><i class="fa fa-user"/><img ng-show="contact.Status.buddyPicture" alt ng-src="{{contact.Status.buddyPicture}}"/></div>
</td>
<td class="name">
<span>{{contact.Status.displayName}}</span>
<span>{{contact.Userid|displayName}}</span>
</td>
<td class="action">
<button class="btn btn-danger" ng-click="removeContact(contact.Userid)">{{_('Remove')}}</button>
<button class="btn btn-primary" ng-click="openContactsManagerEdit(contact)">{{_('Edit')}}</button>
</td>
</tr>
</tbody>

35
static/partials/contactsmanageredit.html

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
<div>
<div class="modal-header">
<button type="button" class="close" ng-click="$close()">×</button>
<h3 class="modal-title" ng-bind-html="header"></h3>
</div>
<div class="modal-body">
<div class="row form-horizontal">
<div class="form-group">
<label for="contact-name" class="col-xs-4 control-label">{{_('Name')}}</label>
<div class="col-xs-6">
<input id="contact-name" class="form-control" type="text" placeholder="{{_('Contact alias')}}" ng-model="contact.Status.displayName">
</div>
</div>
<div class="form-group" ng-if="buddySyncable">
<label for="contact-sync" class="col-xs-4 control-label">{{_('Sync')}}</label>
<div class="col-xs-6">
<button id="contact-sync" class="btn btn-warning" ng-click="syncContactInfo()"><span class="fa fa-rotate-right"></span> {{_('Sync contact info')}}</button>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-xs-2">
<button class="btn btn-danger" ng-click="removeContact()">{{_('Remove')}}</button>
</div>
<div class="col-xs-offset-4 col-xs-6">
<div class="pull-right">
<button class="btn btn-default" ng-click="cancel()">{{_('Cancel')}}</button>
<button class="btn btn-primary" ng-click="save()">{{_('Save')}}</button>
</div>
</div>
</div>
</div>
</div>
Loading…
Cancel
Save