diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2011-12-04 20:25:46 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2011-12-04 20:25:46 +0100 |
commit | 95ae0f23f14c9e6854999233481e107cc330d70f (patch) | |
tree | 1661673ea95e0a6e3d72c57eee4fe3d3416a6c91 /apps | |
parent | 58d1a3516af1450c6d82f75384bfb2a3f8ea3282 (diff) | |
download | nextcloud-server-95ae0f23f14c9e6854999233481e107cc330d70f.tar.gz nextcloud-server-95ae0f23f14c9e6854999233481e107cc330d70f.zip |
Added UI for selecting/editing address books.
Export, CardDAV link and activation/deactivation of address books done.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/contacts/ajax/activation.php | 23 | ||||
-rw-r--r-- | apps/contacts/ajax/addbook.php | 19 | ||||
-rw-r--r-- | apps/contacts/ajax/chooseaddressbook.php | 19 | ||||
-rw-r--r-- | apps/contacts/css/styles.css | 1 | ||||
-rw-r--r-- | apps/contacts/index.php | 7 | ||||
-rw-r--r-- | apps/contacts/js/interface.js | 120 | ||||
-rw-r--r-- | apps/contacts/lib/addressbook.php | 20 | ||||
-rw-r--r-- | apps/contacts/templates/index.php | 16 | ||||
-rw-r--r-- | apps/contacts/templates/part.chooseaddressbook.php | 23 | ||||
-rw-r--r-- | apps/contacts/templates/part.chooseaddressbook.rowfields.php | 4 | ||||
-rw-r--r-- | apps/contacts/templates/part.editaddressbook.php | 31 |
11 files changed, 277 insertions, 6 deletions
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 @@ +<?php +/** + * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net> + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * 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("<script type=\"text/javascript\">document.location = oc_webroot;</script>"); +} +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 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * 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("<script type=\"text/javascript\">document.location = oc_webroot;</script>"); +} +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 @@ +<?php +/** + * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net> + * 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("<script type=\"text/javascript\">document.location = oc_webroot;</script>"); +} +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 @@ -141,6 +141,26 @@ class OC_Contacts_Addressbook{ } /** + * @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 * @return boolean 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 @@ -<?php // Include Style and Script -OC_Util::addScript('contacts','interface'); -OC_Util::addStyle('contacts','styles'); -OC_Util::addStyle('contacts','formtastic'); -?> - +<script type='text/javascript'> + var totalurl = '<?php echo OC_Helper::linkTo('apps/contacts', 'carddav.php', null, true); ?>/addressbooks'; +</script> <div id="controls"> <form> <input type="button" id="contacts_newcontact" value="<?php echo $l->t('Add Contact'); ?>"> + <input type="button" id="chooseaddressbook" value="<?php echo $l->t('Address Books'); ?>"> </form> </div> <div id="leftcontent" class="leftcontent"> @@ -17,3 +15,9 @@ OC_Util::addStyle('contacts','formtastic'); <div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>"> <?php echo $this->inc("part.addcardform"); ?> </div> +<!-- Dialogs --> +<div id="dialog_holder"></div> +<div id="parsingfail_dialog" title="Parsing Fail"> + <?php echo $l->t("There was a fail, while parsing the file."); ?> +</div> +<!-- End of Dialogs --> 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 @@ +<div id="chooseaddressbook_dialog" title="<?php echo $l->t("Choose active Address Books"); ?>"> +<table width="100%" style="border: 0;"> +<?php +$option_addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser()); +for($i = 0; $i < count($option_addressbooks); $i++){ + echo "<tr>"; + $tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields'); + $tmpl->assign('addressbook', $option_addressbooks[$i]); + $tmpl->printpage(); + echo "</tr>"; +} +?> +<tr> + <td colspan="5"> + <a href="#" onclick="Contacts.UI.Addressbooks.newAddressbook(this);"><?php echo $l->t('New Address Book') ?></a> + </td> +</tr> +<tr> + <td colspan="5"> + <p style="margin: 0 auto;width: 90%;"><input style="display:none;width: 90%;float: left;" type="text" id="carddav_url" onmouseover="$('#carddav_url').select();" title="<?php echo $l->t("CardDav Link"); ?>"><img id="carddav_url_close" style="height: 20px;vertical-align: middle;display: none;" src="../../core/img/actions/delete.svg" alt="close" onclick="$('#carddav_url').hide();$('#carddav_url_close').hide();"/></p> + </td> +</tr> +</table> 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 @@ +<?php + echo "<td width=\"20px\"><input id=\"active_" . $_['addressbook']["id"] . "\" type=\"checkbox\" onClick=\"Contacts.UI.Addressbooks.activation(this, " . $_['addressbook']["id"] . ")\"" . ($_['addressbook']["active"] ? ' checked="checked"' : '') . "></td>"; + echo "<td><label for=\"active_" . $_['addressbook']["id"] . "\">" . $_['addressbook']["displayname"] . "</label></td>"; + echo "<td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.showCardDAVUrl('" . OC_User::getUser() . "', '" . $_['addressbook']["uri"] . "');\" title=\"" . $l->t("CardDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?bookid=" . $_['addressbook']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.Addressbooks.deleteAddressbook('" . $_['addressbook']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>"; 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 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +?> +<td id="<?php echo $_['new'] ? 'new' : 'edit' ?>addressbook_dialog" title="<?php echo $_['new'] ? $l->t("New Address Book") : $l->t("Edit Address Book"); ?>" colspan="6"> +<table width="100%" style="border: 0;"> +<tr> + <th><?php echo $l->t('Displayname') ?></th> + <td> + <input id="displayname_<?php echo $_['addressbook']['id'] ?>" type="text" value="<?php echo $_['addressbook']['displayname'] ?>"> + </td> +</tr> +<?php if (!$_['new']): ?> +<tr> + <td></td> + <td> + <input id="edit_active_<?php echo $_['addressbook']['id'] ?>" type="checkbox"<?php echo $_['addressbook']['active'] ? ' checked="checked"' : '' ?>> + <label for="edit_active_<?php echo $_['addressbook']['id'] ?>"> + <?php echo $l->t('Active') ?> + </label> + </td> +</tr> +<?php endif; ?> +</table> +<input style="float: left;" type="button" onclick="Contacts.UI.Addressbooks.submit(this, <?php echo $_['new'] ? "'new'" : $_['addressbook']['id'] ?>);" value="<?php echo $_['new'] ? $l->t("Save") : $l->t("Submit"); ?>"> +<input style="float: left;" type="button" onclick="Contacts.UI.Addressbooks.cancel(this, <?php echo $_['new'] ? "'new'" : $_['addressbook']['id'] ?>);" value="<?php echo $l->t("Cancel"); ?>"> +</td> |