merge of '432ae5bfbc553377904f4af62eb75728fdd9ff07'
and 'b5fd6a81fe5f1b221278976163e751f500a6a90c' Monotone-Parent: 432ae5bfbc553377904f4af62eb75728fdd9ff07 Monotone-Parent: b5fd6a81fe5f1b221278976163e751f500a6a90c Monotone-Revision: bd7bfc7a8af12b0b27f7a5b9d7a313a298cd99fb Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-09-11T19:27:11 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
commit
106e818d2e
|
@ -220,7 +220,7 @@
|
|||
{
|
||||
folder = [folders objectAtIndex: i];
|
||||
if ([folder isKindOfClass: [SOGoContactLDAPFolder class]])
|
||||
[sortedFolders insertObject: folder atIndex: 0];
|
||||
[sortedFolders insertObject: folder atIndex: 0];
|
||||
else
|
||||
[sortedFolders addObject: folder];
|
||||
}
|
||||
|
@ -237,9 +237,9 @@
|
|||
mail = [contact objectForKey: @"c_mail"];
|
||||
//NSLog(@" found %@ (%@)", [contact objectForKey: @"displayName"], mail);
|
||||
if ([mail isNotNull]
|
||||
&& [uniqueContacts objectForKey: mail] == nil
|
||||
&& !(excludeGroups && [contact objectForKey: @"isGroup"]))
|
||||
[uniqueContacts setObject: contact forKey: mail];
|
||||
&& [uniqueContacts objectForKey: mail] == nil
|
||||
&& !(excludeGroups && [contact objectForKey: @"isGroup"]))
|
||||
[uniqueContacts setObject: contact forKey: mail];
|
||||
}
|
||||
}
|
||||
if ([uniqueContacts count] > 0)
|
||||
|
|
|
@ -10,198 +10,200 @@ var SOGoAutoCompletionInterface = {
|
|||
delay: 0.750,
|
||||
delayedSearch: false,
|
||||
menu: null,
|
||||
|
||||
bind: function () {
|
||||
this.menu = $('contactsMenu');
|
||||
this.writeAttribute("autocomplete", "off");
|
||||
this.observe("keydown", this.onKeydown.bindAsEventListener(this));
|
||||
this.observe("blur", this.onBlur.bindAsEventListener(this));
|
||||
},
|
||||
onKeydown: function (event) {
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
this.focussed = true;
|
||||
return;
|
||||
}
|
||||
if (event.keyCode == Event.KEY_TAB) {
|
||||
if (this.confirmedValue)
|
||||
this.value = this.confirmedValue;
|
||||
else
|
||||
this.uid = null;
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
}
|
||||
else if (event.keyCode == 0
|
||||
|| event.keyCode == Event.KEY_BACKSPACE
|
||||
|| event.keyCode == 32 // Space
|
||||
|| event.keyCode > 47) {
|
||||
this.confirmedValue = null;
|
||||
this.selectedIndex = -1;
|
||||
if (this.delayedSearch)
|
||||
window.clearTimeout(this.delayedSearch);
|
||||
this.delayedSearch = this.performSearch.delay(this.delay, this);
|
||||
}
|
||||
else if (event.keyCode == Event.KEY_RETURN) {
|
||||
preventDefault(event);
|
||||
if (this.confirmedValue)
|
||||
this.value = this.confirmedValue;
|
||||
$(this).select();
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
this.selectedIndex = -1;
|
||||
}
|
||||
else if (this.menu.getStyle('visibility') == 'visible') {
|
||||
if (event.keyCode == Event.KEY_UP) { // Up arrow
|
||||
if (this.selectedIndex > 0) {
|
||||
var contacts = this.menu.select("li");
|
||||
contacts[this.selectedIndex--].removeClassName("selected");
|
||||
this.value = contacts[this.selectedIndex].readAttribute("address");
|
||||
this.uid = contacts[this.selectedIndex].uid;
|
||||
contacts[this.selectedIndex].addClassName("selected");
|
||||
}
|
||||
}
|
||||
else if (event.keyCode == Event.KEY_DOWN) { // Down arrow
|
||||
var contacts = this.menu.select("li");
|
||||
if (contacts.size() - 1 > this.selectedIndex) {
|
||||
if (this.selectedIndex >= 0)
|
||||
contacts[this.selectedIndex].removeClassName("selected");
|
||||
this.selectedIndex++;
|
||||
this.value = contacts[this.selectedIndex].readAttribute("address");
|
||||
this.uid = contacts[this.selectedIndex].uid;
|
||||
contacts[this.selectedIndex].addClassName("selected");
|
||||
}
|
||||
}
|
||||
}
|
||||
this.menu = $('contactsMenu');
|
||||
this.writeAttribute("autocomplete", "off");
|
||||
this.observe("keydown", this.onKeydown.bindAsEventListener(this));
|
||||
this.observe("blur", this.onBlur.bindAsEventListener(this));
|
||||
},
|
||||
|
||||
onBlur: function (event) {
|
||||
if (this.delayedSearch)
|
||||
window.clearTimeout(this.delayedSearch);
|
||||
if (this.confirmedValue)
|
||||
onKeydown: function (event) {
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
this.focussed = true;
|
||||
return;
|
||||
}
|
||||
if (event.keyCode == Event.KEY_TAB) {
|
||||
if (this.confirmedValue)
|
||||
this.value = this.confirmedValue;
|
||||
else
|
||||
else
|
||||
this.uid = null;
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
}
|
||||
else if (event.keyCode == 0
|
||||
|| event.keyCode == Event.KEY_BACKSPACE
|
||||
|| event.keyCode == 32 // Space
|
||||
|| event.keyCode > 47) {
|
||||
this.confirmedValue = null;
|
||||
this.selectedIndex = -1;
|
||||
if (this.delayedSearch)
|
||||
window.clearTimeout(this.delayedSearch);
|
||||
this.delayedSearch = this.performSearch.delay(this.delay, this);
|
||||
}
|
||||
else if (event.keyCode == Event.KEY_RETURN) {
|
||||
preventDefault(event);
|
||||
if (this.confirmedValue)
|
||||
this.value = this.confirmedValue;
|
||||
$(this).select();
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
this.selectedIndex = -1;
|
||||
}
|
||||
else if (this.menu.getStyle('visibility') == 'visible') {
|
||||
if (event.keyCode == Event.KEY_UP) { // Up arrow
|
||||
if (this.selectedIndex > 0) {
|
||||
var contacts = this.menu.select("li");
|
||||
contacts[this.selectedIndex--].removeClassName("selected");
|
||||
this.value = contacts[this.selectedIndex].readAttribute("address");
|
||||
this.uid = contacts[this.selectedIndex].uid;
|
||||
contacts[this.selectedIndex].addClassName("selected");
|
||||
}
|
||||
}
|
||||
else if (event.keyCode == Event.KEY_DOWN) { // Down arrow
|
||||
var contacts = this.menu.select("li");
|
||||
if (contacts.size() - 1 > this.selectedIndex) {
|
||||
if (this.selectedIndex >= 0)
|
||||
contacts[this.selectedIndex].removeClassName("selected");
|
||||
this.selectedIndex++;
|
||||
this.value = contacts[this.selectedIndex].readAttribute("address");
|
||||
this.uid = contacts[this.selectedIndex].uid;
|
||||
contacts[this.selectedIndex].addClassName("selected");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onBlur: function (event) {
|
||||
if (this.delayedSearch)
|
||||
window.clearTimeout(this.delayedSearch);
|
||||
if (this.confirmedValue)
|
||||
this.value = this.confirmedValue;
|
||||
else
|
||||
this.uid = null;
|
||||
},
|
||||
|
||||
performSearch: function (input) {
|
||||
// Perform address completion
|
||||
// Perform address completion
|
||||
if (document.contactLookupAjaxRequest) {
|
||||
// Abort any pending request
|
||||
document.contactLookupAjaxRequest.aborted = true;
|
||||
document.contactLookupAjaxRequest.abort();
|
||||
// Abort any pending request
|
||||
document.contactLookupAjaxRequest.aborted = true;
|
||||
document.contactLookupAjaxRequest.abort();
|
||||
}
|
||||
if (input.value.trim().length > 2) {
|
||||
var urlstr = (UserFolderURL + "Contacts/allContactSearch?search="
|
||||
var urlstr = (UserFolderURL + "Contacts/allContactSearch?search="
|
||||
+ encodeURIComponent(input.value));
|
||||
if (input.excludeGroups)
|
||||
urlstr += "&excludeGroups=1";
|
||||
if (input.animationParent)
|
||||
startAnimation(input.animationParent);
|
||||
if (input.excludeGroups)
|
||||
urlstr += "&excludeGroups=1";
|
||||
if (input.animationParent)
|
||||
startAnimation(input.animationParent);
|
||||
document.contactLookupAjaxRequest =
|
||||
triggerAjaxRequest(urlstr, input.performSearchCallback.bind(input), input);
|
||||
triggerAjaxRequest(urlstr, input.performSearchCallback.bind(input), input);
|
||||
}
|
||||
else {
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
hideMenu(document.currentPopupMenu);
|
||||
}
|
||||
},
|
||||
|
||||
performSearchCallback: function (http) {
|
||||
if (http.readyState == 4) {
|
||||
var list = this.menu.down("ul");
|
||||
if (http.readyState == 4) {
|
||||
var list = this.menu.down("ul");
|
||||
|
||||
var input = http.callbackData;
|
||||
|
||||
if (http.status == 200) {
|
||||
var start = input.value.length;
|
||||
var data = http.responseText.evalJSON(true);
|
||||
var start = input.value.length;
|
||||
var data = http.responseText.evalJSON(true);
|
||||
|
||||
if (data.contacts.length > 1) {
|
||||
if (data.contacts.length > 1) {
|
||||
list.select("li").each(function(item) {
|
||||
item.stopObserving("mousedown");
|
||||
item.remove();
|
||||
});
|
||||
item.stopObserving("mousedown");
|
||||
item.remove();
|
||||
});
|
||||
|
||||
// Populate popup menu
|
||||
for (var i = 0; i < data.contacts.length; i++) {
|
||||
var contact = data.contacts[i];
|
||||
var completeEmail = contact["c_cn"] + " <" + contact["c_mail"] + ">";
|
||||
var node = new Element('li', { 'address': completeEmail });
|
||||
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.uid = contact["c_mail"];
|
||||
node.appendChild(document.createTextNode(matchBefore));
|
||||
node.appendChild(new Element('strong').update(matchText));
|
||||
node.appendChild(document.createTextNode(matchAfter));
|
||||
if (contact["contactInfo"])
|
||||
node.appendChild(document.createTextNode(" (" + contact["contactInfo"] + ")"));
|
||||
$(node).observe("mousedown", this.onAddressResultClick.bindAsEventListener(this));
|
||||
var contact = data.contacts[i];
|
||||
var completeEmail = contact["c_cn"] + " <" + contact["c_mail"] + ">";
|
||||
var node = new Element('li', { 'address': completeEmail });
|
||||
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.uid = contact["c_mail"];
|
||||
node.appendChild(document.createTextNode(matchBefore));
|
||||
node.appendChild(new Element('strong').update(matchText));
|
||||
node.appendChild(document.createTextNode(matchAfter));
|
||||
if (contact["contactInfo"])
|
||||
node.appendChild(document.createTextNode(" (" + contact["contactInfo"] + ")"));
|
||||
$(node).observe("mousedown", this.onAddressResultClick.bindAsEventListener(this));
|
||||
}
|
||||
|
||||
// Show popup menu
|
||||
var offsetScroll = Element.cumulativeScrollOffset(input);
|
||||
var offset = Element.positionedOffset(input);
|
||||
if (offset.top == 0)
|
||||
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];
|
||||
var nodeHeight = node.getHeight();
|
||||
|
||||
if ((data.contacts.length * nodeHeight) > heightDiff)
|
||||
// Limit the size of the popup to the window height, minus 12 pixels
|
||||
height = parseInt(heightDiff/nodeHeight) * nodeHeight - 12 + 'px';
|
||||
// Limit the size of the popup to the window height, minus 12 pixels
|
||||
height = parseInt(heightDiff/nodeHeight) * nodeHeight - 12 + 'px';
|
||||
|
||||
this.menu.setStyle({ top: top + "px",
|
||||
left: offset[0] + "px",
|
||||
height: height,
|
||||
visibility: "visible" });
|
||||
left: offset[0] + "px",
|
||||
height: height,
|
||||
visibility: "visible" });
|
||||
this.menu.scrollTop = 0;
|
||||
|
||||
document.currentPopupMenu = this.menu;
|
||||
$(document.body).stopObserving("click");
|
||||
$(document.body).stopObserving("click");
|
||||
$(document.body).observe("click", onBodyClickMenuHandler);
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
hideMenu(document.currentPopupMenu);
|
||||
|
||||
if (data.contacts.length == 1) {
|
||||
// Single result
|
||||
var contact = data.contacts[0];
|
||||
input.uid = contact[this.uidField];
|
||||
var completeEmail = contact["c_cn"] + " <" + contact["c_mail"] + ">";
|
||||
if (contact["c_cn"].substring(0, input.value.length).toUpperCase()
|
||||
// Single result
|
||||
var contact = data.contacts[0];
|
||||
input.uid = contact[this.uidField];
|
||||
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;
|
||||
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);
|
||||
var end = input.value.length;
|
||||
$(input).selectText(start, end);
|
||||
|
||||
this.selectedIndex = -1;
|
||||
this.selectedIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
if (document.currentPopupMenu)
|
||||
hideMenu(document.currentPopupMenu);
|
||||
document.contactLookupAjaxRequest = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onAddressResultClick: function(event) {
|
||||
var e = Event.element(event);
|
||||
if (e.tagName != 'LI')
|
||||
e = e.up('LI');
|
||||
if (e) {
|
||||
var e = Event.element(event);
|
||||
if (e.tagName != 'LI')
|
||||
e = e.up('LI');
|
||||
if (e) {
|
||||
this.uid = e.uid;
|
||||
this.value = e.readAttribute("address");
|
||||
this.confirmedValue = this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue