[Bedework-commit] carddav r178 - in
trunk/clients/javascript/bwAddrbookClient: . config/lang resources
svnadmin at bedework.org
svnadmin at bedework.org
Tue Oct 26 17:13:03 EDT 2010
Author: johnsa
Date: 2010-10-26 17:13:03 -0400 (Tue, 26 Oct 2010)
New Revision: 178
Modified:
trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js
trunk/clients/javascript/bwAddrbookClient/index.html
trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css
trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js
Log:
javascript client: crud operations on location vcard types
Modified: trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js 2010-10-26 18:53:48 UTC (rev 177)
+++ trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js 2010-10-26 21:13:03 UTC (rev 178)
@@ -45,6 +45,8 @@
// form titles and submit buttons
var bwAbDispAddContact = "Add Contact";
var bwAbDispUpdateContact = "Update Contact";
+var bwAbDispAddLocation = "Add Location";
+var bwAbDispUpdateLocation = "Update Location";
// error and status messages
var bwAbDispBookType = "Book type";
@@ -58,10 +60,10 @@
// add/update messages
var bwAbDispSuccessTitle = "Success";
-var bwAbDispSuccessfulAdd = "Contact was successfully added.";
-var bwAbDispSuccessfulUpdate = "Contact was successfully updated.";
+var bwAbDispSuccessfulAdd = "Entry was successfully added.";
+var bwAbDispSuccessfulUpdate = "Entry was successfully updated.";
// delete
var bwAbDispDelete = "Delete";
-var bwAbDispDeleteConfirmTitle = "Delete Contact";
-var bwAbDispDeleteConfirm = "You wish to delete this contact?\n(This action cannot be undone.)";
\ No newline at end of file
+var bwAbDispDeleteConfirmTitle = "Delete Entry";
+var bwAbDispDeleteConfirm = "You wish to delete this entry?\n(This action cannot be undone.)";
\ No newline at end of file
Modified: trunk/clients/javascript/bwAddrbookClient/index.html
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/index.html 2010-10-26 18:53:48 UTC (rev 177)
+++ trunk/clients/javascript/bwAddrbookClient/index.html 2010-10-26 21:13:03 UTC (rev 178)
@@ -117,7 +117,7 @@
</li>
<li id="bw-modContact" class="content-block invisible">
<h3>Add Contact</h3>
- <form id="addForm" action="#add" method="post">
+ <form id="contactForm" action="#add" method="post">
<fieldset>
<legend>Name</legend>
<div class="bwFormData">
@@ -233,26 +233,122 @@
<label class="bwField" for="NOTE">Note:</label>
<div class="bwValue"><textarea cols="47" rows="4" id="NOTE"></textarea></div>
-
</div>
</fieldset>
<div class="submitBlock">
<button id="submitContact" class="add" type="button">Add Contact</button>
+ <button id="cancelContact" class="cancel" type="button">Cancel</button>
</div>
</form>
</li>
<li id="bw-details" class="invisible content-block">
<div class="bwActionButtons">
- <button id="editContact" type="button">edit</button>
- <button id="deleteContact" type="button">delete</button>
+ <button id="editEntry" class="contact" type="button">edit</button>
+ <button id="deleteEntry" type="button">delete</button>
</div>
<div id="bwAddrBookOutputDetails"></div>
+ <button id="backToList" type="button">return to list</button>
</li>
<li id="bw-modGroup" class="invisible content-block">
<h3>Add Group</h3>
</li>
<li id="bw-modLocation" class="invisible content-block">
<h3>Add Location</h3>
+ <form id="locationForm" action="#add" method="post">
+ <fieldset>
+ <legend>Name</legend>
+ <div class="bwFormData">
+
+ <label class="bwField" for="LOCATION-NAME">Name:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-NAME"/></div>
+
+ <label class="bwField" for="LOCATION-ORG">Organization:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-ORG"/></div>
+
+ <label class="bwField" for="LOCATION-NICKNAME">Nickname:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-NICKNAME"/></div>
+
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>Address</legend>
+ <div class="bwFormData">
+ <div class="bwAddrBlock">
+ <label class="bwField" for="LOCATION-EXTADDR">Room/Suite:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-EXTADDR"/></div>
+ <label class="bwField" for="LOCATION-STREET">Street:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-STREET"/></div>
+
+ <label class="bwField" for="LOCATION-CITY">City:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-CITY"/></div>
+
+ <label class="bwField" for="LOCATION-STATE">State/Province:</label>
+ <div class="bwValue">
+ <input type="text" size="20" value="" id="LOCATION-STATE"/>
+ <label class="bwInternalField" for="LOCATION-POSTAL">Postal Code:</label>
+ <input type="text" size="20" value="" id="LOCATION-POSTAL"/>
+ </div>
+
+ <label class="bwField" for="LOCATION-COUNTRY">Country:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-COUNTRY"/></div>
+
+ <label class="bwField" for="LOCATION-GEO">GEO:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-GEO" disabled="disabled"/></div>
+ <div class="bwHelpLink">
+ ?
+ <div class="bwHelp">
+ Geographic coordinates<br/>
+ Example: 47.251056,-68.594527<br/>
+ (unimeplemented)
+ </div>
+ </div>
+
+ <br class="clear"/>
+ </div>
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>Contact information</legend>
+ <div class="bwFormData">
+
+ <label class="bwField" for="LOCATION-EMAIL">Email:</label>
+ <div class="bwValue">
+ <input type="text" size="60" value="" id="LOCATION-EMAIL"/>
+ </div>
+
+ <label class="bwField" for="LOCATION-PHONE">Phone:</label>
+ <div class="bwValue">
+ <select id="LOCATION-TELTYPE">
+ <option value="voice">voice</option>
+ <option value="cell">mobile</option>
+ <option value="fax">fax</option>
+ <option value="text">text</option>
+ <option value="pager">pager</option>
+ </select>
+ <input type="text" size="30" value="" id="LOCATION-PHONE"/>
+ </div>
+
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>Details</legend>
+ <div class="bwFormData">
+
+ <label class="bwField" for="LOCATION-WEBPAGE">Webpage:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-WEBPAGE"/></div>
+ <label class="bwField" for="LOCATION-PHOTOURL">Photo URL:</label>
+ <div class="bwValue"><input type="text" size="60" value="" id="LOCATION-PHOTOURL" disabled="disabled"/></div>
+ <label class="bwField" for="LOCATION-NOTE">Note:</label>
+ <div class="bwValue"><textarea cols="47" rows="4" id="LOCATION-NOTE"></textarea></div>
+
+
+ </div>
+ </fieldset>
+ <div class="submitBlock">
+ <button id="submitLocation" class="add" type="button">Add Location</button>
+ <button id="cancelLocation" class="cancel" type="button">Cancel</button>
+ </div>
+ </form>
</li>
</ul>
</div>
Modified: trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css 2010-10-26 18:53:48 UTC (rev 177)
+++ trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css 2010-10-26 21:13:03 UTC (rev 178)
@@ -227,10 +227,19 @@
#bwDetailsTable tr.newGrouping td {
padding-top: 1em;
}
-#bwDetailsTable a {
- color: blue;
+#bwDetailsTable a,
+.bwAddrBookTable a {
+ color: #55f;
background-color: transparent;
}
+#bwDetailsTable a:hover,
+.bwAddrBookTable a:hover {
+ color: #11f;
+ background-color: transparent;
+}
+#backToList {
+ margin-top: 3em;
+}
.bwActionButtons {
float: right;
}
@@ -272,6 +281,14 @@
color: #99e;
background-color: white;
}
+input:focus,
+textarea:focus {
+ background-color: #ffe !important;
+ color: black !important;
+}
+button {
+ cursor: pointer;
+}
.bwFormData {
margin: 1em;
}
Modified: trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js 2010-10-26 18:53:48 UTC (rev 177)
+++ trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js 2010-10-26 21:13:03 UTC (rev 178)
@@ -33,7 +33,6 @@
this.books = new Array(); // our address books, loaded on init
this.userid = ""; // our default personal user, loaded on init
this.defPersBookUrl = ""; // URL of our default personal book, built at init
- this.kind = "individual"; // the vcard KIND of the contact we are adding or modifying
this.creating = true; // are we creating or editing an item?
this.book; // the currently selected book
this.card; // the currently selected card
@@ -297,6 +296,10 @@
};
+ // *********************
+ // CONTACT FORM HANDLING
+ // *********************
+
this.addContact = function() {
// For now, we'll assume there is only one book to which we can write.
// In the future, we'll want to check to see if there is more than
@@ -320,7 +323,7 @@
vcData += "UID:" + newUUID + "\n";
vcData += "FN:" + $("#FIRSTNAME").val() + " " + $("#LASTNAME").val() + "\n";
vcData += "N:" + $("#LASTNAME").val() + ";" + $("#FIRSTNAME").val() + ";;;\n";
- vcData += "KIND:" + bwAddressBook.kind + "\n";
+ vcData += "KIND:individual\n";
vcData += "ORG:" + $("#ORG").val() + ";;\n";
vcData += "TITLE:" + $("#TITLE").val() + "\n";
vcData += "NICKNAME:" + $("#NICKNAME").val() + "\n";
@@ -349,7 +352,7 @@
success: function(responseData, status){
var serverMsg = "\n" + status + ": " + responseData;
showMessage(bwAbDispSuccessTitle,bwAbDispSuccessfulAdd + serverMsg,true);
- clearFields("#addForm");
+ clearFields("#contactForm");
window.location.reload(); // this is temporary - for now, just re-fetch the data from the server to redisplay the cards.
},
error: function(msg) {
@@ -378,7 +381,7 @@
vcData += "UID:" + curCard.UID[0].value + "\n";
vcData += "FN:" + $("#FIRSTNAME").val() + " " + $("#LASTNAME").val() + "\n";
vcData += "N:" + $("#LASTNAME").val() + ";" + $("#FIRSTNAME").val() + ";;;\n";
- vcData += "KIND:" + bwAddressBook.kind + "\n";
+ vcData += "KIND:individual\n";
vcData += "ORG:" + $("#ORG").val() + ";;\n";
vcData += "TITLE:" + $("#TITLE").val() + "\n";
vcData += "NICKNAME:" + $("#NICKNAME").val() + "\n";
@@ -408,7 +411,7 @@
success: function(responseData, status){
var serverMsg = "\n" + status + ": " + responseData;
showMessage(bwAbDispSuccessTitle,bwAbDispSuccessfulUpdate + serverMsg,true);
- clearFields("#addForm");
+ clearFields("#contactForm");
window.location.reload(); // this is temporary - for now, just re-fetch the data from the server to redisplay the cards.
},
@@ -418,7 +421,141 @@
}
});
};
+
+ // *******************
+ // GROUP FORM HANDLING
+ // *******************
+
+ // **********************
+ // LOCATION FORM HANDLING
+ // **********************
+
+ this.addLocation = function() {
+ // For now, we'll assume there is only one book to which we can write.
+ // In the future, we'll want to check to see if there is more than
+ // one personal book, and check which is selected.
+ var addrBookUrl = bwAddressBook.defPersBookUrl;
+
+ // Create the UUID
+ var newUUID = "BwABC-" + Math.uuid();
+
+ // build the revision date
+ var now = new Date();
+ var revDate = String(now.getUTCFullYear());
+ revDate += String(now.getUTCMonthFull());
+ revDate += String(now.getUTCDateFull()) + "T";
+ revDate += String(now.getUTCHoursFull());
+ revDate += String(now.getUTCMinutesFull());
+ revDate += String(now.getUTCSecondsFull()) + "Z";
+
+ var vcData = "BEGIN:VCARD\n"
+ vcData += "VERSION:4.0\n";
+ vcData += "UID:" + newUUID + "\n";
+ vcData += "FN:" + $("#LOCATION-NAME").val() + "\n";
+ vcData += "N:" + $("#LOCATION-NAME").val() + ";;;;\n";
+ vcData += "KIND:location\n";
+ vcData += "ORG:" + $("#LOCATION-ORG").val() + ";;\n";
+ vcData += "NICKNAME:" + $("#LOCATION-NICKNAME").val() + "\n";
+ vcData += "CLASS:PRIVATE\n";
+ vcData += "REV:" + revDate + "\n";
+ vcData += "EMAIL:" + $("#LOCATION-EMAIL").val() + "\n";
+ vcData += "TEL:" + $("#LOCATION-PHONE").val() + "\n";
+ vcData += "ADR:" + $("#LOCATION-POBOX").val() + ";" + $("#LOCATION-EXTADDR").val() + ";" + $("#LOCATION-STREET").val() + ";" + $("#LOCATION-CITY").val() + ";" + $("#LOCATION-STATE").val() + ";" + $("#LOCATION-POSTAL").val() + ";" + $("#LOCATION-COUNTRY").val() + "\n";
+ //vcData += "GEO:TYPE=" + $("#ADDRTYPE-01").val() + ":geo:" + $("#GEO-01").val() + "\n";;
+ vcData += "URL:" + $("#LOCATION-WEBPAGE").val() + "\n";
+ vcData += "PHOTO:VALUE=uri:" + $("#LOCATION-PHOTOURL").val() + "\n";
+ vcData += "NOTE:" + $("#LOCATION-NOTE").val() + "\n";
+ vcData += "END:VCARD";
+
+ $.ajax({
+ type: "put",
+ url: addrBookUrl + newUUID + ".vcf",
+ data: vcData,
+ dataType: "text",
+ processData: false,
+ beforeSend: function(xhrobj) {
+ xhrobj.setRequestHeader("X-HTTP-Method-Override", "PUT");
+ xhrobj.setRequestHeader("If-None-Match", "*");
+ xhrobj.setRequestHeader("Content-Type", "text/vcard");
+ },
+ success: function(responseData, status){
+ var serverMsg = "\n" + status + ": " + responseData;
+ showMessage(bwAbDispSuccessTitle,bwAbDispSuccessfulAdd + serverMsg,true);
+ clearFields("#contactForm");
+ window.location.reload(); // this is temporary - for now, just re-fetch the data from the server to redisplay the cards.
+ },
+ error: function(msg) {
+ // there was a problem
+ showError(msg.status + " " + msg.statusText);
+ }
+ });
+ };
+
+ this.updateLocation = function() {
+ // For now, we'll assume there is only one book to which we can write.
+ var addrBookUrl = bwAddressBook.defPersBookUrl;
+ var curCard = jQuery.parseJSON(bwAddressBook.books[bwAddressBook.book].vcards[bwAddressBook.card]);
+
+ // build the revision date
+ var now = new Date();
+ var revDate = String(now.getUTCFullYear());
+ revDate += String(now.getUTCMonthFull());
+ revDate += String(now.getUTCDateFull()) + "T";
+ revDate += String(now.getUTCHoursFull());
+ revDate += String(now.getUTCMinutesFull());
+ revDate += String(now.getUTCSecondsFull()) + "Z";
+
+ var vcData = "BEGIN:VCARD\n"
+ vcData += "VERSION:4.0\n";
+ vcData += "UID:" + curCard.UID[0].value + "\n";
+ vcData += "FN:" + $("#LOCATION-NAME").val() + "\n";
+ vcData += "N:" + $("#LOCATION-NAME").val() + ";;;;\n";
+ vcData += "KIND:location\n";
+ vcData += "ORG:" + $("#LOCATION-ORG").val() + ";;\n";
+ vcData += "NICKNAME:" + $("#LOCATION-NICKNAME").val() + "\n";
+ vcData += "CLASS:PRIVATE\n";
+ vcData += "REV:" + revDate + "\n";
+ vcData += "EMAIL:" + $("#LOCATION-EMAIL").val() + "\n";
+ vcData += "TEL:" + $("#LOCATION-PHONE").val() + "\n";
+ vcData += "ADR:" + $("#LOCATION-POBOX").val() + ";" + $("#LOCATION-EXTADDR").val() + ";" + $("#LOCATION-STREET").val() + ";" + $("#LOCATION-CITY").val() + ";" + $("#LOCATION-STATE").val() + ";" + $("#LOCATION-POSTAL").val() + ";" + $("#LOCATION-COUNTRY").val() + "\n";
+ //vcData += "GEO:TYPE=" + $("#ADDRTYPE-01").val() + ":geo:" + $("#GEO-01").val() + "\n";;
+ vcData += "URL:" + $("#LOCATION-WEBPAGE").val() + "\n";
+ vcData += "PHOTO:VALUE=uri:" + $("#LOCATION-PHOTOURL").val() + "\n";
+ vcData += "NOTE:" + $("#LOCATION-NOTE").val() + "\n";
+ vcData += "END:VCARD";
+
+ $.ajax({
+ type: "put",
+ url: curCard.href,
+ data: vcData,
+ dataType: "text",
+ processData: false,
+ beforeSend: function(xhrobj) {
+ xhrobj.setRequestHeader("X-HTTP-Method-Override", "PUT");
+ xhrobj.setRequestHeader("If-Match", '"' + curCard.etag + '"'); // restore the etag dquotes
+ xhrobj.setRequestHeader("Content-Type", "text/vcard");
+ },
+ success: function(responseData, status){
+ var serverMsg = "\n" + status + ": " + responseData;
+ showMessage(bwAbDispSuccessTitle,bwAbDispSuccessfulUpdate + serverMsg,true);
+ clearFields("#contactForm");
+ window.location.reload(); // this is temporary - for now, just re-fetch the data from the server to redisplay the cards.
+
+ },
+ error: function(msg) {
+ // there was a problem
+ showError(msg.status + " " + msg.statusText);
+ }
+ });
+ };
+
+
+ // *********************
+ // DELETE AN ITEM
+ // *********************
+
+ // Note: deleteContact works for contacts, locations, groups, and resources
this.deleteContact = function() {
// For now, we'll assume there is only one book from which we can delete cards.
// If we try to delete from another at the moment, we'll either have no access or get
@@ -474,7 +611,24 @@
this.showDetails = function() {
var details = "";
var curCard = jQuery.parseJSON(bwAddressBook.books[bwAddressBook.book].vcards[bwAddressBook.card]);
-
+ // Get the current kind for branching.
+ // If no kind, attempt to use "individual".
+ var curKind = "individual";
+ if (curCard.KIND != undefined) {
+ curKind = curCard.KIND[0].value;
+ }
+
+ // branch to different display types based on kind
+ switch(curKind) {
+ case "location":
+ break;
+ case "group":
+ break;
+ case "thing":
+ break;
+ default: // this is the "individual" kind
+ }
+
// check for the existence of the properties
var fn = "";
if(curCard.FN != undefined) {
@@ -516,10 +670,6 @@
}
// Getters and Setters
- this.setKind = function(val) {
- bwAddressBook.kind = val;
- }
-
this.setBook = function(val) {
bwAddressBook.book = val;
}
@@ -591,6 +741,10 @@
* EVENT HANDLERS:
****************************/
+ // *****************
+ // DISPLAY HANDLERS
+ // *****************
+
// select a book to display
$(".bwBook").click(function() {
// extract the book array index from the id
@@ -617,86 +771,99 @@
bwAddrBook.showDetails();
});
+
+ $("#backToList").click(function() {
+ showPage("bw-list");
+ });
+ // *****************
+ // FORM HANDLING
+ // *****************
+ // ADDING
+
// show form for adding a new contact
$("#addContact").click(function() {
- bwAddrBook.setKind("individual"); // vcard 4 kind
+ clearFields("#contactForm");
$("#bw-modContact h3").text(bwAbDispAddContact);
$("#submitContact").attr("class","add");
+ $("#contactForm").attr("action","#add");
$("#submitContact").text(bwAbDispAddContact);
showPage("bw-modContact");
+ $("#FIRSTNAME").focus();
});
- //show form for editing a contact
- $("#editContact").click(function() {
- bwAddrBook.setKind("individual"); // vcard 4 kind
- $("#bw-modContact h3").text(bwAbDispUpdateContact);
- $("#submitContact").attr("class","update");
- $("#submitContact").text(bwAbDispUpdateContact);
-
- // Setup the form fields. This is dependent on
- // calling this function from the details view
- // where we have a current card loaded.
- var curCard = jQuery.parseJSON(bwAddressBook.books[bwAddressBook.book].vcards[bwAddressBook.card]);
- $("#FIRSTNAME").val(curCard.N[0].values.given_names);
- $("#LASTNAME").val(curCard.N[0].values.family_name);
- $("#ORG").val(curCard.ORG[0].values.organization_name);
- $("#TITLE").val(curCard.TITLE[0].value);
- $("#NICKNAME").val(curCard.NICKNAME[0].value);
- $("#TITLE").val(curCard.TITLE[0].value);
- $("#EMAILTYPE-01").val(curCard.EMAIL[0].params['parameter-value']); // this won't do
- $("#EMAIL-01").val(curCard.EMAIL[0].value);
- $("#PHONETYPE-01").val(curCard.TEL[0].params['parameter-value']); // this won't do
- $("#PHONE-01").val(curCard.TEL[0].values.number);
- $("#ADDRTYPE-01").val(curCard.ADR[0].params['parameter-value']); // also won't do
- $("#POBOX-01").val(curCard.ADR[0].values.po_box);
- $("#EXTADDR-01").val(curCard.ADR[0].values.extended_address);
- $("#STREET-01").val(curCard.ADR[0].values.street_address);
- $("#CITY-01").val(curCard.ADR[0].values.locality);
- $("#STATE-01").val(curCard.ADR[0].values.state);
- $("#POSTAL-01").val(curCard.ADR[0].values.postal_code);
- $("#COUNTRY-01").val(curCard.ADR[0].values.country);
- //$("#GEO-01").val(curCard.URL[0].value); -- set when we have geo working
- $("#WEBPAGE").val(curCard.URL[0].value);
- $("#PHOTOURL").val(curCard.PHOTO[0].value);
- $("#NOTE").val(curCard.NOTE[0].value);
-
- // now show the page
- showPage("bw-modContact");
- });
-
// show form for adding a group
$("#addGroup").click(function() {
- bwAddrBook.setKind("group"); // vcard 4 kind
showPage("bw-modGroup");
});
-
- // show form for editing a group
- $("#editGroup").click(function() {
- bwAddrBook.setKind("group"); // vcard 4 kind
- showPage("bw-modGroup");
- });
- // show form for adding\ a location
+ // show form for adding a location
$("#addLocation").click(function() {
- bwAddrBook.setKind("location"); // vcard 4 kind
+ clearFields("#locationForm");
+ $("#bw-modLocation h3").text(bwAbDispAddLocation);
+ $("#submitLocation").attr("class","add");
+ $("#locationForm").attr("action","#add");
+ $("#submitLocation").text(bwAbDispAddLocation);
showPage("bw-modLocation");
+ $("#LOCATION-NAME").focus();
});
-
- //show form for editing a location
- $("#addLocation").click(function() {
- bwAddrBook.setKind("location"); // vcard 4 kind
- showPage("bw-modLocation");
- });
-
+
// show form for adding/editing a resource (not yet available)
$("#addResource").click(function() {
- bwAddrBook.setKind("thing"); // vcard 4 kind
showPage("bw-modResource");
});
- // submit a vcard to the server
+
+ // EDITING
+
+ //show form for editing an item
+ $("#editEntry").click(function() {
+ // get the current vcard
+ var curCard = jQuery.parseJSON(bwAddressBook.books[bwAddressBook.book].vcards[bwAddressBook.card]);
+ // get its KIND, defaulting to "individual"
+ var curKind = "individual";
+ if (curCard.KIND != undefined) {
+ curKind = curCard.KIND[0].value;
+ }
+
+ // Setup the form fields. This is dependent on
+ // calling this function from the details view
+ // where we have a current card loaded.
+ setupFormFields(curCard,curKind);
+
+ // branch on the type of entry,
+ // fix up buttons and titles, and show the page:
+ switch(curKind) {
+ case "location":
+ $("#bw-modLocation h3").text(bwAbDispUpdateLocation);
+ $("#submitLocation").attr("class","update");
+ $("#locationForm").attr("action","#update");
+ $("#submitLocation").text(bwAbDispUpdateLocation);
+
+ showPage("bw-modLocation");
+ $("#LOCATION-NAME").focus();
+ break;
+ case "group":
+ break;
+ case "thing":
+ break;
+ default: // this is the "individual" kind
+ $("#bw-modContact h3").text(bwAbDispUpdateContact);
+ $("#submitContact").attr("class","update");
+ $("#contactForm").attr("action","#update");
+ $("#submitContact").text(bwAbDispUpdateContact);
+
+ // now show the page
+ showPage("bw-modContact");
+ $("#FIRSTNAME").focus();
+ }
+
+ });
+
+ // SUBMITTING AND CANCELLING
+
+ // submit a contact to the server
$("#submitContact").click(function() {
if ($("#submitContact").hasClass('update')) {
bwAddrBook.updateContact();
@@ -705,6 +872,27 @@
}
});
+ $("#cancelContact").click(function() {
+ clearFields("#contactForm");
+ showPage("bw-list");
+ });
+
+ //submit a location to the server
+ $("#submitLocation").click(function() {
+ if ($("#submitLocation").hasClass('update')) {
+ bwAddrBook.updateLocation();
+ } else {
+ bwAddrBook.addLocation();
+ }
+ });
+
+ $("#cancelLocation").click(function() {
+ clearFields("#locationForm");
+ showPage("bw-list");
+ });
+
+ // DELETING
+
// delete a vcard from the address book
$("#deleteContact").click(function() {
bwAddrBook.deleteContact();
@@ -720,6 +908,8 @@
}
);
+ // SEARCHING AND FILTERING
+
// letter filters
$("#filterLetters a").click(function() {
showMessage(bwAbDispUnimplementedTitle,bwAbDispUnimplemented,true);
@@ -732,6 +922,8 @@
return false;
});
+ // FORM APPENDERS
+
// add a set of address fields to the add contact form
$("#bwAppendAddr").click(function() {
showMessage(bwAbDispUnimplementedTitle,bwAbDispUnimplemented,true);
@@ -753,6 +945,66 @@
});
/****************************
+ * HELPER FUNCTIONS:
+ ****************************/
+function setupFormFields(curCard,kind) {
+ // branch on the KIND of vcard to fill the correct form
+ switch(kind) {
+ case "location" :
+ if (curCard.FN != undefined) $("#LOCATION-NAME").val(curCard.FN[0].value);
+ if (curCard.ORG != undefined) $("#LOCATION-ORG").val(curCard.ORG[0].values.organization_name);
+ if (curCard.NICKNAME != undefined) $("#LOCATION-NICKNAME").val(curCard.NICKNAME[0].value);
+ if (curCard.EMAIL != undefined) $("#LOCATION-EMAIL").val(curCard.EMAIL[0].value);
+ if (curCard.TEL != undefined) $("#LOCATION-PHONE").val(curCard.TEL[0].values.number);
+ if (curCard.ADR != undefined) {
+ $("#LOCATION-POBOX").val(curCard.ADR[0].values.po_box);
+ $("#LOCATION-EXTADDR").val(curCard.ADR[0].values.extended_address);
+ $("#LOCATION-STREET").val(curCard.ADR[0].values.street_address);
+ $("#LOCATION-CITY").val(curCard.ADR[0].values.locality);
+ $("#LOCATION-STATE").val(curCard.ADR[0].values.state);
+ $("#LOCATION-POSTAL").val(curCard.ADR[0].values.postal_code);
+ $("#LOCATION-COUNTRY").val(curCard.ADR[0].values.country);
+ // $("#GEO-01").val(curCard.URL[0].value); -- set when we have geo working
+ }
+ if (curCard.URL != undefined) $("#LOCATION-WEBPAGE").val(curCard.URL[0].value);
+ if (curCard.PHOTO != undefined) $("#LOCATION-PHOTOURL").val(curCard.PHOTO[0].value);
+ if (curCard.NOTE != undefined) $("#LOCATION-NOTE").val(curCard.NOTE[0].value);
+ break;
+ default: // this is the "individual" KIND
+ if (curCard.N != undefined) {
+ $("#FIRSTNAME").val(curCard.N[0].values.given_names);
+ $("#LASTNAME").val(curCard.N[0].values.family_name);
+ }
+ if (curCard.ORG != undefined) $("#ORG").val(curCard.ORG[0].values.organization_name);
+ if (curCard.TITLE != undefined) $("#TITLE").val(curCard.TITLE[0].value);
+ if (curCard.NICKNAME != undefined) $("#NICKNAME").val(curCard.NICKNAME[0].value);
+ if (curCard.TITLE != undefined) $("#TITLE").val(curCard.TITLE[0].value);
+ if (curCard.EMAIL != undefined) {
+ $("#EMAILTYPE-01").val(curCard.EMAIL[0].params['parameter-value']); // this won't do
+ $("#EMAIL-01").val(curCard.EMAIL[0].value);
+ }
+ if (curCard.TEL != undefined) {
+ $("#PHONETYPE-01").val(curCard.TEL[0].params['parameter-value']); // this won't do
+ $("#PHONE-01").val(curCard.TEL[0].values.number);
+ }
+ if (curCard.ADR != undefined) {
+ $("#ADDRTYPE-01").val(curCard.ADR[0].params['parameter-value']); // also won't do
+ $("#POBOX-01").val(curCard.ADR[0].values.po_box);
+ $("#EXTADDR-01").val(curCard.ADR[0].values.extended_address);
+ $("#STREET-01").val(curCard.ADR[0].values.street_address);
+ $("#CITY-01").val(curCard.ADR[0].values.locality);
+ $("#STATE-01").val(curCard.ADR[0].values.state);
+ $("#POSTAL-01").val(curCard.ADR[0].values.postal_code);
+ $("#COUNTRY-01").val(curCard.ADR[0].values.country);
+ //$("#GEO-01").val(curCard.URL[0].value); -- set when we have geo working
+ }
+ if (curCard.URL != undefined) $("#WEBPAGE").val(curCard.URL[0].value);
+ if (curCard.PHOTO != undefined) $("#PHOTOURL").val(curCard.PHOTO[0].value);
+ if (curCard.NOTE != undefined) $("#NOTE").val(curCard.NOTE[0].value);
+ }
+}
+
+/****************************
* GENERIC FUNCTIONS:
****************************/
// display the named page
More information about the Bedework-commit
mailing list