summaryrefslogtreecommitdiffstats
path: root/apps/contacts
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2011-12-05 03:38:06 +0100
committerThomas Tanghus <thomas@tanghus.net>2011-12-05 03:38:06 +0100
commit830efdccac71ebbd4ee5f9414abd0878f2ff9349 (patch)
tree9a546b0c8b7a0e8e0ffd8d05d96bf0f17e778229 /apps/contacts
parent2b48b733a3052c07e199dc2196426a529e977d2d (diff)
downloadnextcloud-server-830efdccac71ebbd4ee5f9414abd0878f2ff9349.tar.gz
nextcloud-server-830efdccac71ebbd4ee5f9414abd0878f2ff9349.zip
Fixed adding, editing and deleting address books. One minor UI flaw remains.
Diffstat (limited to 'apps/contacts')
-rw-r--r--apps/contacts/ajax/addbook.php6
-rw-r--r--apps/contacts/ajax/chooseaddressbook.php2
-rw-r--r--apps/contacts/ajax/createaddressbook.php26
-rw-r--r--apps/contacts/ajax/deletebook.php4
-rw-r--r--apps/contacts/ajax/editaddressbook.php20
-rw-r--r--apps/contacts/ajax/updateaddressbook.php26
-rw-r--r--apps/contacts/js/interface.js36
-rw-r--r--apps/contacts/templates/part.chooseaddressbook.rowfields.php2
8 files changed, 101 insertions, 21 deletions
diff --git a/apps/contacts/ajax/addbook.php b/apps/contacts/ajax/addbook.php
index ce74ccf9d28..d8e5a0ecd59 100644
--- a/apps/contacts/ajax/addbook.php
+++ b/apps/contacts/ajax/addbook.php
@@ -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();
?>
diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php
index e150f97f541..d55fdf3e93b 100644
--- a/apps/contacts/ajax/chooseaddressbook.php
+++ b/apps/contacts/ajax/chooseaddressbook.php
@@ -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();
diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php
new file mode 100644
index 00000000000..3dd38703c17
--- /dev/null
+++ b/apps/contacts/ajax/createaddressbook.php
@@ -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,
+));
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php
index c13217ef2e2..238975436e7 100644
--- a/apps/contacts/ajax/deletebook.php
+++ b/apps/contacts/ajax/deletebook.php
@@ -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');
diff --git a/apps/contacts/ajax/editaddressbook.php b/apps/contacts/ajax/editaddressbook.php
new file mode 100644
index 00000000000..abdad09dea0
--- /dev/null
+++ b/apps/contacts/ajax/editaddressbook.php
@@ -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();
+?>
diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/updateaddressbook.php
new file mode 100644
index 00000000000..ccf1cef03f7
--- /dev/null
+++ b/apps/contacts/ajax/updateaddressbook.php
@@ -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,
+));
diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js
index 077bbd2071e..f34cde89576 100644
--- a/apps/contacts/js/interface.js
+++ b/apps/contacts/js/interface.js
@@ -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();
diff --git a/apps/contacts/templates/part.chooseaddressbook.rowfields.php b/apps/contacts/templates/part.chooseaddressbook.rowfields.php
index f6c11310960..7f7b5a9154e 100644
--- a/apps/contacts/templates/part.chooseaddressbook.rowfields.php
+++ b/apps/contacts/templates/part.chooseaddressbook.rowfields.php
@@ -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>";