From: Thomas Tanghus Date: Mon, 25 Jun 2012 14:21:29 +0000 (+0200) Subject: Select which address book to add a contact to. Fixes oc-1071. X-Git-Tag: v4.0.4~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=56ed8ba70be35f56e4d34126780d704666089eca;p=nextcloud-server.git Select which address book to add a contact to. Fixes oc-1071. --- diff --git a/apps/contacts/ajax/selectaddressbook.php b/apps/contacts/ajax/selectaddressbook.php new file mode 100644 index 00000000000..e5527c8e5f1 --- /dev/null +++ b/apps/contacts/ajax/selectaddressbook.php @@ -0,0 +1,24 @@ + + * 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'); + +$books = OC_Contacts_Addressbook::all(OCP\USER::getUser()); +if(count($books) > 1) { + $addressbooks = array(); + foreach($books as $book) { + $addressbooks[] = array('id' => $book['id'], 'name' => $book['displayname']); + } + $tmpl = new OCP\Template("contacts", "part.selectaddressbook"); + $tmpl->assign('addressbooks', $addressbooks); + $page = $tmpl->fetchPage(); + OCP\JSON::success(array('data' => array( 'type' => 'dialog', 'page' => $page ))); +} else { + OCP\JSON::success(array('data' => array( 'type' => 'result', 'id' => $books[0]['id'] ))); +} \ No newline at end of file diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 43659956869..2a37a7ff9e4 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -288,9 +288,39 @@ Contacts={ Contacts.UI.notImplemented(); }, editNew:function(){ // add a new contact - this.id = ''; this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = ''; - //Contacts.UI.Card.add(t('contacts', 'Contact')+';'+t('contacts', 'New')+';;;', t('contacts', 'New Contact'), '', true); - Contacts.UI.Card.add(';;;;;', '', '', true); + this.id = ''; this.bookid = '', this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = ''; + self = this; + $.getJSON(OC.filePath('contacts', 'ajax', 'selectaddressbook.php'),{},function(jsondata) { + if(jsondata.status == 'success') { + if(jsondata.data.type == 'dialog') { + // Load dialog to select addressbook. + if($('#selectaddressbook_dialog').dialog('isOpen') == true) { + $('#selectaddressbook_dialog').dialog('moveToTop'); + } else { + $('#dialog_holder').html(jsondata.data.page).ready(function($) { + $('#selectaddressbook_dialog').dialog({ + modal: true, height: 'auto', width: 'auto', + buttons: { + 'Ok':function() { + Contacts.UI.Card.add(';;;;;', '',$('#selectaddressbook_dialog').find('select').val(), true); + $(this).dialog('close'); + }, + 'Cancel':function() { $(this).dialog('close'); } + }, + close: function(event, ui) { + $(this).dialog('destroy').remove(); + } + }); + }); + } + } else { + Contacts.UI.Card.bookid = jsondata.data.id; + Contacts.UI.Card.add(';;;;;', '',jsondata.data.id, true); + } + } else { + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + } + }); return false; }, add:function(n, fn, aid, isnew){ // add a new contact @@ -304,7 +334,7 @@ Contacts={ if(jsondata.status == 'success'){ Contacts.UI.Card.loadContact(jsondata.data); $('#leftcontent .active').removeClass('active'); - var item = $('
  • '+Contacts.UI.Card.fn+'
  • '); + var item = $('
  • '+Contacts.UI.Card.fn+'
  • '); var added = false; $('#leftcontent ul li').each(function(){ if ($(this).text().toLowerCase() > Contacts.UI.Card.fn.toLowerCase()) { diff --git a/apps/contacts/templates/part.selectaddressbook.php b/apps/contacts/templates/part.selectaddressbook.php new file mode 100644 index 00000000000..38b8a4b767e --- /dev/null +++ b/apps/contacts/templates/part.selectaddressbook.php @@ -0,0 +1,10 @@ +
    "> +
    + +
    +
    +