Browse Source

Connect onerror function to db actions. Cleanups.

pull/104/head
Evan Theurer 12 years ago
parent
commit
6f7d236ed6
  1. 64
      static/js/controllers/contactsmanagercontroller.js
  2. 2
      static/js/controllers/controllers.js
  3. 4
      static/js/directives/buddylist.js
  4. 2
      static/js/directives/contactrequest.js
  5. 54
      static/js/directives/contactsmanager.js
  6. 6
      static/js/directives/directives.js
  7. 11
      static/js/directives/settings.js
  8. 4
      static/js/filters/displayname.js
  9. 18
      static/js/services/buddylist.js
  10. 4
      static/js/services/contactdata.js
  11. 36
      static/js/services/contacts.js
  12. 8
      static/partials/contactsmanager.html
  13. 4
      static/partials/contactsmanageredit.html

64
static/js/controllers/contactsmanagercontroller.js

@ -22,43 +22,47 @@ define([], function() { @@ -22,43 +22,47 @@ define([], function() {
// ContactsmanagerController
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.contact = null;
$scope.session = null;
if(data.contact) {
var tmp = {
displayName: data.contact ? data.contact.Status.displayName : null
};
var setContactInfo = function(contact) {
contacts.update(contact.Userid, contact.Status);
};
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(true);
});
contacts.e.on('contactupdated', function() {
updateContacts(true);
});
// 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 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];
$scope.session = sessions[id] ? sessions[id].sessions[id] : null;
//console.log('contact manager session', $scope.session);
}
}
}
var totalUnnamed = 0;
$scope.unnamed = function() {
return totalUnnamed += 1;
};
var updateContacts = function() {
$scope.contacts = contactData.getAll();
};
updateContacts();
contacts.e.on('contactadded', function() {
updateContacts();
});
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();
@ -66,22 +70,22 @@ define([], function() { @@ -66,22 +70,22 @@ define([], function() {
};
$scope.syncContactInfo = function() {
$scope.tmp.displayName = $scope.session.Status.displayName;
};
$scope.edit = function(contact) {
$modalInstance.close(contact);
$scope.contact.Status.displayName = $scope.session.Status.displayName;
};
$scope.save = function() {
setContactInfo(data.contact);
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);
};
}];
});

2
static/js/controllers/controllers.js

@ -26,7 +26,7 @@ define([ @@ -26,7 +26,7 @@ define([
'controllers/chatroomcontroller',
'controllers/roomchangecontroller',
'controllers/usersettingscontroller',
'controllers/contactsmanagercontroller'], function(_, MediastreamController, StatusmessageController, ChatroomController, RoomchangeController, UsersettingsController, ContactsmanagerController) {
'controllers/contactsmanagercontroller',], function(_, MediastreamController, StatusmessageController, ChatroomController, RoomchangeController, UsersettingsController, ContactsmanagerController) {
var controllers = {
MediastreamController: MediastreamController,

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);
});
}];

2
static/js/directives/contactrequest.js

@ -53,7 +53,7 @@ define(['jquery', 'underscore'], function($, _) { @@ -53,7 +53,7 @@ define(['jquery', 'underscore'], function($, _) {
var buddy = buddyData.lookup($scope.id);
var status = {};
if (buddy) {
status = angular.isObject(buddy.status) ? angular.extend(status, buddy.status) : buddy.status;
$.extend(status, buddy.status);
}
$scope.addContact(request, status);
}

54
static/js/directives/contactsmanager.js

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

11
static/js/directives/settings.js

@ -51,6 +51,17 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -51,6 +51,17 @@ 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) {

4
static/js/filters/displayname.js

@ -29,6 +29,7 @@ define([], function() { @@ -29,6 +29,7 @@ define([], function() {
var user_text = translation._("User");
var someone_text = translation._("Someone");
var me_text = translation._("Me");
var contact_text = translation._("Unnamed Contact");
return function(id, me_ok) {
if (id === group_chat_id) {
return "";
@ -38,6 +39,9 @@ define([], function() { @@ -38,6 +39,9 @@ define([], function() {
if (scope.display.displayName) {
return scope.display.displayName;
}
if(me_ok === "contactsmanager") {
return contact_text + " " + scope.buddyIndex;
}
return user_text + " " + scope.buddyIndex;
} else {
var data = appData.get();

18
static/js/services/buddylist.js

@ -129,7 +129,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -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", '$timeout', function($window, $compile, playSound, buddyData, buddySession, buddyPicture, fastScroll, mediaStream, animationFrame, $q, $timeout) {
return ["$window", "$compile", "playSound", "buddyData", "buddySession", "buddyPicture", "fastScroll", "mediaStream", "animationFrame", "$q", function($window, $compile, playSound, buddyData, buddySession, buddyPicture, fastScroll, mediaStream, animationFrame, $q) {
var buddyTemplate = $compile(templateBuddy);
var buddyActions = $compile(templateBuddyActions);
@ -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);
@ -585,7 +594,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -585,7 +594,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
scope.contact = contact;
var sessionData = scope.session.get();
if (sessionData) {
if (angular.isString(contact.Status) && sessionData.Status) {
if (contact.Status === null && sessionData.Status) {
// Update contact status with session.Status
var status = contact.Status = _.extend({}, sessionData.Status);
// Remove status message.
@ -602,10 +611,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -602,10 +611,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
console.log("Injected status into contact", contact);
}
this.updateDisplay(sessionData.Id, scope, contact, "status");
// keep asyc nature but eliminate $apply conflicts
$timeout(function() {
scope.$apply();
}, 0, false);
scope.$apply();
}
} else {
// Create new scope for contact.

4
static/js/services/contactdata.js

@ -54,8 +54,8 @@ define(['underscore', 'jquery'], function(underscore, $) { @@ -54,8 +54,8 @@ define(['underscore', 'jquery'], function(underscore, $) {
Id: "contact-"+id,
Userid: userid,
Token: token,
Status: status
};
Status: null
}
return contact;
},
addByData: function(data) {

36
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', 'text!partials/contactsmanageredit.html'], function(underscore, $, Modernizr, sjcl, templateContactsManager, templateContactsManagerEdit) {
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) {
@ -156,6 +157,13 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -156,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)) {
@ -243,10 +251,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -243,10 +251,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);
}
};
@ -262,10 +267,23 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana @@ -262,10 +267,23 @@ 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);
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));
};
return new Contacts();

8
static/partials/contactsmanager.html

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<div default-dialog>
<div default-dialog contactsmanager>
<div class="row head">
<div class="col-xs-7" ng-if="contacts.length === 0">
<p>{{_('You have no contacts.')}}</p>
@ -14,12 +14,10 @@ @@ -14,12 +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 ng-if="contact.Status.displayName">{{contact.Status.displayName}}</span>
<span ng-if="!contact.Status.displayName" ng-init="i = unnamed()">Unnamed Contact {{i}}</span>
<span>{{contact.Userid|displayName:'contactsmanager'}}</span>
</td>
<td class="action">
<!-- <button class="btn btn-danger" ng-click="removeContact(contact.Userid)">{{_('Remove')}}</button> -->
<button class="btn btn-primary" ng-click="edit(contact)">{{_('Edit')}}</button>
<button class="btn btn-primary" ng-click="edit($index)">{{_('Edit')}}</button>
</td>
</tr>
</tbody>

4
static/partials/contactsmanageredit.html

@ -3,13 +3,13 @@ @@ -3,13 +3,13 @@
<button type="button" class="close" ng-click="$close()">×</button>
<h3 class="modal-title" ng-bind-html="header"></h3>
</div>
<div class="modal-header">
<div class="modal-body">
<div class="row">
<form class="form-horizontal">
<div class="form-group">
<label class="col-xs-4 control-label">{{_('Name')}}</label>
<div class="col-xs-6">
<input type="text" class="form-control" ng-model="tmp.displayName">
<input placeholder="{{_('Unnamed')}}" type="text" class="form-control" ng-model="contact.Status.displayName">
</div>
</div>
<div class="form-group" ng-if="session.Type">

Loading…
Cancel
Save