From a8faae4f421ab8b85c2bd88b9617efb191c3ff62 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 1 Aug 2012 23:59:44 +0200 Subject: [PATCH] Addressbooks settings rewrite and cleanup. --- apps/contacts/ajax/activation.php | 32 ---- .../add.php} | 6 +- .../delete.php} | 5 +- .../update.php} | 23 +-- apps/contacts/ajax/chooseaddressbook.php | 15 -- apps/contacts/ajax/createaddressbook.php | 36 ----- apps/contacts/ajax/editaddressbook.php | 16 -- apps/contacts/css/contacts.css | 7 + apps/contacts/js/contacts.js | 144 +++--------------- apps/contacts/lib/app.php | 5 +- apps/contacts/templates/index.php | 1 - .../templates/part.chooseaddressbook.php | 24 --- .../part.chooseaddressbook.rowfields.php | 18 --- apps/contacts/templates/part.contact.php | 3 +- .../templates/part.edit_address_dialog.php | 1 + apps/contacts/templates/part.no_contacts.php | 1 + apps/contacts/templates/settings.php | 44 +++++- 17 files changed, 98 insertions(+), 283 deletions(-) delete mode 100644 apps/contacts/ajax/activation.php rename apps/contacts/ajax/{addaddressbook.php => addressbook/add.php} (90%) rename apps/contacts/ajax/{deletebook.php => addressbook/delete.php} (90%) rename apps/contacts/ajax/{updateaddressbook.php => addressbook/update.php} (58%) delete mode 100644 apps/contacts/ajax/chooseaddressbook.php delete mode 100644 apps/contacts/ajax/createaddressbook.php delete mode 100644 apps/contacts/ajax/editaddressbook.php delete mode 100644 apps/contacts/templates/part.chooseaddressbook.php delete mode 100644 apps/contacts/templates/part.chooseaddressbook.rowfields.php diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php deleted file mode 100644 index 69173c54c4..0000000000 --- a/apps/contacts/ajax/activation.php +++ /dev/null @@ -1,32 +0,0 @@ - - * Copyright (c) 2011 Bart Visscher - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - - -OCP\JSON::checkLoggedIn(); -OCP\JSON::checkAppEnabled('contacts'); -OCP\JSON::callCheck(); - -$bookid = $_POST['bookid']; -$book = OC_Contacts_App::getAddressbook($bookid);// is owner access check - -if(!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) { - OCP\Util::writeLog('contacts', - 'ajax/activation.php: Error activating addressbook: '. $bookid, - OCP\Util::ERROR); - OCP\JSON::error(array( - 'data' => array( - 'message' => OC_Contacts_App::$l10n->t('Error (de)activating addressbook.')))); - exit(); -} - -OCP\JSON::success(array( - 'active' => OC_Contacts_Addressbook::isActive($bookid), - 'bookid' => $bookid, - 'book' => $book, -)); diff --git a/apps/contacts/ajax/addaddressbook.php b/apps/contacts/ajax/addressbook/add.php similarity index 90% rename from apps/contacts/ajax/addaddressbook.php rename to apps/contacts/ajax/addressbook/add.php index 40773704bb..617c2fd182 100644 --- a/apps/contacts/ajax/addaddressbook.php +++ b/apps/contacts/ajax/addressbook/add.php @@ -6,13 +6,13 @@ * later. * See the COPYING-README file. */ - + // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); -require_once 'loghandler.php'; +require_once __DIR__.'/../loghandler.php'; debug('name: '.$_POST['name']); @@ -34,4 +34,4 @@ if(!OC_Contacts_Addressbook::setActive($bookid, 1)) { bailOut('Error activating addressbook.'); } $addressbook = OC_Contacts_App::getAddressbook($bookid); -OCP\JSON::success(array('data' => $addressbook)); +OCP\JSON::success(array('addressbook' => $addressbook)); diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/addressbook/delete.php similarity index 90% rename from apps/contacts/ajax/deletebook.php rename to apps/contacts/ajax/addressbook/delete.php index 1b86ecf223..f59c605f4e 100644 --- a/apps/contacts/ajax/deletebook.php +++ b/apps/contacts/ajax/addressbook/delete.php @@ -24,9 +24,12 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); +require_once __DIR__.'/../loghandler.php'; -//$id = $_GET['id']; $id = $_POST['id']; +if(!$id) { + bailOut(OC_Contacts_App::$l10n->t('id is not set.')); +} OC_Contacts_App::getAddressbook( $id ); // is owner access check OC_Contacts_Addressbook::delete($id); diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/addressbook/update.php similarity index 58% rename from apps/contacts/ajax/updateaddressbook.php rename to apps/contacts/ajax/addressbook/update.php index a14b215843..0fc66c3a3b 100644 --- a/apps/contacts/ajax/updateaddressbook.php +++ b/apps/contacts/ajax/addressbook/update.php @@ -6,33 +6,34 @@ * See the COPYING-README file. */ - + // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); -require_once 'loghandler.php'; - -$bookid = $_POST['id']; -OC_Contacts_App::getAddressbook($bookid); // is owner access check +require_once __DIR__.'/../loghandler.php'; +$id = $_POST['id']; $name = trim(strip_tags($_POST['name'])); +$description = trim(strip_tags($_POST['description'])); +if(!$id) { + bailOut(OC_Contacts_App::$l10n->t('id is not set.')); +} + if(!$name) { bailOut(OC_Contacts_App::$l10n->t('Cannot update addressbook with an empty name.')); } -if(!OC_Contacts_Addressbook::edit($bookid, $name, null)) { +if(!OC_Contacts_Addressbook::edit($id, $name, $description)) { bailOut(OC_Contacts_App::$l10n->t('Error updating addressbook.')); } -if(!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) { +if(!OC_Contacts_Addressbook::setActive($id, $_POST['active'])) { bailOut(OC_Contacts_App::$l10n->t('Error (de)activating addressbook.')); } -$addressbook = OC_Contacts_App::getAddressbook($bookid); -$tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields'); -$tmpl->assign('addressbook', $addressbook); +OC_Contacts_App::getAddressbook($id); // is owner access check +$addressbook = OC_Contacts_App::getAddressbook($id); OCP\JSON::success(array( - 'page' => $tmpl->fetchPage(), 'addressbook' => $addressbook, )); diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php deleted file mode 100644 index 1ce8dd46ee..0000000000 --- a/apps/contacts/ajax/chooseaddressbook.php +++ /dev/null @@ -1,15 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - - -OCP\JSON::checkLoggedIn(); -OCP\JSON::checkAppEnabled('contacts'); - -$tmpl = new OCP\Template("contacts", "part.chooseaddressbook"); -$page = $tmpl->fetchPage(); -OCP\JSON::success(array('data' => array('page'=>$page))); diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php deleted file mode 100644 index 8dbd63f642..0000000000 --- a/apps/contacts/ajax/createaddressbook.php +++ /dev/null @@ -1,36 +0,0 @@ - - * Copyright (c) 2011 Bart Visscher - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - - -// Check if we are a user -OCP\JSON::checkLoggedIn(); -OCP\JSON::checkAppEnabled('contacts'); -OCP\JSON::callCheck(); -require_once 'loghandler.php'; - -$userid = OCP\USER::getUser(); -$name = trim(strip_tags($_POST['name'])); -if(!$name) { - bailOut('Cannot add addressbook with an empty name.'); -} -$bookid = OC_Contacts_Addressbook::add($userid, $name, null); -if(!$bookid) { - bailOut('Error adding addressbook: '.$name); -} - -if(!OC_Contacts_Addressbook::setActive($bookid, 1)) { - bailOut('Error activating addressbook.'); -} -$addressbook = OC_Contacts_App::getAddressbook($bookid); -$tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields'); -$tmpl->assign('addressbook', $addressbook); -OCP\JSON::success(array( - 'page' => $tmpl->fetchPage(), - 'addressbook' => $addressbook, -)); diff --git a/apps/contacts/ajax/editaddressbook.php b/apps/contacts/ajax/editaddressbook.php deleted file mode 100644 index 4bc77302e5..0000000000 --- a/apps/contacts/ajax/editaddressbook.php +++ /dev/null @@ -1,16 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - - -OCP\JSON::checkLoggedIn(); -OCP\JSON::checkAppEnabled('contacts'); -$addressbook = OC_Contacts_App::getAddressbook($_GET['bookid']); -$tmpl = new OCP\Template("contacts", "part.editaddressbook"); -$tmpl->assign('new', false); -$tmpl->assign('addressbook', $addressbook); -$tmpl->printPage(); diff --git a/apps/contacts/css/contacts.css b/apps/contacts/css/contacts.css index 5350fdd5d3..1a7935aa79 100644 --- a/apps/contacts/css/contacts.css +++ b/apps/contacts/css/contacts.css @@ -134,3 +134,10 @@ input[type="checkbox"] { width: 20px; height: 20px; vertical-align: bottom; } .help-section dl { width: 100%; float: left; clear: right; margin: 0; padding: 0; cursor: normal; } .help-section dt { display: table-cell; clear: left; float: left; width: 35%; margin: 0; padding: 0.2em; text-align: right; text-overflow: ellipsis; vertical-align: text-bottom; font-weight: bold: } .help-section dd { display: table-cell; clear: right; float: left; margin: 0; padding: 0.2em; white-space: nowrap; vertical-align: text-bottom; } +.contacts-settings dl { width: 100%; } +.addressbooks-settings table { width: 100%; } +.addressbooks-settings .actions { width: 100%; white-space: nowrap; } +.addressbooks-settings .actions * { float: left; } +.addressbooks-settings .actions input.name { width: 5em; } +.addressbooks-settings .actions input.name { width: 7em; } + diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index fa99878174..c53fc5af63 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -22,7 +22,7 @@ Contacts={ * cancel: If set cancel all ongoing timer events and hide the notification. */ notify:function(params) { - self = this; + var self = this; if(!self.notifier) { self.notifier = $('#notification'); } @@ -40,6 +40,10 @@ Contacts={ self.notifier.fadeIn(); self.notifier.on('click', function() { $(this).fadeOut();}); var timer = setTimeout(function() { + if(!self || !self.notifier) { + var self = Contacts.UI; + self.notifier = $('#notification'); + } self.notifier.fadeOut(); if(params.timeouthandler && $.isFunction(params.timeouthandler)) { params.timeouthandler(self.notifier.data(dataid)); @@ -53,6 +57,10 @@ Contacts={ } if(params.clickhandler && $.isFunction(params.clickhandler)) { self.notifier.on('click', function() { + if(!self || !self.notifier) { + var self = Contacts.UI; + self.notifier = $(this); + } clearTimeout(timer); self.notifier.off('click'); params.clickhandler(self.notifier.data(dataid)); @@ -1382,123 +1390,6 @@ Contacts={ return false; }, }, - Addressbooks:{ - overview:function(){ - if($('#chooseaddressbook_dialog').dialog('isOpen') == true){ - $('#chooseaddressbook_dialog').dialog('moveToTop'); - }else{ - $('body').append('
'); - $.getJSON(OC.filePath('contacts', 'ajax', 'chooseaddressbook.php'), function(jsondata){ - if(jsondata.status == 'success'){ - $('#addressbook_dialog').html(jsondata.data.page).find('#chooseaddressbook_dialog').dialog({ - minWidth : 600, - close : function(event, ui) { - $(this).dialog('destroy').remove(); - $('#addressbook_dialog').remove(); - } - }).css('overflow','visible'); - } else { - alert(jsondata.data.message); - $('#addressbook_dialog').remove(); - } - }); - } - return false; - }, - activation:function(checkbox, bookid){ - var active = checkbox.checked; - $.post(OC.filePath('contacts', 'ajax', 'activation.php'), {bookid: bookid, active: (active?1:0)}, function(jsondata) { - if (jsondata.status == 'success'){ - if(!active) { - $('#contacts h3[data-id="'+bookid+'"],#contacts ul[data-id="'+bookid+'"]').remove(); - } else { - Contacts.UI.Contacts.update(); - } - } else { - OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); - checkbox.checked = !active; - } - }); - }, - addAddressbook:function(name, description, cb) { - $.post(OC.filePath('contacts', 'ajax', 'addaddressbook.php'), { name: name, description: description, active: true }, - function(jsondata){ - if(jsondata.status == 'success'){ - if(cb) { - cb(jsondata.data); - } - } else { - OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); - return false; - } - }); - - }, - newAddressbook:function(object){ - var tr = $(document.createElement('tr')) - .load(OC.filePath('contacts', 'ajax', 'addbook.php')); - $(object).closest('tr').after(tr).hide(); - }, - 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(obj, 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(jsondata) { - if (jsondata.status == 'success'){ - $(obj).closest('tr').remove(); - $('#contacts h3[data-id="'+bookid+'"],#contacts ul[data-id="'+bookid+'"]').remove(); - Contacts.UI.Contacts.update(); - } else { - OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); - } - }); - } - }, - doImport:function(file, aid){ - $.post(OC.filePath('contacts', '', 'import.php'), { id: aid, file: file, fstype: 'OC_FilesystemView' }, - function(jsondata){ - if(jsondata.status != 'success'){ - Contacts.UI.notify({message:jsondata.data.message}); - } - }); - return false; - }, - submit:function(button, bookid){ - var displayname = $("#displayname_"+bookid).val().trim(); - var active = $("#edit_active_"+bookid+":checked").length; - var description = $("#description_"+bookid).val(); - - if(displayname.length == 0) { - OC.dialogs.alert(t('contacts', 'Displayname cannot be empty.'), t('contacts', 'Error')); - return false; - } - var url; - if (bookid == 'new'){ - url = OC.filePath('contacts', 'ajax', 'createaddressbook.php'); - }else{ - url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php'); - } - $.post(url, { id: bookid, name: displayname, active: active, description: description }, - function(jsondata){ - if(jsondata.status == 'success'){ - $(button).closest('tr').prev().html(jsondata.page).show().next().remove(); - Contacts.UI.Contacts.update(); - } else { - OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); - } - }); - }, - cancel:function(button, bookid){ - $(button).closest('tr').prev().show().next().remove(); - } - }, Contacts:{ contacts:{}, deletionQueue:[], @@ -1613,6 +1504,15 @@ Contacts={ //this.contacts[id] = contact; return contact; }, + doImport:function(file, aid){ + $.post(OC.filePath('contacts', '', 'import.php'), { id: aid, file: file, fstype: 'OC_FilesystemView' }, + function(jsondata){ + if(jsondata.status != 'success'){ + Contacts.UI.notify({message:jsondata.data.message}); + } + }); + return false; + }, next:function(reverse) { // TODO: Check if we're last-child/first-child and jump to next/prev address book. var curlistitem = $('#contacts li[data-id="'+Contacts.UI.Card.id+'"]'); @@ -1747,7 +1647,11 @@ $(document).ready(function(){ //$('#chooseaddressbook').on('click keydown', Contacts.UI.Addressbooks.overview); $('#bottomcontrols .settings').on('click keydown', function() { - OC.appSettings({appid:'contacts'}); + try { + OC.appSettings({appid:'contacts', loadJS:true, cache:false}); + } catch(e) { + console.log('error:', e.message); + } }); $('#bottomcontrols .import').click(function() { $('#import_upload_start').trigger('click'); @@ -2045,7 +1949,7 @@ $(document).ready(function(){ $('#uploadprogressbar').progressbar('value',50); var todo = uploadedfiles; $.each(fileList, function(fileName, data) { - Contacts.UI.Addressbooks.doImport(fileName, aid); + Contacts.UI.Contacts.doImport(fileName, aid); delete fileList[fileName]; numfiles -= 1; uploadedfiles -= 1; $('#uploadprogressbar').progressbar('value',50+(50/(todo-uploadedfiles))); diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php index 67dfe8f640..3972d0e0a5 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -22,16 +22,18 @@ class OC_Contacts_App { public static $categories = null; public static function getAddressbook($id) { + // TODO: Throw an exception instead of returning json. $addressbook = OC_Contacts_Addressbook::find( $id ); if($addressbook === false || $addressbook['userid'] != OCP\USER::getUser()) { if ($addressbook === false) { OCP\Util::writeLog('contacts', 'Addressbook not found: '. $id, OCP\Util::ERROR); + //throw new Exception('Addressbook not found: '. $id); OCP\JSON::error( array( 'data' => array( - 'message' => self::$l10n->t('Addressbook not found.') + 'message' => self::$l10n->t('Addressbook not found: ' . $id) ) ) ); @@ -40,6 +42,7 @@ class OC_Contacts_App { OCP\Util::writeLog('contacts', 'Addressbook('.$id.') is not from '.OCP\USER::getUser(), OCP\Util::ERROR); + //throw new Exception('This is not your addressbook.'); OCP\JSON::error( array( 'data' => array( diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 7ff139e31c..4c2a19e8d9 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -24,7 +24,6 @@
- inc('part.contact'); diff --git a/apps/contacts/templates/part.chooseaddressbook.php b/apps/contacts/templates/part.chooseaddressbook.php deleted file mode 100644 index caed67736c..0000000000 --- a/apps/contacts/templates/part.chooseaddressbook.php +++ /dev/null @@ -1,24 +0,0 @@ -
"> - -"; - $tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields'); - $tmpl->assign('addressbook', $option_addressbooks[$i]); - $tmpl->assign('active', OC_Contacts_Addressbook::isActive($option_addressbooks[$i]['id'])); - $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 deleted file mode 100644 index 2988bb44c5..0000000000 --- a/apps/contacts/templates/part.chooseaddressbook.rowfields.php +++ /dev/null @@ -1,18 +0,0 @@ - - " type="checkbox" onClick="Contacts.UI.Addressbooks.activation(this, )" > - - - - - - " class="svg action globe"> - - - " title="t("Download"); ?>" class="svg action download"> - - - " class="svg action edit" onclick="Contacts.UI.Addressbooks.editAddressbook(this, );"> - - - );" title="t("Delete"); ?>" class="svg action delete"> - diff --git a/apps/contacts/templates/part.contact.php b/apps/contacts/templates/part.contact.php index 4233bffede..3670ce0389 100644 --- a/apps/contacts/templates/part.contact.php +++ b/apps/contacts/templates/part.contact.php @@ -1,3 +1,4 @@ + @@ -73,7 +74,7 @@ $id = isset($_['id']) ? $_['id'] : '';
diff --git a/apps/contacts/templates/part.no_contacts.php b/apps/contacts/templates/part.no_contacts.php index 5faa481bc3..be12092d45 100644 --- a/apps/contacts/templates/part.no_contacts.php +++ b/apps/contacts/templates/part.no_contacts.php @@ -1,3 +1,4 @@ +
t('You have no contacts in your addressbook.') ?>
diff --git a/apps/contacts/templates/settings.php b/apps/contacts/templates/settings.php index c42de12fa7..85dbca36fa 100644 --- a/apps/contacts/templates/settings.php +++ b/apps/contacts/templates/settings.php @@ -6,13 +6,49 @@
t('iOS/OS X'); ?>
principals//
-
t('Read only vCard directory link(s)'); ?>
-
+
+ - Powered by geonames.org webservice +
+ +