From f159f607deff03201fb3b35ce1d01ef532d918fe Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 2 Aug 2012 00:01:48 +0200 Subject: [PATCH] And then the missing files ;) --- apps/contacts/ajax/addressbook/activate.php | 32 ++++ apps/contacts/js/settings.js | 186 ++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 apps/contacts/ajax/addressbook/activate.php create mode 100644 apps/contacts/js/settings.js diff --git a/apps/contacts/ajax/addressbook/activate.php b/apps/contacts/ajax/addressbook/activate.php new file mode 100644 index 0000000000..a8dec21dac --- /dev/null +++ b/apps/contacts/ajax/addressbook/activate.php @@ -0,0 +1,32 @@ + + * 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(); + +$id = $_POST['id']; +$book = OC_Contacts_App::getAddressbook($id);// is owner access check + +if(!OC_Contacts_Addressbook::setActive($id, $_POST['active'])) { + OCP\Util::writeLog('contacts', + 'ajax/activation.php: Error activating addressbook: '. $id, + 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($id), + 'id' => $id, + 'addressbook' => $book, +)); diff --git a/apps/contacts/js/settings.js b/apps/contacts/js/settings.js new file mode 100644 index 0000000000..b79e52cb87 --- /dev/null +++ b/apps/contacts/js/settings.js @@ -0,0 +1,186 @@ +OC.Contacts = OC.Contacts || {}; +OC.Contacts.Settings = OC.Contacts.Settings || { + init:function() { + this.Addressbook.adrsettings = $('.addressbooks-settings').first(); + this.Addressbook.adractions = $('#contacts-settings').find('div.actions'); + console.log('actions: ' + this.Addressbook.adractions.length); + }, + Addressbook:{ + showActions:function(act) { + this.adractions.children().hide(); + this.adractions.children('.'+act.join(',.')).show(); + }, + doActivate:function(id, tgt) { + var active = tgt.is(':checked'); + console.log('doActivate: ', id, active); + $.post(OC.filePath('contacts', 'ajax', 'addressbook/activate.php'), {id: id, active: Number(active)}, function(jsondata) { + if (jsondata.status == 'success'){ + if(!active) { + $('#contacts h3[data-id="'+id+'"],#contacts ul[data-id="'+id+'"]').remove(); + } else { + Contacts.UI.Contacts.update(); + } + } else { + console.log('Error:', jsondata.data.message); + Contacts.UI.notify(t('contacts', 'Error') + ': ' + jsondata.data.message); + tgt.checked = !active; + } + }); + }, + doDelete:function(id) { + console.log('doDelete: ', id); + var check = confirm('Do you really want to delete this address book?'); + if(check == false){ + return false; + } else { + $.post(OC.filePath('contacts', 'ajax', 'addressbook/delete.php'), { id: id}, function(jsondata) { + if (jsondata.status == 'success'){ + $('#contacts h3[data-id="'+id+'"],#contacts ul[data-id="'+id+'"]').remove(); + $('.addressbooks-settings tr[data-id="'+id+'"]').remove() + Contacts.UI.Contacts.update(); + } else { + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + } + }); + } + }, + doEdit:function(id) { + console.log('doEdit: ', id); + this.showActions(['active', 'name', 'description', 'save', 'cancel']); + var name = this.adrsettings.find('[data-id="'+id+'"]').find('.name').text(); + var description = this.adrsettings.find('[data-id="'+id+'"]').find('.description').text(); + var active = this.adrsettings.find('[data-id="'+id+'"]').find(':checkbox').is(':checked'); + console.log('name, desc', name, description); + this.adractions.find('.active').prop('checked', active); + this.adractions.find('.name').val(name); + this.adractions.find('.description').val(description); + this.adractions.data('id', id); + }, + doSave:function() { + var name = this.adractions.find('.name').val(); + var description = this.adractions.find('.description').val(); + var active = this.adractions.find('.active').is(':checked'); + var id = this.adractions.data('id'); + console.log('doSave:', id, name, description, active); + + if(name.length == 0) { + OC.dialogs.alert(t('contacts', 'Displayname cannot be empty.'), t('contacts', 'Error')); + return false; + } + var url; + if (id == 'new'){ + url = OC.filePath('contacts', 'ajax', 'addressbook/add.php'); + }else{ + url = OC.filePath('contacts', 'ajax', 'addressbook/update.php'); + } + self = this; + $.post(url, { id: id, name: name, active: Number(active), description: description }, + function(jsondata){ + if(jsondata.status == 'success'){ + self.showActions(['new',]); + self.adractions.removeData('id'); + active = Boolean(Number(jsondata.addressbook.active)); + if(id == 'new') { + self.adrsettings.find('table') + .append('' + + '' + + ''+jsondata.addressbook.displayname+'' + + ''+jsondata.addressbook.description+'' + + '' + + '' + + '' + + '' + + '' + + ''); + } else { + var row = self.adrsettings.find('tr[data-id="'+id+'"]'); + row.find('td.active').find('input:checkbox').prop('checked', active); + row.find('td.name').text(jsondata.addressbook.displayname); + row.find('td.description').text(jsondata.addressbook.description); + } + Contacts.UI.Contacts.update(); + } else { + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + } + }); + }, + showCardDAV:function(id) { + console.log('showCardDAV: ', id); + var row = this.adrsettings.find('tr[data-id="'+id+'"]'); + this.adractions.find('.link').val(totalurl+'/'+encodeURIComponent(oc_current_user)+'/'); + this.showActions(['link','cancel']); + }, + showVCF:function(id) { + console.log('showVCF: ', id); + var row = this.adrsettings.find('tr[data-id="'+id+'"]'); + this.adractions.find('.link').val(totalurl+'/'+encodeURIComponent(oc_current_user)+'/'+encodeURIComponent(row.data('uri'))+'?export'); + this.showActions(['link','cancel']); + } + } +}; + + +$(document).ready(function() { + OC.Contacts.Settings.init(); + + var moreless = $('#contacts-settings').find('.moreless').first(); + moreless.keydown(function(event) { + if(event.which == 13 || event.which == 32) { + moreless.click(); + } + }); + moreless.on('click', function(event) { + event.preventDefault(); + if(OC.Contacts.Settings.Addressbook.adrsettings.is(':visible')) { + OC.Contacts.Settings.Addressbook.adrsettings.slideUp(); + OC.Contacts.Settings.Addressbook.adrsettings.prev('dt').hide(); + moreless.text(t('contacts', 'More...')); + } else { + OC.Contacts.Settings.Addressbook.adrsettings.slideDown(); + OC.Contacts.Settings.Addressbook.adrsettings.prev('dt').show(); + moreless.text(t('contacts', 'Less...')); + } + }); + + OC.Contacts.Settings.Addressbook.adrsettings.keydown(function(event) { + if(event.which == 13 || event.which == 32) { + OC.Contacts.Settings.Addressbook.adrsettings.click(); + } + }); + + + OC.Contacts.Settings.Addressbook.adrsettings.on('click', function(event){ + $('.tipsy').remove(); + var tgt = $(event.target); + if(tgt.is('a') || tgt.is(':checkbox')) { + var id = tgt.parents('tr').first().data('id'); + if(!id) { + return; + } + if(tgt.is(':checkbox')) { + OC.Contacts.Settings.Addressbook.doActivate(id, tgt); + } else if(tgt.is('a')) { + if(tgt.hasClass('edit')) { + OC.Contacts.Settings.Addressbook.doEdit(id); + } else if(tgt.hasClass('delete')) { + OC.Contacts.Settings.Addressbook.doDelete(id); + } else if(tgt.hasClass('globe')) { + OC.Contacts.Settings.Addressbook.showCardDAV(id); + } else if(tgt.hasClass('cloud')) { + OC.Contacts.Settings.Addressbook.showVCF(id); + } + } + } else if(tgt.is('button')) { + event.preventDefault(); + if(tgt.hasClass('save')) { + OC.Contacts.Settings.Addressbook.doSave(); + } else if(tgt.hasClass('cancel')) { + OC.Contacts.Settings.Addressbook.showActions(['new']); + } else if(tgt.hasClass('new')) { + OC.Contacts.Settings.Addressbook.doEdit('new'); + } + } + }); +});