--- /dev/null
+<?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
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
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()) {