diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-06-25 18:21:29 +0400 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-06-25 18:21:29 +0400 |
commit | 56ed8ba70be35f56e4d34126780d704666089eca (patch) | |
tree | e806e8655e11f42780ef5983b0c5ea77518702a5 | |
parent | d72b85684f6b2dfe2d4103ce6f3d6c604d53c868 (diff) |
Select which address book to add a contact to. Fixes oc-1071.
-rw-r--r-- | apps/contacts/ajax/selectaddressbook.php | 24 | ||||
-rw-r--r-- | apps/contacts/js/contacts.js | 38 | ||||
-rw-r--r-- | apps/contacts/templates/part.selectaddressbook.php | 10 |
3 files changed, 68 insertions, 4 deletions
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 @@ +<?php +/** + * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net> + * 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 = $('<li data-id="'+jsondata.data.id+'" class="active"><a href="index.php?id='+jsondata.data.id+'" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+jsondata.data.id+') no-repeat scroll 0% 0% transparent;">'+Contacts.UI.Card.fn+'</a></li>'); + var item = $('<li role="button" data-id="'+jsondata.data.id+'" data-book-id="'+aid+'" class="active"><a href="index.php?id='+jsondata.data.id+'" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+jsondata.data.id+') no-repeat scroll 0% 0% transparent;">'+Contacts.UI.Card.fn+'</a></li>'); 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 @@ +<div id="selectaddressbook_dialog" title="<?php echo $l->t("Select Address Books"); ?>"> +<form> +<select id="adr_type" name="parameters[ADR][TYPE]" size="1"> + <?php foreach($_['addressbooks'] as $addressbook) { ?> + <option value="<?php echo $addressbook['id']; ?>"><?php echo $addressbook['name']; ?></option> + <?php } ?> +</select> +</form> +</div> + |