]> source.dussan.org Git - nextcloud-server.git/commitdiff
Select which address book to add a contact to. Fixes oc-1071.
authorThomas Tanghus <thomas@tanghus.net>
Mon, 25 Jun 2012 14:21:29 +0000 (16:21 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Mon, 25 Jun 2012 14:21:29 +0000 (16:21 +0200)
apps/contacts/ajax/selectaddressbook.php [new file with mode: 0644]
apps/contacts/js/contacts.js
apps/contacts/templates/part.selectaddressbook.php [new file with mode: 0644]

diff --git a/apps/contacts/ajax/selectaddressbook.php b/apps/contacts/ajax/selectaddressbook.php
new file mode 100644 (file)
index 0000000..e5527c8
--- /dev/null
@@ -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
index 436599568697d6292cf557a7d866a7ef0eddd27c..2a37a7ff9e480515ba15000778fdcdd1beed97c3 100644 (file)
@@ -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 (file)
index 0000000..38b8a4b
--- /dev/null
@@ -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>
+