1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-30 19:52:17 +01:00

Fixed adding, editing and deleting address books. One minor UI flaw remains.

This commit is contained in:
Thomas Tanghus 2011-12-05 03:38:06 +01:00
parent 51b21f2969
commit b77bb04972
8 changed files with 101 additions and 21 deletions

View File

@ -12,8 +12,12 @@ if(!OC_USER::isLoggedIn()) {
die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
}
OC_JSON::checkAppEnabled('contacts');
$book = array(
'id' => 'new',
'displayname' => '',
);
$tmpl = new OC_Template('contacts', 'part.editaddressbook');
$tmpl->assign('new', true);
$tmpl->assign('book', $book);
$tmpl->assign('addressbook', $book);
$tmpl->printPage();
?>

View File

@ -12,7 +12,7 @@ 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);
/* OC_Log::write('contacts','chooseaddressbook.php',OC_Log::DEBUG); */
$output = new OC_TEMPLATE("contacts", "part.chooseaddressbook");
$output -> printpage();

View File

@ -0,0 +1,26 @@
<?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');
$l10n = new OC_L10N('contacts');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$userid = OC_User::getUser();
$bookid = OC_Contacts_Addressbook::add($userid, $_POST['name'], null);
OC_Contacts_Addressbook::setActive($bookid, 1);
$book = OC_Contacts_Addressbook::find($bookid);
$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $book);
OC_JSON::success(array(
'page' => $tmpl->fetchPage(),
'bookid' => $bookid,
));

View File

@ -23,7 +23,9 @@
// Init owncloud
require_once('../../../lib/base.php');
$id = $_GET['id'];
$id = $_POST['id'];
OC_Log::write('contacts','deletebook.php: '.$id,OC_Log::DEBUG);
$l10n = new OC_L10N('contacts');

20
ajax/editaddressbook.php Normal file
View File

@ -0,0 +1,20 @@
<?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');
$addressbook = OC_Contacts_Addressbook::find($_GET['bookid']);
$tmpl = new OC_Template("contacts", "part.editaddressbook");
$tmpl->assign('new', false);
$tmpl->assign('addressbook', $addressbook);
$tmpl->printPage();
?>

View File

@ -0,0 +1,26 @@
<?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');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$bookid = $_POST['id'];
OC_Contacts_Addressbook::edit($bookid, $_POST['name'], null);
OC_Contacts_Addressbook::setActive($bookid, $_POST['active']);
$addressbook = OC_Contacts_Addressbook::find($bookid);
$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('book', $book);
OC_JSON::success(array(
'page' => $tmpl->fetchPage(),
'addressbook' => $addressbook,
));

View File

@ -36,7 +36,7 @@ Contacts={
*/
if (data.status == 'success'){
checkbox.checked = data.active == 1;
alert('Update Contacts list.');
alert('TODO: Update Contacts list.');
/* TODO: Update Contacts list.
if (data.active == 1){
$('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
@ -53,6 +53,11 @@ Contacts={
$(object).closest('tr').after(tr).hide();
/* TODO: Shouldn't there be some kinda error checking here? */
},
editAddressbook:function(object, bookid){
var tr = $(document.createElement('tr'))
.load(OC.filePath('contacts', 'ajax', 'editaddressbook.php') + "?bookid="+bookid);
$(object).closest('tr').after(tr).hide();
},
deleteAddressbook:function(bookid){
var check = confirm("Do you really want to delete this address book?");
if(check == false){
@ -61,38 +66,35 @@ Contacts={
$.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid},
function(data) {
if (data.status == 'success'){
alert('TODO: Update Contacts list.');
/* 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();*/
$('#calendar_holder').fullCalendar('removeEventSource', url);*/
$('#chooseaddressbook_dialog').dialog('destroy').remove();
Contacts.UI.Addressbooks.overview();
} else {
alert('Error: ' + data.message);
}
});
}
},
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 displayname = $("#displayname_"+bookid).val();
var active = $("#edit_active_"+bookid+":checked").length;
var description = $("#description_"+bookid).val();
var url;
if (calendarid == 'new'){
url = "ajax/createcalendar.php";
if (bookid == 'new'){
url = OC.filePath('contacts', 'ajax', 'createaddressbook.php');
}else{
url = "ajax/updatecalendar.php";
url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
}
$.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
$.post(url, { id: bookid, name: displayname, active: active, description: description },
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();

View File

@ -1,4 +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>";
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=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.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>";