[dev] [imp-patch] prevent duplicate contacts from addressbook
Francois Marier
francois at nit.ca
Tue Jul 27 13:51:37 PDT 2004
Hi,
Here's a small Javascript patch for IMP. The annoyance it fixes is
the following:
After having clicked on the "Addressbook" button in the Compose
window, it is possible to add several times the same contact to the
listbox on the right.
This patches only allows a contact to move to the right listbox if it
is not already in there. Thus clicking repeatedly on the "To >>"
button will not fill the right listbox with useless entries.
Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/imp/templates/contacts/contacts.inc imp/templates/contacts/contacts.inc
--- ../build/imp/templates/contacts/contacts.inc Sat Mar 20 16:33:31 2004
+++ imp/templates/contacts/contacts.inc Sat Jul 10 18:57:08 2004
@@ -49,6 +49,17 @@ function passAddresses() {
window.document.contacts.action = action;
}
+function sameOption(f, item, itemj)
+{
+ var text = f + ": " + item.text;
+ var value = f + ": " + item.value;
+ var textj = itemj.text;
+ var valuej = itemj.value;
+
+ return ((text == textj) || (unescape(text) == unescape(textj))) &&
+ ((value == valuej) || (unescape(value) == unescape(valuej)));
+}
+
function addAddress(f)
{
var s = window.document.contacts.search_results;
@@ -62,6 +73,12 @@ function addAddress(f)
var item = s.options[i];
if (item.value == "") { continue; }
if (item.selected) {
+ for (var j = 0; j < d.length; j++) {
+ var itemj = d.options[j];
+ if (sameOption(f, item, itemj)) {
+ return false;
+ }
+ }
d.options[d.length] = new Option(f + ': ' + item.text, f + ': ' + item.value);
}
}
More information about the dev
mailing list