mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-07 20:45:28 +00:00
See ChangeLog
Monotone-Parent: c66c023a1a42d53c473a7338a49a9b456d889ed9 Monotone-Revision: 62137d02651888053a8bd415f6e6f5aa79e44cf4 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2009-10-28T17:48:22 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,18 +1,27 @@
|
||||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
|
||||
// The popup menu with id "contactsMenu" must exist before
|
||||
// using this interface.
|
||||
// NOTE: The popup menu with id "contactsMenu" must exist before
|
||||
// using this interface.
|
||||
//
|
||||
// This interface fires two events:
|
||||
// - autocompletion:changed : fired when a new contact is selected
|
||||
// - autocompletion:changedlist : fired when a new list is selected
|
||||
//
|
||||
var SOGoAutoCompletionInterface = {
|
||||
|
||||
// Attributes that could be changed from the object
|
||||
// inheriting the inteface
|
||||
uidField: "c_name",
|
||||
addressBook: null,
|
||||
excludeGroups: false,
|
||||
excludeLists: false,
|
||||
|
||||
// Internal attributes
|
||||
animationParent: null,
|
||||
selectedIndex: -1,
|
||||
delay: 0.750,
|
||||
delayedSearch: false,
|
||||
menu: null,
|
||||
baseUrl: null,
|
||||
onListAdded: null,
|
||||
endEditable: null,
|
||||
|
||||
bind: function () {
|
||||
this.menu = $('contactsMenu');
|
||||
@@ -30,13 +39,15 @@ var SOGoAutoCompletionInterface = {
|
||||
if (this.confirmedValue)
|
||||
this.value = this.confirmedValue;
|
||||
else
|
||||
this.uid = null;
|
||||
if (document.currentPopupMenu)
|
||||
this.writeAttribute("uid", null);
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
if (this.endEditable)
|
||||
this.endEditable ();
|
||||
if (this.onListAdded)
|
||||
this.onListAdded ();
|
||||
if (this.readAttribute("container")) {
|
||||
this.confirmedValue = null;
|
||||
this.fire("autocompletion:changedlist", this.readAttribute("container"));
|
||||
}
|
||||
else
|
||||
this.fire("autocompletion:changed");
|
||||
}
|
||||
else if (event.keyCode == 0
|
||||
|| event.keyCode == Event.KEY_BACKSPACE
|
||||
@@ -52,14 +63,18 @@ var SOGoAutoCompletionInterface = {
|
||||
preventDefault(event);
|
||||
if (this.confirmedValue)
|
||||
this.value = this.confirmedValue;
|
||||
else
|
||||
this.writeAttribute("uid", null);
|
||||
$(this).select();
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
this.selectedIndex = -1;
|
||||
if (this.endEditable)
|
||||
this.endEditable ();
|
||||
if (this.onListAdded)
|
||||
this.onListAdded ();
|
||||
if (this.readAttribute("container")) {
|
||||
this.confirmedValue = null;
|
||||
this.fire("autocompletion:changedlist", this.readAttribute("container"));
|
||||
}
|
||||
else
|
||||
this.fire("autocompletion:changed");
|
||||
}
|
||||
else if (this.menu.getStyle('visibility') == 'visible') {
|
||||
if (event.keyCode == Event.KEY_UP) { // Up arrow
|
||||
@@ -67,13 +82,12 @@ var SOGoAutoCompletionInterface = {
|
||||
var contacts = this.menu.select("li");
|
||||
contacts[this.selectedIndex--].removeClassName("selected");
|
||||
this.value = contacts[this.selectedIndex].readAttribute("address");
|
||||
this.uid = contacts[this.selectedIndex].uid;
|
||||
this.confirmedValue = this.value;
|
||||
this.writeAttribute("uid", contacts[this.selectedIndex].readAttribute("uid"));
|
||||
contacts[this.selectedIndex].addClassName("selected");
|
||||
var e = contacts[this.selectedIndex];
|
||||
this.writeAttribute("card", e.readAttribute("card"));
|
||||
this.writeAttribute("mail", e.readAttribute("mail"));
|
||||
this.writeAttribute("uname", e.readAttribute("uname"));
|
||||
this.writeAttribute("container", e.readAttribute("container"));
|
||||
var container = contacts[this.selectedIndex].readAttribute("container");
|
||||
if (container)
|
||||
this.writeAttribute("container", container);
|
||||
}
|
||||
}
|
||||
else if (event.keyCode == Event.KEY_DOWN) { // Down arrow
|
||||
@@ -83,13 +97,12 @@ var SOGoAutoCompletionInterface = {
|
||||
contacts[this.selectedIndex].removeClassName("selected");
|
||||
this.selectedIndex++;
|
||||
this.value = contacts[this.selectedIndex].readAttribute("address");
|
||||
this.uid = contacts[this.selectedIndex].uid;
|
||||
this.confirmedValue = this.value;
|
||||
this.writeAttribute("uid", contacts[this.selectedIndex].readAttribute("uid"));
|
||||
contacts[this.selectedIndex].addClassName("selected");
|
||||
var e = contacts[this.selectedIndex];
|
||||
this.writeAttribute("card", e.readAttribute("card"));
|
||||
this.writeAttribute("mail", e.readAttribute("mail"));
|
||||
this.writeAttribute("uname", e.readAttribute("uname"));
|
||||
this.writeAttribute("container", e.readAttribute("container"));
|
||||
var container = contacts[this.selectedIndex].readAttribute("container");
|
||||
if (container)
|
||||
this.writeAttribute("container", container);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,10 +111,13 @@ var SOGoAutoCompletionInterface = {
|
||||
onBlur: function (event) {
|
||||
if (this.delayedSearch)
|
||||
window.clearTimeout(this.delayedSearch);
|
||||
if (this.confirmedValue)
|
||||
if (this.confirmedValue) {
|
||||
this.value = this.confirmedValue;
|
||||
if (this.readAttribute("container"))
|
||||
this.fire("autocompletion:changedlist", this.readAttribute("container"));
|
||||
}
|
||||
else
|
||||
this.uid = null;
|
||||
this.writeAttribute("uid", null);
|
||||
},
|
||||
|
||||
performSearch: function (input) {
|
||||
@@ -112,10 +128,12 @@ var SOGoAutoCompletionInterface = {
|
||||
document.contactLookupAjaxRequest.abort();
|
||||
}
|
||||
if (input.value.trim().length > 2) {
|
||||
var urlstr = (UserFolderURL + "Contacts/allContactSearch?search="
|
||||
+ encodeURIComponent(input.value));
|
||||
if (input.baseUrl)
|
||||
urlstr = input.baseUrl + encodeURIComponent(input.value);
|
||||
var urlstr = UserFolderURL + "Contacts/";
|
||||
if (input.addressBook)
|
||||
urlstr += input.addressBook + "/contact";
|
||||
else
|
||||
urlstr += "allContact";
|
||||
urlstr += "Search?search=" + encodeURIComponent(input.value);
|
||||
if (input.excludeGroups)
|
||||
urlstr += "&excludeGroups=1";
|
||||
if (input.excludeLists)
|
||||
@@ -153,20 +171,15 @@ var SOGoAutoCompletionInterface = {
|
||||
var completeEmail = contact["c_cn"];
|
||||
if (contact["c_mail"])
|
||||
completeEmail += " <" + contact["c_mail"] + ">";
|
||||
var node = new Element('li', { 'address': completeEmail });
|
||||
var node = new Element('li', { 'address': completeEmail,
|
||||
'uid': contact[this.uidField] });
|
||||
var matchPosition = completeEmail.toLowerCase().indexOf(data.searchText.toLowerCase());
|
||||
var matchBefore = completeEmail.substring(0, matchPosition);
|
||||
var matchText = completeEmail.substring(matchPosition, matchPosition + data.searchText.length);
|
||||
var matchAfter = completeEmail.substring(matchPosition + data.searchText.length);
|
||||
list.appendChild(node);
|
||||
node.writeAttribute ("card", contact['c_name']);
|
||||
node.writeAttribute ("uid", contact['c_mail']);
|
||||
if (contact['c_name'].endsWith (".vlf")) {
|
||||
node.writeAttribute("container", contact['container']);
|
||||
}
|
||||
else {
|
||||
node.writeAttribute("mail", contact['c_mail']);
|
||||
node.writeAttribute("uname", contact['c_cn']);
|
||||
// Keep track of list containers
|
||||
node.writeAttribute("container", contact['container']);
|
||||
}
|
||||
node.appendChild(document.createTextNode(matchBefore));
|
||||
@@ -179,7 +192,9 @@ var SOGoAutoCompletionInterface = {
|
||||
|
||||
// Show popup menu
|
||||
var offsetScroll = Element.cumulativeScrollOffset(input);
|
||||
var offset = Element.cumulativeOffset(input);
|
||||
var offset = Element.positionedOffset(input);
|
||||
if (offset.top == 0)
|
||||
offset = Element.cumulativeOffset(input);
|
||||
var top = offset[1] - offsetScroll[1] + node.offsetHeight + 3;
|
||||
var height = 'auto';
|
||||
var heightDiff = window.height() - offset[1];
|
||||
@@ -199,37 +214,32 @@ var SOGoAutoCompletionInterface = {
|
||||
$(document.body).stopObserving("click");
|
||||
$(document.body).observe("click", onBodyClickMenuHandler);
|
||||
}
|
||||
else { // Only one result
|
||||
else {
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
|
||||
if (data.contacts.length == 1) {
|
||||
// Single result
|
||||
var contact = data.contacts[0];
|
||||
input.uid = contact[this.uidField];
|
||||
if (contact['c_name'].endsWith (".vlf") && this.onListAdded) {
|
||||
input.writeAttribute("uid", contact[this.uidField]);
|
||||
if (contact['c_name'].endsWith(".vlf")) {
|
||||
this.writeAttribute("container", contact['container']);
|
||||
this.writeAttribute("card", contact['c_name']);
|
||||
this.onListAdded ();
|
||||
}
|
||||
else {
|
||||
input.writeAttribute("card", contact['c_name']);
|
||||
input.writeAttribute("mail", contact['c_mail']);
|
||||
input.writeAttribute("uname", contact['c_cn']);
|
||||
var completeEmail = contact["c_cn"] + " <" + contact["c_mail"] + ">";
|
||||
if (contact["c_cn"].substring(0, input.value.length).toUpperCase()
|
||||
== input.value.toUpperCase())
|
||||
input.value = completeEmail;
|
||||
else
|
||||
// The result matches email address, not user name
|
||||
input.value += ' >> ' + completeEmail;
|
||||
input.confirmedValue = completeEmail;
|
||||
|
||||
var end = input.value.length;
|
||||
$(input).selectText(start, end);
|
||||
|
||||
this.selectedIndex = -1;
|
||||
}
|
||||
var completeEmail = contact["c_cn"];
|
||||
if (contact["c_mail"])
|
||||
completeEmail += " <" + contact["c_mail"] + ">";
|
||||
if (contact["c_cn"].substring(0, input.value.length).toUpperCase()
|
||||
== input.value.toUpperCase())
|
||||
input.value = completeEmail;
|
||||
else
|
||||
// The result matches email address, not user name
|
||||
input.value += ' >> ' + completeEmail;
|
||||
input.confirmedValue = completeEmail;
|
||||
|
||||
var end = input.value.length;
|
||||
$(input).selectText(start, end);
|
||||
|
||||
this.selectedIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,21 +255,14 @@ var SOGoAutoCompletionInterface = {
|
||||
if (e.tagName != 'LI')
|
||||
e = e.up('LI');
|
||||
if (e) {
|
||||
var card = e.readAttribute("card");
|
||||
this.writeAttribute("card", card);
|
||||
if (card.endsWith (".vlf") && this.onListAdded) {
|
||||
this.writeAttribute("container", e.readAttribute("container"));
|
||||
this.onListAdded ();
|
||||
}
|
||||
else {
|
||||
this.writeAttribute("mail", e.readAttribute("mail"));
|
||||
this.writeAttribute("uname", e.readAttribute("uname"));
|
||||
}
|
||||
this.writeAttribute("uid", e.readAttribute("uid"));
|
||||
this.value = e.readAttribute("address");
|
||||
this.confirmedValue = this.value;
|
||||
if (this.endEditable)
|
||||
this.endEditable ();
|
||||
this.writeAttribute("uid", e.readAttribute("uid"));
|
||||
if (e.readAttribute("container"))
|
||||
this.fire("autocompletion:changedlist", e.readAttribute("container"));
|
||||
else {
|
||||
this.confirmedValue = this.value;
|
||||
this.fire("autocompletion:changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user