forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contacts: Add vcard import to interface.html
- Loading branch information
Showing
2 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ | |
<link rel="stylesheet" href="../../css/spectre-icons.min.css"> | ||
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css"> | ||
<script type="module"> | ||
import vcf from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm' | ||
window.vcf = vcf; | ||
</script> | ||
|
||
<style type="text/css"> | ||
html, body { height: 100% } | ||
|
@@ -36,16 +40,6 @@ <h1>Contacts v.2</h1> | |
<span id="status"></span> | ||
<span id="routestatus"></span> | ||
</div> | ||
<div> | ||
<ul class="tab tab-block"> | ||
<li class="tab-item active" id="tabitem-map"> | ||
<a href="#">Map</a> | ||
</li> | ||
<li class="tab-item" id="tabitem-list"> | ||
<a href="#">List</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<div style="flex: 1"> | ||
<div id="tab-list"> | ||
<table class="table"> | ||
|
@@ -75,6 +69,17 @@ <h4>Add a new contact</h4> | |
</div> | ||
</div> | ||
</form> | ||
<div class="divider"></div> | ||
<div class="form-horizontal"> | ||
<div class="form-group"> | ||
<div class="col-5 col-xs-12"> | ||
<label class="form-label" for="fileinput">Add from vCard file</label> | ||
</div> | ||
<div class="col-7 col-xs-12"> | ||
<input id="fileinput" class="form-input" type="file" onchange="readFile(this)" accept=".vcf" multiple/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -99,12 +104,6 @@ <h4>Add a new contact</h4> | |
|
||
/*** contacts ***/ | ||
|
||
function addContact(arr, lat, lon, name) { | ||
arr.push({number:lat, name:name}); | ||
renderAllContacts(); | ||
dirty(); | ||
} | ||
|
||
function deleteContact(arr, i) { | ||
arr.splice(i, 1); | ||
renderAllContacts(); | ||
|
@@ -201,6 +200,28 @@ <h4>Add a new contact</h4> | |
renderContactsList(); | ||
} | ||
|
||
function readFile(input) { | ||
for(let i=0; i<input.files.length; i++) { | ||
const reader = new FileReader(); | ||
reader.addEventListener("load", () => { | ||
const vcards = vcf.parse(reader.result); | ||
vcards.forEach(vcard => { | ||
const name = vcard.get('fn')?.valueOf() || vcard.get('n')?.valueOf(); | ||
const tels = Array.isArray(vcard.get('tel')) ? vcard.get('tel') : [vcard.get('tel')]; | ||
tels.forEach(tel => { | ||
if (tel) { | ||
const number = tel.valueOf(); | ||
contacts.push({name: name, number: number}); | ||
} | ||
}); | ||
}); | ||
renderAllContacts(); | ||
dirty(); | ||
}, false); | ||
reader.readAsText(input.files[i], "UTF-8"); | ||
} | ||
} | ||
|
||
// ========================================================================== UPLOAD/DOWNLOAD | ||
|
||
function downloadJSONfile(fileid, callback) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters