Export, CardDAV link and activation/deactivation of address books done.
--- /dev/null
+<?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,
+));
--- /dev/null
+<?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();
+?>
--- /dev/null
+<?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();
+?>
+#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%; }
$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);
+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
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'){
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
-<?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">
<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 -->
--- /dev/null
+<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>
--- /dev/null
+<?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>";
--- /dev/null
+<?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>