Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

web: contacts are shown :)

  • Loading branch information...
commit 99ded01db50e5f59413f8e7a69ac24c7bae0ba6d 1 parent dfa2302
@billiob billiob authored
Showing with 126 additions and 120 deletions.
  1. +126 −120 amsn2/ui/front_ends/web/static/backend.js
View
246 amsn2/ui/front_ends/web/static/backend.js
@@ -1,42 +1,49 @@
// Backend functions
+// Contact List {{{
function ContactList()
{
var groups = {};
var contacts = {};
var group_ids = [];
var head=$("<div/>");
+
this.setGroups = function(parent, _group_ids){
var prev = head;
- var k, i, j = 0;
+ var i, j = 0;
+
+ console.log("group ids = " + _group_ids);
+ console.log("length = " + _group_ids.length);
if (prev.parent() != parent)
parent.append(prev);
- while (group_ids.length && _group_ids.indexOf(group_ids[j]) < 0)
- group_ids.splice(j,1);
+ for (i = group_ids.length - 1; i >= 0; i--) {
+ if (_group_ids.indexOf(group_ids[i]) < 0) {
+ group_ids.splice(i,1);
+ }
+ }
for (i = 0; i < _group_ids.length; i++) {
if (group_ids[j] == _group_ids[i]) {
prev = this.getGroup(_group_ids[i]).getTop();
j++;
- while (group_ids.length && _group_ids.indexOf(group_ids[j]) < 0)
- group_ids.splice(j, 1);
} else {
- if ((k = group_ids.indexOf(_group_ids[i])) > -1)
- group_ids.splice(k, 1);
elem = this.getGroup(_group_ids[i]).getTop();
elem.insertAfter(prev);
prev = elem;
}
}
+ group_ids = _group_ids;
}
+
this.getContact = function(uid){
if (contacts[uid] == undefined)
contacts[uid] = new Contact(uid);
return contacts[uid];
}
+
this.getGroup = function(uid){
if (groups[uid] == undefined)
groups[uid] = new Group(uid);
@@ -47,7 +54,7 @@ function ContactList()
function Group(_uid)
{
var uid = _uid;
- var contacts = [];
+ var contact_ids = [];
var name = "";
var top = $("<div/>");
@@ -61,6 +68,7 @@ function Group(_uid)
var elementVisible = true;
+ console.log("New group " + _uid);
header.click(function() {
element.slideToggle("slow");
elementVisible = !elementVisible;
@@ -75,46 +83,58 @@ function Group(_uid)
this.getName = function() {
return name;
}
+
this.getUid = function() {
return uid;
}
+
this.setName = function(_name) {
name = _name;
refresh();
}
- this.setContacts = function(_contacts) {
+
+ this.setContacts = function(_contact_ids) {
var prev = first;
- var k, i, j = 0;
+ var i, j = 0;
- while (contacts.length && _contacts.indexOf(contacts[j]) < 0)
- contacts.splice(j,1);
+ for (i = contact_ids.length - 1; i >= 0; i--) {
+ if (_contact_ids.indexOf(contact_ids[i]) < 0) {
+ contact_ids.splice(i,1);
+ }
+ }
- for (i = 0; i < _contacts.length; i++) {
- if (contacts[j] == _contacts[i]) {
- prev = contacts[i].getElement(uid);
+ for (i = 0; i < _contact_ids.length; i++) {
+ if (contact_ids[j] == _contact_ids[i]) {
+ prev = contactList.getContact(_contact_ids[i]).getElement(uid);
j++;
- while (contacts.length && contacts.indexOf(contacts[j]) < 0)
- contacts.splice(j,1);
} else {
- if ((k = contacts.indexOf(_contacts[i])) > -1)
- contacts.splice(k, 1);
- elem = _contacts[i].getElement(uid);
+ elem = contactList.getContact(_contact_ids[i]).getElement(uid);
elem.insertAfter(prev);
prev = elem;
}
}
- contacts = _contacts;
+ contact_ids = _contact_ids;
refresh();
}
+
this.getContacts = function() {
- return contacts;
+ return contact_ids;
}
+
this.getElement = function() {
return element;
}
+
+ this.getContact = function(uid){
+ if (contacts[uid] == undefined)
+ contacts[uid] = new Contact(uid);
+ return contacts[uid];
+ }
+
this.getTop = function() {
return top;
}
+
refresh();
}
@@ -161,8 +181,45 @@ function Contact(_uid)
}
}
+// contact_list
+var contactList = new ContactList();
+
+function showContactListWindow()
+{
+ $("div.contact_list").show("slow");
+}
+
+function hideContactListWindow()
+{
+ $("div.contact_list").hide("slow");
+}
+
+function setContactListTitle(title)
+{
+ $("div.contact_list div.title").text(title);
+}
+
+function contactListUpdated(groupsL)
+{
+ contactList.setGroups($("div.contact_list"), groupsL);
+}
+
+function groupUpdated(uid, name, contact_ids)
+{
+ var group = contactList.getGroup(uid);
+ group.setName(name);
+ group.setContacts(contact_ids);
+}
+
+function contactUpdated(uid, name)
+{
+ contactList.getContact(uid).setName(name);
+}
+// }}}
+// ChatWindow {{{
function ChatWindow(_uid)
{
+
var uid = _uid;
var element = $("<div class='chatWindow'/>");
@@ -271,6 +328,49 @@ function ChatWidget(_uid)
}
}
+// Chat functions
+var chatWindows = {};
+var chatWidgets = {};
+
+function newChatWindow(uid)
+{
+ chatWindows[uid] = new ChatWindow(uid);
+}
+
+function addChatWidget(windowUid, widgetUid)
+{
+ chatWindows[windowUid].addChatWidget(chatWidgets[widgetUid]);
+}
+
+function showChatWindow(uidL)
+{
+ var uid = uidL.shift();
+ chatWindows[uid].show();
+}
+
+function hideChatWindow(uidL)
+{
+ var uid = uidL.shift();
+ chatWindows[uid].hide();
+}
+
+function newChatWidget(uid)
+{
+ chatWidgets[uid] = new ChatWidget(uid);
+}
+
+function onMessageReceivedChatWidget(omrcwL)
+{
+ var uid = omrcwL.shift();
+ var msg = omrcwL.shift();
+ chatWidgets[uid].onMessageReceived(msg);
+}
+
+function nudgeChatWidget(uidL)
+{
+ var uid = uidL.shift();
+ chatWidgets[uid].nudge();
+}
// main
function showMainWindow()
{
@@ -300,13 +400,9 @@ function hideLogin()
function signingIn()
{
hideLogin();
-}
-
-// splash screen
-function setImageSplashScreen()
-{
- // TODO
-}
+} // }}}
+// splash screen {{{
+function setImageSplashScreen() {}
function setTextSplashScreen(txt)
{
$("div.splashScreen").text(txt);
@@ -318,104 +414,14 @@ function showSplashScreen()
function hideSplashScreen()
{
$("div.splashScreen").hide("slow");
-}
-
+} // }}}
function myInfoUpdated()
{
// TODO
}
-// contact_list
-var contactList = new ContactList();
-
-function showContactListWindow()
-{
- $("div.contact_list").show("slow");
-}
-
-function hideContactListWindow()
-{
- $("div.contact_list").hide("slow");
-}
-
-function setContactListTitle(title)
-{
- $("div.contact_list div.title").text(title);
-}
-
-function contactListUpdated(groupsL)
-{
- contactList.setGroups($("div.contact_list"), groupsL);
-}
-
-function groupUpdated(groupV)
-{
- var uid = groupV[0];
- var contact_ids = groupV[1];
- var name = groupV[2];
- var group = contactList.getGroup(uid);
- group.setName(name);
- if (contact_ids) {
- var cuids = contact_ids.split(',');
- var clist = [];
- $.each(cuids, function(){
- clist.push(contactList.getContact(cuids.shift()));
- });
- group.setContacts(clist);
- }
-}
-
-function contactUpdated(contactV)
-{
- var uid = contactV[0];
- var name = contactV[1];
- contactList.getContact(uid).setName(name);
-}
-
-// Chat functions
-var chatWindows = {};
-var chatWidgets = {};
-
-function newChatWindow(uid)
-{
- chatWindows[uid] = new ChatWindow(uid);
-}
-
-function addChatWidget(windowUid, widgetUid)
-{
- chatWindows[windowUid].addChatWidget(chatWidgets[widgetUid]);
-}
-
-function showChatWindow(uidL)
-{
- var uid = uidL.shift();
- chatWindows[uid].show();
-}
-
-function hideChatWindow(uidL)
-{
- var uid = uidL.shift();
- chatWindows[uid].hide();
-}
-
-function newChatWidget(uid)
-{
- chatWidgets[uid] = new ChatWidget(uid);
-}
-
-function onMessageReceivedChatWidget(omrcwL)
-{
- var uid = omrcwL.shift();
- var msg = omrcwL.shift();
- chatWidgets[uid].onMessageReceived(msg);
-}
-function nudgeChatWidget(uidL)
-{
- var uid = uidL.shift();
- chatWidgets[uid].nudge();
-}
// Comunication functions
/*
Please sign in to comment.
Something went wrong with that request. Please try again.