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() {
// ContactsmanagerController // ContactsmanagerController
return ["$scope", "$modalInstance", "contactData", "data", "contacts", 'buddySession', function($scope, $modalInstance, contactData, data, contacts, buddySession) { return ["$scope", "$modalInstance", "contactData", "data", "contacts", 'buddySession', function($scope, $modalInstance, contactData, data, contacts, buddySession) {
$scope.header = data.header; $scope.header = data.header;
$scope.contacts = []; $scope.contacts = [];
$scope.search = {}; $scope.search = {};
$scope.tmp = {}; $scope.contact = null;
$scope.tmp.displayName = data.contact && data.contact.Status.displayName;
$scope.contact = data.contact;
$scope.session = 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(); var sessions = buddySession.sessions();
for (var id in sessions) { for (var id in sessions) {
if (sessions.hasOwnProperty(id) && sessions[id].Userid === $scope.contact.Userid) { 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); //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() { $scope.removeContact = function() {
contacts.remove($scope.contact.Userid); contacts.remove($scope.contact.Userid);
updateContacts(); updateContacts();
@ -66,22 +70,22 @@ define([], function() {
}; };
$scope.syncContactInfo = function() { $scope.syncContactInfo = function() {
$scope.tmp.displayName = $scope.session.Status.displayName; $scope.contact.Status.displayName = $scope.session.Status.displayName;
};
$scope.edit = function(contact) {
$modalInstance.close(contact);
}; };
$scope.save = function() { $scope.save = function() {
setContactInfo(data.contact); setContactInfo($scope.contact);
$modalInstance.close(); $modalInstance.close();
}; };
$scope.cancel = function(contact) { $scope.cancel = function(contact) {
$scope.contact.Status.displayName = tmp.displayName;
$modalInstance.dismiss(); $modalInstance.dismiss();
}; };
$scope.edit = function(index) {
$scope.$broadcast('openEditContact', index);
};
}]; }];
}); });

2
static/js/controllers/controllers.js

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

4
static/js/directives/buddylist.js

@ -84,6 +84,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
var onStatus = _.bind(buddylist.onStatus, buddylist); var onStatus = _.bind(buddylist.onStatus, buddylist);
var onContactAdded = _.bind(buddylist.onContactAdded, buddylist); var onContactAdded = _.bind(buddylist.onContactAdded, buddylist);
var onContactRemoved = _.bind(buddylist.onContactRemoved, buddylist); var onContactRemoved = _.bind(buddylist.onContactRemoved, buddylist);
var onContactUpdated = _.bind(buddylist.onContactUpdated, buddylist);
mediaStream.api.e.on("received.userleftorjoined", function(event, dataType, data) { mediaStream.api.e.on("received.userleftorjoined", function(event, dataType, data) {
if (dataType === "Left") { if (dataType === "Left") {
onLeft(data); onLeft(data);
@ -119,6 +120,9 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
contacts.e.on("contactremoved", function(event, data) { contacts.e.on("contactremoved", function(event, data) {
onContactRemoved(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($, _) {
var buddy = buddyData.lookup($scope.id); var buddy = buddyData.lookup($scope.id);
var status = {}; var status = {};
if (buddy) { if (buddy) {
status = angular.isObject(buddy.status) ? angular.extend(status, buddy.status) : buddy.status; $.extend(status, buddy.status);
} }
$scope.addContact(request, status); $scope.addContact(request, status);
} }

54
static/js/directives/contactsmanager.js

@ -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([
'directives/pdfcanvas', 'directives/pdfcanvas',
'directives/odfcanvas', 'directives/odfcanvas',
'directives/presentation', '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 = { var directives = {
onEnter: onEnter, onEnter: onEnter,
@ -66,7 +67,8 @@ 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) {

11
static/js/directives/settings.js

@ -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() { $scope.saveSettings = function() {
var form = $scope.settingsform; var form = $scope.settingsform;
if (form.$valid && form.$dirty) { if (form.$valid && form.$dirty) {

4
static/js/filters/displayname.js

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

18
static/js/services/buddylist.js

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

4
static/js/services/contactdata.js

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

36
static/js/services/contacts.js

@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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) { var Database = function(name) {
this.version = 3; this.version = 3;
@ -36,6 +36,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
console.info("Created contacts database.") console.info("Created contacts database.")
}; };
request.onsuccess = _.bind(that.onsuccess, that); request.onsuccess = _.bind(that.onsuccess, that);
request.onerror = _.bind(that.onerror, that);
}; };
Database.prototype.init = function(db) { Database.prototype.init = function(db) {
var createOrUpdateStore = function(name, obj) { var createOrUpdateStore = function(name, obj) {
@ -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) { Contacts.prototype.open = function(userid, suserid) {
if (this.database && (!userid || this.userid !== userid)) { if (this.database && (!userid || this.userid !== userid)) {
@ -243,10 +251,7 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
var contact = contactData.addByRequest(request, status); var contact = contactData.addByRequest(request, status);
this.e.triggerHandler("contactadded", contact); this.e.triggerHandler("contactadded", contact);
if (this.database) { if (this.database) {
this.database.put("contacts", { this.put(contact);
id: this.id(contact.Userid),
contact: this.encrypt(contact)
})
} }
}; };
@ -262,10 +267,23 @@ define(['underscore', 'jquery', 'modernizr', 'sjcl', 'text!partials/contactsmana
} }
}; };
Contacts.prototype.update = function(request, status) { Contacts.prototype.update = function(userid, status) {
console.log("contact update", status); var updateContact = _.bind(function(contact) {
this.remove(request.Userid); contact.Status = angular.extend(contact.Status, status);
this.add(request, 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(); return new Contacts();

8
static/partials/contactsmanager.html

@ -1,4 +1,4 @@
<div default-dialog> <div default-dialog contactsmanager>
<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>
@ -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> <div class="buddyPicture"><i class="fa fa-user"/><img ng-show="contact.Status.buddyPicture" alt ng-src="{{contact.Status.buddyPicture}}"/></div>
</td> </td>
<td class="name"> <td class="name">
<span ng-if="contact.Status.displayName">{{contact.Status.displayName}}</span> <span>{{contact.Userid|displayName:'contactsmanager'}}</span>
<span ng-if="!contact.Status.displayName" ng-init="i = unnamed()">Unnamed Contact {{i}}</span>
</td> </td>
<td class="action"> <td class="action">
<!-- <button class="btn btn-danger" ng-click="removeContact(contact.Userid)">{{_('Remove')}}</button> --> <button class="btn btn-primary" ng-click="edit($index)">{{_('Edit')}}</button>
<button class="btn btn-primary" ng-click="edit(contact)">{{_('Edit')}}</button>
</td> </td>
</tr> </tr>
</tbody> </tbody>

4
static/partials/contactsmanageredit.html

@ -3,13 +3,13 @@
<button type="button" class="close" ng-click="$close()">×</button> <button type="button" class="close" ng-click="$close()">×</button>
<h3 class="modal-title" ng-bind-html="header"></h3> <h3 class="modal-title" ng-bind-html="header"></h3>
</div> </div>
<div class="modal-header"> <div class="modal-body">
<div class="row"> <div class="row">
<form class="form-horizontal"> <form class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label class="col-xs-4 control-label">{{_('Name')}}</label> <label class="col-xs-4 control-label">{{_('Name')}}</label>
<div class="col-xs-6"> <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> </div>
<div class="form-group" ng-if="session.Type"> <div class="form-group" ng-if="session.Type">

Loading…
Cancel
Save