aboutsummaryrefslogtreecommitdiffstats
path: root/importAddrBook.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2013-05-22 19:23:18 +0200
committerMatěj Cepl <mcepl@redhat.com>2013-05-22 22:48:51 +0200
commitbb2685eed25e1f347188c6dfc32d5756adf3d006 (patch)
tree457d1ec0c378a2eed48655705581c3c888c5e6b4 /importAddrBook.js
parent06f4854c6b527da1f5d07b49e3eb5b1d2d4f2f49 (diff)
downloadimportLDIF-bb2685eed25e1f347188c6dfc32d5756adf3d006.tar.gz
Clean up metadata and small UI improvements.v2
* rename to 'Import LDIF' * change icon to the Crystal text/x-vcard one * make it clear when the download finishes, and restore the URL form * don't try to import empty LDIF file * remove .appcache … we don’t use it for the packaged app
Diffstat (limited to 'importAddrBook.js')
-rw-r--r--importAddrBook.js33
1 files changed, 28 insertions, 5 deletions
diff --git a/importAddrBook.js b/importAddrBook.js
index 9a0e6f4..75c45df 100644
--- a/importAddrBook.js
+++ b/importAddrBook.js
@@ -210,6 +210,7 @@
return null;
}
+
/**
* Not used presently and not debugged.
*/
@@ -252,6 +253,14 @@
}
}
+ function restoreURLForm(url) {
+ document.getElementById("progress-div").style.display = "none";
+ document.getElementById("URL-form").style.display = "block";
+ if (url !== undefined) {
+ document.getElementsByName("URL")[0].value = url;
+ }
+ }
+
function insertData(ldifText) {
var progressEl = document.querySelector("#progress-div progress");
@@ -283,21 +292,27 @@
sav_req.onsuccess = function() {
progressEl.value += 1;
- console.log("Contact added:\n" + add_contact.id);
+ if (progressEl.value >= records.length) {
+ window.alert("All contacts have been imported!");
+ restoreURLForm();
+ }
};
sav_req.onerror = function() {
- console.error("Cannot save record " + add_contact.id);
+ console.error("Cannot save record " + add_contact.id +
+ "\n" + rec.toSource());
};
});
};
}
- window.onload = function() {
+
+ window.onload = function() {
document.body.addEventListener("submit",
function(evt) {
+
var URL = document.getElementsByName("URL")[0].value;
var progressForm = document.getElementById("progress-div");
@@ -316,14 +331,22 @@
};
req.onload = function() {
- insertData(req.responseText);
+ var inText = req.responseText;
+ if (inText.length > 0) {
+ insertData(inText);
+ }
+ };
+
+ req.onerror = function() {
+ window.alert("Cannot load " + URL + "!");
+ restoreURLForm(URL);
};
+
req.send();
evt.stopPropagation();
evt.preventDefault();
}, false);
-
};
}());