From 95ae0f23f14c9e6854999233481e107cc330d70f Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 4 Dec 2011 20:25:46 +0100 Subject: [PATCH] Added UI for selecting/editing address books. Export, CardDAV link and activation/deactivation of address books done. --- apps/contacts/ajax/activation.php | 23 ++++ apps/contacts/ajax/addbook.php | 19 +++ apps/contacts/ajax/chooseaddressbook.php | 19 +++ apps/contacts/css/styles.css | 1 + apps/contacts/index.php | 7 + apps/contacts/js/interface.js | 120 ++++++++++++++++++ apps/contacts/lib/addressbook.php | 20 +++ apps/contacts/templates/index.php | 16 ++- .../templates/part.chooseaddressbook.php | 23 ++++ .../part.chooseaddressbook.rowfields.php | 4 + .../templates/part.editaddressbook.php | 31 +++++ 11 files changed, 277 insertions(+), 6 deletions(-) create mode 100644 apps/contacts/ajax/activation.php create mode 100644 apps/contacts/ajax/addbook.php create mode 100644 apps/contacts/ajax/chooseaddressbook.php create mode 100644 apps/contacts/templates/part.chooseaddressbook.php create mode 100644 apps/contacts/templates/part.chooseaddressbook.rowfields.php create mode 100644 apps/contacts/templates/part.editaddressbook.php diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php new file mode 100644 index 00000000000..6e137692dac --- /dev/null +++ b/apps/contacts/ajax/activation.php @@ -0,0 +1,23 @@ + + * Copyright (c) 2011 Bart Visscher + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once ("../../../lib/base.php"); +if(!OC_USER::isLoggedIn()) { + die(""); +} +OC_JSON::checkAppEnabled('contacts'); +$bookid = $_POST['bookid']; +OC_Contacts_Addressbook::setActive($bookid, $_POST['active']); +$book = OC_Contacts_Addressbook::find($bookid); + +/* is there an OC_JSON::error() ? */ +OC_JSON::success(array( + 'active' => $book['active'], + 'bookid' => $bookid, +)); diff --git a/apps/contacts/ajax/addbook.php b/apps/contacts/ajax/addbook.php new file mode 100644 index 00000000000..ce74ccf9d28 --- /dev/null +++ b/apps/contacts/ajax/addbook.php @@ -0,0 +1,19 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../lib/base.php'); +$l10n = new OC_L10N('contacts'); +if(!OC_USER::isLoggedIn()) { + die(""); +} +OC_JSON::checkAppEnabled('contacts'); +$tmpl = new OC_Template('contacts', 'part.editaddressbook'); +$tmpl->assign('new', true); +$tmpl->assign('book', $book); +$tmpl->printPage(); +?> diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php new file mode 100644 index 00000000000..e150f97f541 --- /dev/null +++ b/apps/contacts/ajax/chooseaddressbook.php @@ -0,0 +1,19 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../lib/base.php'); +$l10n = new OC_L10N('contacts'); +if(!OC_USER::isLoggedIn()) { + die(""); +} +OC_JSON::checkAppEnabled('contacts'); +OC_Log::write('contacts','chooseaddressbook.php',OC_Log::DEBUG); + +$output = new OC_TEMPLATE("contacts", "part.chooseaddressbook"); +$output -> printpage(); +?> diff --git a/apps/contacts/css/styles.css b/apps/contacts/css/styles.css index f351589fe12..048f4cf9d2d 100644 --- a/apps/contacts/css/styles.css +++ b/apps/contacts/css/styles.css @@ -1,3 +1,4 @@ +#chooseaddressbook {margin-right: 170px; float: right; font-size: 12px;} #contacts_details_name { font-weight:bold;font-size:1.1em;margin-left:25%;} #contacts_details_photo { margin:.5em 0em .5em 25%; } diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 29d41d3c4c4..57c28a5761c 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -79,6 +79,13 @@ $l10n = new OC_L10N('contacts'); $adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); $phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +// Include Style and Script +OC_Util::addScript('contacts','interface'); +OC_Util::addStyle('contacts','styles'); +OC_Util::addStyle('contacts','formtastic'); +OC_Util::addScript('', 'jquery.multiselect'); +OC_Util::addStyle('', 'jquery.multiselect'); + // Process the template $tmpl = new OC_Template( 'contacts', 'index', 'user' ); $tmpl->assign('adr_types',$adr_types); diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js index ba1c0e536c2..077bbd2071e 100644 --- a/apps/contacts/js/interface.js +++ b/apps/contacts/js/interface.js @@ -1,3 +1,106 @@ +Contacts={ + space:' ', + UI:{ + showCardDAVUrl:function(username, bookname){ + $('#carddav_url').val(totalurl + '/' + username + '/' + bookname); + $('#carddav_url').show(); + $('#carddav_url_close').show(); + }, + Addressbooks:{ + overview:function(){ + if($('#chooseaddressbook_dialog').dialog('isOpen') == true){ + /*alert('Address books.moveToTop');*/ + $('#chooseaddressbook_dialog').dialog('moveToTop'); + }else{ + $('#dialog_holder').load(OC.filePath('contacts', 'ajax', 'chooseaddressbook.php'), function(){ + /*alert('Address books.load');*/ + $('#chooseaddressbook_dialog').dialog({ + width : 600, + close : function(event, ui) { + $(this).dialog('destroy').remove(); + } + }); + }); + } + }, + activation:function(checkbox, bookid) + { + /* TODO: + * Add integer field 'active' to table 'contacts_addressbooks'. See apps/contacts/README.tanghus */ + $.post(OC.filePath('contacts', 'ajax', 'activation.php'), { bookid: bookid, active: checkbox.checked?1:0 }, + function(data) { + /* + * Arguments: + * data.status + * data.bookid + */ + if (data.status == 'success'){ + checkbox.checked = data.active == 1; + alert('Update Contacts list.'); + /* TODO: Update Contacts list. + if (data.active == 1){ + $('#calendar_holder').fullCalendar('addEventSource', data.eventSource); + }else{ + $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url); + } + */ + } + }); + }, + newAddressbook:function(object){ + var tr = $(document.createElement('tr')) + .load(OC.filePath('contacts', 'ajax', 'addbook.php')); + $(object).closest('tr').after(tr).hide(); + /* TODO: Shouldn't there be some kinda error checking here? */ + }, + deleteAddressbook:function(bookid){ + var check = confirm("Do you really want to delete this address book?"); + if(check == false){ + return false; + }else{ + $.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid}, + function(data) { + if (data.status == 'success'){ + alert('TODO: Update Contacts list.'); + /* TODO: Update Contacts list. + var url = 'ajax/deletebook.php?id='+bookid; + $('#calendar_holder').fullCalendar('removeEventSource', url); + $('#choosecalendar_dialog').dialog('destroy').remove();*/ + Contacts.UI.Addressbooks.overview(); + } + }); + } + }, + submit:function(button, bookid){ + alert('TODO: Add or update address book.'); + /* TODO: Add or update address book. + var displayname = $("#displayname_"+calendarid).val(); + var active = $("#edit_active_"+calendarid+":checked").length; + var description = $("#description_"+calendarid).val(); + var calendarcolor = $("#calendarcolor_"+calendarid).val(); + + var url; + if (calendarid == 'new'){ + url = "ajax/createcalendar.php"; + }else{ + url = "ajax/updatecalendar.php"; + } + $.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor }, + function(data){ + if(data.status == 'success'){ + $(button).closest('tr').prev().html(data.page).show().next().remove(); + $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url); + $('#calendar_holder').fullCalendar('addEventSource', data.eventSource); + } + }, 'json');*/ + }, + cancel:function(button, bookid){ + $(button).closest('tr').prev().show().next().remove(); + } + } + } +} + $(document).ready(function(){ /*------------------------------------------------------------------------- * Event handlers @@ -79,6 +182,23 @@ $(document).ready(function(){ return false; }); + $('#chooseaddressbook').click(function(){ + Contacts.UI.Addressbooks.overview(); + /* + $.getJSON('ajax/showaddcard.php',{},function(jsondata){ + if(jsondata.status == 'success'){ + $('#rightcontent').data('id',''); + $('#rightcontent').html(jsondata.data.page) + .find('select').chosen(); + } + else{ + alert(jsondata.data.message); + } + }); + */ + return false; + }); + $('#contacts_newcontact').click(function(){ $.getJSON('ajax/showaddcard.php',{},function(jsondata){ if(jsondata.status == 'success'){ diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index 87477ed7ed4..93f069cff2f 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -140,6 +140,26 @@ class OC_Contacts_Addressbook{ return true; } + /** + * @brief Activates an addressbook + * @param integer $id + * @param integer $name + * @return boolean + */ + public static function setActive($id,$active){ + // Need these ones for checking uri + //$addressbook = self::find($id); + + if(is_null($id)){ + $id = 0; + } + + $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET active=?, ctag=ctag+1 WHERE id=?' ); + $result = $stmt->execute(array($active,$id)); + + return true; + } + /** * @brief removes an address book * @param integer $id diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 630dca41b2e..20a1e34eb78 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -1,12 +1,10 @@ - - +
+
@@ -17,3 +15,9 @@ OC_Util::addStyle('contacts','formtastic');
inc("part.addcardform"); ?>
+ +
+
+ t("There was a fail, while parsing the file."); ?> +
+ diff --git a/apps/contacts/templates/part.chooseaddressbook.php b/apps/contacts/templates/part.chooseaddressbook.php new file mode 100644 index 00000000000..a698a334174 --- /dev/null +++ b/apps/contacts/templates/part.chooseaddressbook.php @@ -0,0 +1,23 @@ +
"> + +"; + $tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields'); + $tmpl->assign('addressbook', $option_addressbooks[$i]); + $tmpl->printpage(); + echo ""; +} +?> + + + + + + +
+ t('New Address Book') ?> +
+

">

+
diff --git a/apps/contacts/templates/part.chooseaddressbook.rowfields.php b/apps/contacts/templates/part.chooseaddressbook.rowfields.php new file mode 100644 index 00000000000..f6c11310960 --- /dev/null +++ b/apps/contacts/templates/part.chooseaddressbook.rowfields.php @@ -0,0 +1,4 @@ +"; + echo ""; + echo "t("CardDav Link") . "\" class=\"action\">t("Download") . "\" class=\"action\">t("Delete") . "\" class=\"action\">"; diff --git a/apps/contacts/templates/part.editaddressbook.php b/apps/contacts/templates/part.editaddressbook.php new file mode 100644 index 00000000000..4e63ce5ec17 --- /dev/null +++ b/apps/contacts/templates/part.editaddressbook.php @@ -0,0 +1,31 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +?> +t("Edit Address Book"); ?>" colspan="6"> + + + + + + + + + + + +
t('Displayname') ?> + +
+ > + +
+);" value="t("Save") : $l->t("Submit"); ?>"> +);" value="t("Cancel"); ?>"> + -- 2.39.5