summaryrefslogtreecommitdiffstats
path: root/apps/contacts
diff options
context:
space:
mode:
authorBrice Maron <brice@bmaron.net>2012-06-21 17:15:35 +0000
committerBrice Maron <brice@bmaron.net>2012-06-21 17:15:35 +0000
commite5c56b2433b1987e4b6b8020e01f4da03623c4b8 (patch)
treea650870f7bbc497833b8ea00051f9046e1779f5e /apps/contacts
parentdf83df5263db57056d0bd70edfa3b28e7b5e6b6b (diff)
parent6707e4187e4c1186eff8dfe06999c4539ab80de7 (diff)
downloadnextcloud-server-e5c56b2433b1987e4b6b8020e01f4da03623c4b8.tar.gz
nextcloud-server-e5c56b2433b1987e4b6b8020e01f4da03623c4b8.zip
Merge branch 'master' into multi_app_dir
Conflicts: lib/app.php lib/base.php lib/minimizer/css.php lib/minimizer/js.php lib/template.php lib/util.php
Diffstat (limited to 'apps/contacts')
-rw-r--r--apps/contacts/ajax/addcontact.php2
-rw-r--r--apps/contacts/ajax/contacts.php47
-rw-r--r--apps/contacts/ajax/editaddress.php13
-rw-r--r--apps/contacts/ajax/editname.php5
-rw-r--r--apps/contacts/css/contacts.css13
-rw-r--r--apps/contacts/index.php2
-rw-r--r--apps/contacts/js/contacts.js115
-rw-r--r--apps/contacts/lib/addressbook.php23
-rw-r--r--apps/contacts/lib/hooks.php2
-rw-r--r--apps/contacts/lib/search.php13
-rw-r--r--apps/contacts/lib/vcard.php2
-rw-r--r--apps/contacts/templates/index.php19
-rw-r--r--apps/contacts/templates/part.contact.php24
-rw-r--r--apps/contacts/templates/part.contacts.php18
-rw-r--r--apps/contacts/templates/part.cropphoto.php2
-rw-r--r--apps/contacts/templates/part.edit_address_dialog.php22
-rw-r--r--apps/contacts/templates/part.edit_name_dialog.php10
17 files changed, 195 insertions, 137 deletions
diff --git a/apps/contacts/ajax/addcontact.php b/apps/contacts/ajax/addcontact.php
index e45072c9542..12f7bb9db96 100644
--- a/apps/contacts/ajax/addcontact.php
+++ b/apps/contacts/ajax/addcontact.php
@@ -47,4 +47,4 @@ if(!$id) {
exit();
}
-OCP\JSON::success(array('data' => array( 'id' => $id )));
+OCP\JSON::success(array('data' => array( 'id' => $id, 'aid' => $aid )));
diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php
index 37d396cd83a..16730ec9474 100644
--- a/apps/contacts/ajax/contacts.php
+++ b/apps/contacts/ajax/contacts.php
@@ -6,15 +6,54 @@
* See the COPYING-README file.
*/
+function cmp($a, $b)
+{
+ if ($a['displayname'] == $b['displayname']) {
+ return 0;
+ }
+ return ($a['displayname'] < $b['displayname']) ? -1 : 1;
+}
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
-$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
-$contacts = OC_Contacts_VCard::all($ids);
+$active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
+error_log('active_addressbooks: '.print_r($active_addressbooks, true));
+
+$contacts_addressbook = array();
+$ids = array();
+foreach($active_addressbooks as $addressbook) {
+ $ids[] = $addressbook['id'];
+ if(!isset($contacts_addressbook[$addressbook['id']])) {
+ $contacts_addressbook[$addressbook['id']] = array('contacts' => array());
+ $contacts_addressbook[$addressbook['id']]['displayname'] = $addressbook['displayname'];
+ }
+}
+error_log('ids: '.print_r($ids, true));
+$contacts_alphabet = OC_Contacts_VCard::all($ids);
+error_log('contacts_alphabet: '.print_r($contacts_alphabet, true));
+
+// Our new array for the contacts sorted by addressbook
+foreach($contacts_alphabet as $contact) {
+ if(!isset($contacts_addressbook[$contact['addressbookid']])) { // It should never execute.
+ $contacts_addressbook[$contact['addressbookid']] = array('contacts' => array());
+ }
+ $display = trim($contact['fullname']);
+ if(!$display) {
+ $vcard = OC_Contacts_App::getContactVCard($contact['id']);
+ if(!is_null($vcard)) {
+ $struct = OC_Contacts_VCard::structureContact($vcard);
+ $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]';
+ }
+ }
+ $contacts_addressbook[$contact['addressbookid']]['contacts'][] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'displayname' => htmlspecialchars($display));
+}
+
+uasort($contacts_addressbook, 'cmp');
+
$tmpl = new OCP\Template("contacts", "part.contacts");
-$tmpl->assign('contacts', $contacts);
+$tmpl->assign('books', $contacts_addressbook, false);
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array( 'page' => $page )));
-?>
+
diff --git a/apps/contacts/ajax/editaddress.php b/apps/contacts/ajax/editaddress.php
index 969aeeba8f4..2d7aba11b0e 100644
--- a/apps/contacts/ajax/editaddress.php
+++ b/apps/contacts/ajax/editaddress.php
@@ -20,7 +20,18 @@ if($checksum) {
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
$element = $vcard->children[$line];
$adr = OC_Contacts_VCard::structureProperty($element);
- $tmpl->assign('adr',$adr);
+ $types = array();
+ if(isset($adr['parameters']['TYPE'])) {
+ if(is_array($adr['parameters']['TYPE'])) {
+ $types = array_map('htmlspecialchars', $adr['parameters']['TYPE']);
+ $types = array_map('strtoupper', $types);
+ } else {
+ $types = array(strtoupper(htmlspecialchars($adr['parameters']['TYPE'])));
+ }
+ }
+ $tmpl->assign('types', $types, false);
+ $adr = array_map('htmlspecialchars', $adr['value']);
+ $tmpl->assign('adr', $adr, false);
}
$tmpl->assign('id',$id);
diff --git a/apps/contacts/ajax/editname.php b/apps/contacts/ajax/editname.php
index d06d416b7ed..62cae894b6f 100644
--- a/apps/contacts/ajax/editname.php
+++ b/apps/contacts/ajax/editname.php
@@ -28,8 +28,9 @@ if($id) {
$name = OC_Contacts_VCard::structureProperty($property);
}
}
- $tmpl->assign('name',$name);
- $tmpl->assign('id',$id);
+ $name = array_map('htmlspecialchars', $name['value']);
+ $tmpl->assign('name',$name, false);
+ $tmpl->assign('id',$id, false);
} else {
bailOut(OC_Contacts_App::$l10n->t('Contact ID is missing.'));
}
diff --git a/apps/contacts/css/contacts.css b/apps/contacts/css/contacts.css
index 8de68fbf052..6c65db2b772 100644
--- a/apps/contacts/css/contacts.css
+++ b/apps/contacts/css/contacts.css
@@ -2,9 +2,12 @@
font-weight: bold;
}*/
#leftcontent { top: 3.5em !important; padding: 0; margin: 0; }
+#leftcontent a { padding: 0 0 0 25px; }
#rightcontent { top: 3.5em !important; padding-top: 5px; }
-#contacts { background: #fff; width: 20em; left: 12.5em; top: 3.7em; bottom:3em; position: fixed; overflow: auto; padding: 0; margin: 0; }
-#contacts a { height: 23px; display: block; margin: 0 0 0 0; padding: 0 0 0 25px; }
+#leftcontent h3 { cursor: pointer; -moz-transition: background 300ms ease 0s; background: none no-repeat scroll 1em center #eee; border-bottom: 1px solid #ddd; border-top: 1px solid #fff; display: block; max-width: 100%; padding: 0.5em 0.8em; color: #666; text-shadow: 0 1px 0 #f8f8f8; font-size: 1.2em; }
+#leftcontent h3:hover { background-color: #DBDBDB; border-bottom: 1px solid #CCCCCC; border-top: 1px solid #D4D4D4; color: #333333; }
+#contacts { position: fixed; background: #fff; max-width: 100%; width: 20em; left: 12.5em; top: 3.7em; bottom: 3em; overflow: auto; padding: 0; margin: 0; }
+.contacts a { height: 23px; display: block; left: 12.5em; margin: 0 0 0 0; padding: 0 0 0 25px; }
#bottomcontrols { padding: 0; bottom:0px; height:2.8em; width: 20em; margin:0; background:#eee; border-top:1px solid #ccc; position:fixed; -moz-box-shadow: 0 -3px 3px -3px #000; -webkit-box-shadow: 0 -3px 3px -3px #000; box-shadow: 0 -3px 3px -3px #000;}
#contacts_newcontact { float: left; margin: 0.2em 0 0 1em; }
#chooseaddressbook { float: right; margin: 0.2em 1em 0 0; }
@@ -22,10 +25,10 @@
#firstrun { width: 100%; position: absolute; top: 5em; left: 0; text-align: center; font-weight:bold; font-size:1.5em; color:#777; }
#firstrun #selections { font-size:0.8em; margin: 2em auto auto auto; clear: both; }
-#card input[type="text"].contacts_property,input[type="email"].contacts_property { width: 14em; float: left; font-weight: bold; }
+#card input[type="text"].contacts_property,input[type="email"].contacts_property,input[type="url"].contacts_property { width: 14em; float: left; font-weight: bold; }
.categories { float: left; width: 16em; }
-#card input[type="text"],input[type="email"],input[type="tel"],input[type="date"], select, textarea { background-color: #fefefe; border: 0 !important; -webkit-appearance:none !important; -moz-appearance:none !important; -webkit-box-sizing:none !important; -moz-box-sizing:none !important; box-sizing:none !important; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; -moz-border-radius: 0px; -webkit-border-radius: 0px; border-radius: 0px; float: left; }
-#card input[type="text"]:hover, input[type="text"]:focus, input[type="text"]:active,input[type="email"]:hover,input[type="tel"]:hover,input[type="date"]:hover,input[type="date"],input[type="date"]:hover,input[type="date"]:active,input[type="date"]:active,input[type="date"]:active,input[type="email"]:active,input[type="tel"]:active, select:hover, select:focus, select:active, textarea:focus, textarea:hover { border: 0 !important; -webkit-appearance:textfield; -moz-appearance:textfield; -webkit-box-sizing:content-box; -moz-box-sizing:content-box; box-sizing:content-box; background:#fff; color:#333; border:1px solid #ddd; -moz-box-shadow:0 1px 1px #ddd, 0 2px 0 #bbb inset; -webkit-box-shadow:0 1px 1px #ddd, 0 1px 0 #bbb inset; box-shadow:0 1px 1px #ddd, 0 1px 0 #bbb inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; outline:none; float: left; }
+#card input[type="text"],input[type="email"],input[type="url"],input[type="tel"],input[type="date"], select, textarea { background-color: #fefefe; border: 0 !important; -webkit-appearance:none !important; -moz-appearance:none !important; -webkit-box-sizing:none !important; -moz-box-sizing:none !important; box-sizing:none !important; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; -moz-border-radius: 0px; -webkit-border-radius: 0px; border-radius: 0px; float: left; }
+#card input[type="text"]:hover, input[type="text"]:focus, input[type="text"]:active,input[type="email"]:hover,input[type="url"]:hover,input[type="tel"]:hover,input[type="date"]:hover,input[type="date"],input[type="date"]:hover,input[type="date"]:active,input[type="date"]:active,input[type="date"]:active,input[type="email"]:active,input[type="url"]:active,input[type="tel"]:active, select:hover, select:focus, select:active, textarea:focus, textarea:hover { border: 0 !important; -webkit-appearance:textfield; -moz-appearance:textfield; -webkit-box-sizing:content-box; -moz-box-sizing:content-box; box-sizing:content-box; background:#fff; color:#333; border:1px solid #ddd; -moz-box-shadow:0 1px 1px #ddd, 0 2px 0 #bbb inset; -webkit-box-shadow:0 1px 1px #ddd, 0 1px 0 #bbb inset; box-shadow:0 1px 1px #ddd, 0 1px 0 #bbb inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; outline:none; float: left; }
textarea { width: 80%; min-height: 5em; min-width: 30em; margin: 0 !important; padding: 0 !important; outline: 0 !important;}
dl.form { width: 100%; float: left; clear: right; margin: 0; padding: 0; }
.form dt { display: table-cell; clear: left; float: left; width: 7em; margin: 0; padding: 0.8em 0.5em 0 0; text-align:right; text-overflow:ellipsis; o-text-overflow: ellipsis; vertical-align: text-bottom; color: #bbb;/* white-space: pre-wrap; white-space: -moz-pre-wrap !important; white-space: -pre-wrap; white-space: -o-pre-wrap;*/ }
diff --git a/apps/contacts/index.php b/apps/contacts/index.php
index 74b7c43c556..bdb52c123ce 100644
--- a/apps/contacts/index.php
+++ b/apps/contacts/index.php
@@ -66,7 +66,7 @@ $tmpl->assign('phone_types', $phone_types);
$tmpl->assign('email_types', $email_types);
$tmpl->assign('categories', $categories);
$tmpl->assign('addressbooks', $addressbooks);
-$tmpl->assign('contacts', $contacts);
+$tmpl->assign('contacts', $contacts, false);
$tmpl->assign('details', $details );
$tmpl->assign('id',$id);
$tmpl->printPage();
diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js
index a1b9976006d..8ab2a3fbb88 100644
--- a/apps/contacts/js/contacts.js
+++ b/apps/contacts/js/contacts.js
@@ -171,13 +171,14 @@ Contacts={
});*/
// Name has changed. Update it and reorder.
+ // TODO: Take addressbook into account
$('#fn').change(function(){
var name = $('#fn').val().strip_tags();
- var item = $('#contacts [data-id="'+Contacts.UI.Card.id+'"]');
+ var item = $('.contacts li[data-id="'+Contacts.UI.Card.id+'"]');
$(item).find('a').html(name);
Contacts.UI.Card.fn = name;
var added = false;
- $('#contacts li').each(function(){
+ $('.contacts li[data-bookid="'+Contacts.UI.Card.bookid+'"]').each(function(){
if ($(this).text().toLowerCase() > name.toLowerCase()) {
$(this).before(item).fadeIn('fast');
added = true;
@@ -185,7 +186,7 @@ Contacts={
}
});
if(!added) {
- $('#leftcontent ul').append(item);
+ $('#contacts ul[data-id="'+Contacts.UI.Card.bookid+'"]').append(item);
}
Contacts.UI.Contacts.scrollTo(Contacts.UI.Card.id);
});
@@ -245,19 +246,23 @@ Contacts={
honpre:'',
honsuf:'',
data:undefined,
- update:function(id) {
- var newid;
+ update:function(id, bookid) {
+ var newid, firstitem;
if(!id) {
- newid = $('#contacts li:first-child').data('id');
+ firstitem = $('#contacts:first-child li:first-child');
+ if(firstitem.length > 0) {
+ newid = firstitem.data('id');
+ bookid = firstitem.data('bookid');
+ }
} else {
newid = id;
}
- var localLoadContact = function(id) {
- if($('#contacts li').length > 0) {
- $('#leftcontent li[data-id="'+newid+'"]').addClass('active');
+ var localLoadContact = function(newid, bookid) {
+ if($('.contacts li').length > 0) {
+ firstitem.addClass('active');
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){
if(jsondata.status == 'success'){
- Contacts.UI.Card.loadContact(jsondata.data);
+ Contacts.UI.Card.loadContact(jsondata.data, bookid);
} else {
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
@@ -266,19 +271,19 @@ Contacts={
}
// Make sure proper DOM is loaded.
- if(!$('#card')[0]) {
+ if(!$('#card')[0] && newid) {
$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){
if(jsondata.status == 'success'){
$('#rightcontent').html(jsondata.data.page).ready(function() {
Contacts.UI.loadHandlers();
- localLoadContact(newid);
+ localLoadContact(newid, bookid);
});
} else {
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
}
- else if($('#contacts li').length == 0) {
+ else if(!newid) {
// load intro page
$.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){
if(jsondata.status == 'success'){
@@ -291,7 +296,7 @@ Contacts={
});
}
else {
- localLoadContact();
+ localLoadContact(newid, bookid);
}
},
doExport:function() {
@@ -313,13 +318,14 @@ Contacts={
if (jsondata.status == 'success'){
$('#rightcontent').data('id',jsondata.data.id);
var id = jsondata.data.id;
+ var aid = jsondata.data.aid;
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':id},function(jsondata){
if(jsondata.status == 'success'){
- Contacts.UI.Card.loadContact(jsondata.data);
- $('#leftcontent .active').removeClass('active');
+ Contacts.UI.Card.loadContact(jsondata.data, aid);
+ $('#contacts .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 added = false;
- $('#leftcontent ul li').each(function(){
+ $('#contacts ul[data-id="'+aid+'"] li').each(function(){
if ($(this).text().toLowerCase() > Contacts.UI.Card.fn.toLowerCase()) {
$(this).before(item).fadeIn('fast');
added = true;
@@ -327,7 +333,7 @@ Contacts={
}
});
if(!added) {
- $('#leftcontent ul').append(item);
+ $('#contacts ul[data-id="'+aid+'"]').append(item);
}
if(isnew) { // add some default properties
Contacts.UI.Card.addProperty('EMAIL');
@@ -370,8 +376,8 @@ Contacts={
if(answer == true) {
$.post(OC.filePath('contacts', 'ajax', 'deletecard.php'),{'id':Contacts.UI.Card.id},function(jsondata){
if(jsondata.status == 'success'){
- var newid = '';
- var curlistitem = $('#leftcontent [data-id="'+jsondata.data.id+'"]');
+ var newid = '', bookid;
+ var curlistitem = $('#contacts li[data-id="'+jsondata.data.id+'"]');
var newlistitem = curlistitem.prev();
if(newlistitem == undefined) {
newlistitem = curlistitem.next();
@@ -379,13 +385,14 @@ Contacts={
curlistitem.remove();
if(newlistitem != undefined) {
newid = newlistitem.data('id');
+ bookid = newlistitem.data('id');
}
$('#rightcontent').data('id',newid);
this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = '';
this.data = undefined;
- if($('#contacts li').length > 0) { // Load first in list.
- Contacts.UI.Card.update(newid);
+ if($('.contacts li').length > 0) { // Load first in list.
+ Contacts.UI.Card.update(newid, bookid);
} else {
// load intro page
$.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){
@@ -408,9 +415,10 @@ Contacts={
});
return false;
},
- loadContact:function(jsondata){
+ loadContact:function(jsondata, bookid){
this.data = jsondata;
this.id = this.data.id;
+ this.bookid = bookid;
$('#rightcontent').data('id',this.id);
this.populateNameFields();
this.loadPhoto();
@@ -1498,40 +1506,54 @@ Contacts={
update:function(){
$.getJSON(OC.filePath('contacts', 'ajax', 'contacts.php'),{},function(jsondata){
if(jsondata.status == 'success'){
- $('#contacts').html(jsondata.data.page);
+ $('#contacts').html(jsondata.data.page).ready(function() {
+ /*setTimeout(function() {
+ $('.contacts li').unbind('inview');
+ $('.contacts li:visible').bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
+ if (isInView) {
+ if (!$(this).find('a').attr('style')) {
+ $(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
+ }
+ }
+ })}, 100);
+ setTimeout(Contacts.UI.Contacts.lazyupdate, 500);*/
+ });
Contacts.UI.Card.update();
}
else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
- setTimeout(function() {
- $('#contacts li').unbind('inview');
- $('#contacts li').bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
+ /*setTimeout(function() {
+ $('.contacts li').unbind('inview');
+ $('.contacts li:visible').bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
if (isInView) {
if (!$(this).find('a').attr('style')) {
$(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
}
}
})}, 500);
- setTimeout(Contacts.UI.Contacts.lazyupdate, 500);
+ setTimeout(Contacts.UI.Contacts.lazyupdate, 500);*/
},
// Add thumbnails to the contact list as they become visible in the viewport.
lazyupdate:function(){
- $('#contacts li').live('inview', function(){
+ $('.contacts li').live('inview', function(){
if (!$(this).find('a').attr('style')) {
$(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
}
});
},
refreshThumbnail:function(id){
- var item = $('#contacts [data-id="'+id+'"]').find('a');
+ var item = $('.contacts li[data-id="'+id+'"]').find('a');
item.html(Contacts.UI.Card.fn);
item.css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+id+'&refresh=1'+Math.random()+') no-repeat');
},
scrollTo:function(id){
- $('#contacts').animate({
- scrollTop: $('#leftcontent li[data-id="'+id+'"]').offset().top-20}, 'slow','swing');
+ var item = $('#contacts li[data-id="'+id+'"]');
+ if(item) {
+ $('.contacts').animate({
+ scrollTop: $('#contacts li[data-id="'+id+'"]').offset().top-20}, 'slow','swing');
+ }
}
}
}
@@ -1552,24 +1574,25 @@ $(document).ready(function(){
$('#contacts_newcontact').keydown(Contacts.UI.Card.editNew);
// Load a contact.
- $('#contacts').keydown(function(event) {
+ $('.contacts').keydown(function(event) {
if(event.which == 13) {
- $('#contacts').click();
+ $('.contacts').click();
}
});
- $('#contacts').click(function(event){
+ $(document).on('click', '.contacts', function(event){
var $tgt = $(event.target);
if ($tgt.is('li') || $tgt.is('a')) {
var item = $tgt.is('li')?$($tgt):($tgt).parent();
var id = item.data('id');
+ var bookid = item.data('bookid');
item.addClass('active');
var oldid = $('#rightcontent').data('id');
if(oldid != 0){
- $('#contacts li[data-id="'+oldid+'"]').removeClass('active');
+ $('.contacts li[data-id="'+oldid+'"]').removeClass('active');
}
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':id},function(jsondata){
if(jsondata.status == 'success'){
- Contacts.UI.Card.loadContact(jsondata.data);
+ Contacts.UI.Card.loadContact(jsondata.data, bookid);
}
else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
@@ -1579,7 +1602,12 @@ $(document).ready(function(){
return false;
});
- $('#contacts li').bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
+ $(document).on('click', '.addressbook', function(event){
+ $(this).next().slideToggle(300);
+ return false;
+ });
+
+ /*$('.contacts li').bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
if (isInView) { //NOTE: I've kept all conditions for future reference ;-)
// element is now visible in the viewport
if (visiblePartY == 'top') {
@@ -1591,14 +1619,14 @@ $(document).ready(function(){
if (!$(this).find('a').attr('style')) {
//alert($(this).data('id') + ' has background: ' + $(this).attr('style'));
$(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
- }/* else {
- alert($(this).data('id') + ' has style ' + $(this).attr('style').match('url'));
- }*/
+ }// else {
+ // alert($(this).data('id') + ' has style ' + $(this).attr('style').match('url'));
+ //}
}
} else {
// element has gone out of viewport
}
- });
+ });*/
$('.contacts_property').live('change', function(){
Contacts.UI.Card.saveProperty(this);
@@ -1677,4 +1705,7 @@ $(document).ready(function(){
}
$('#contacts_propertymenu_dropdown a').click(propertyMenuItem);
$('#contacts_propertymenu_dropdown a').keydown(propertyMenuItem);
+
+ Contacts.UI.loadHandlers();
+ Contacts.UI.Contacts.update();
});
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index 79445ceeee1..878d8835f94 100644
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -172,12 +172,11 @@ class OC_Contacts_Addressbook{
if(!$prefbooks){
$addressbooks = OC_Contacts_Addressbook::all($uid);
if(count($addressbooks) == 0){
- OC_Contacts_Addressbook::add($uid,'default','Default Address Book');
- $addressbooks = OC_Contacts_Addressbook::all($uid);
+ $id = OC_Contacts_Addressbook::add($uid,'default','Default Address Book');
+ self::setActive($id, true);
}
- $prefbooks = $addressbooks[0]['id'];
- OCP\Config::setUserValue($uid,'contacts','openaddressbooks',$prefbooks);
}
+ $prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null);
return explode(';',$prefbooks);
}
@@ -195,7 +194,7 @@ class OC_Contacts_Addressbook{
$stmt = OCP\DB::prepare( $prep );
$result = $stmt->execute($active);
} catch(Exception $e) {
- OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
+ OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OCP\Util::ERROR);
OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active, ids: '.join(',', $active),OCP\Util::DEBUG);
OCP\Util::writeLog('contacts','OC_Contacts_Addressbook::active, SQL:'.$prep,OCP\Util::DEBUG);
}
@@ -210,7 +209,7 @@ class OC_Contacts_Addressbook{
/**
* @brief Activates an addressbook
* @param integer $id
- * @param integer $name
+ * @param boolean $active
* @return boolean
*/
public static function setActive($id,$active){
@@ -256,11 +255,15 @@ class OC_Contacts_Addressbook{
* @return boolean
*/
public static function delete($id){
- // FIXME: There's no error checking at all.
self::setActive($id, false);
- $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
- $stmt->execute(array($id));
-
+ try {
+ $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
+ $stmt->execute(array($id));
+ } catch(Exception $e) {
+ OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:delete:, exception for '.$id.': '.$e->getMessage(),OCP\Util::ERROR);
+ return false;
+ }
+
$cards = OC_Contacts_VCard::all($id);
foreach($cards as $card){
OC_Contacts_VCard::delete($card['id']);
diff --git a/apps/contacts/lib/hooks.php b/apps/contacts/lib/hooks.php
index e3d5df3d51f..e74b465a47b 100644
--- a/apps/contacts/lib/hooks.php
+++ b/apps/contacts/lib/hooks.php
@@ -56,7 +56,7 @@ class OC_Contacts_Hooks{
static public function getBirthdayEvents($parameters) {
$name = $parameters['calendar_id'];
- if (strpos('birthday_', $name) != 0) {
+ if (strpos($name, 'birthday_') != 0) {
return;
}
$info = explode('_', $name);
diff --git a/apps/contacts/lib/search.php b/apps/contacts/lib/search.php
index 144138a7c2c..19330fa9be1 100644
--- a/apps/contacts/lib/search.php
+++ b/apps/contacts/lib/search.php
@@ -2,17 +2,10 @@
class OC_Search_Provider_Contacts extends OC_Search_Provider{
function search($query){
$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
-// if(count($calendars)==0 || !OCP\App::isEnabled('contacts')){
-// //return false;
-// }
- // NOTE: Does the following do anything
- $results=array();
- $searchquery=array();
- if(substr_count($query, ' ') > 0){
- $searchquery = explode(' ', $query);
- }else{
- $searchquery[] = $query;
+ if(count($addressbooks)==0 || !OCP\App::isEnabled('contacts')){
+ return array();
}
+ $results=array();
$l = new OC_l10n('contacts');
foreach($addressbooks as $addressbook){
$vcards = OC_Contacts_VCard::all($addressbook['id']);
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 71a874d783b..110d721ace0 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -56,7 +56,7 @@ class OC_Contacts_VCard{
$stmt = OCP\DB::prepare( $prep );
$result = $stmt->execute($id);
} catch(Exception $e) {
- OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
+ OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::ERROR);
OCP\Util::writeLog('contacts','OC_Contacts_VCard:all, ids: '.join(',', $id),OCP\Util::DEBUG);
OCP\Util::writeLog('contacts','SQL:'.$prep,OCP\Util::DEBUG);
}
diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php
index 7d212e71ba8..d16356d4a56 100644
--- a/apps/contacts/templates/index.php
+++ b/apps/contacts/templates/index.php
@@ -3,16 +3,15 @@
var categories = <?php echo json_encode($_['categories']); ?>;
var lang = '<?php echo OCP\Config::getUserValue(OCP\USER::getUser(), 'core', 'lang', 'en'); ?>';
</script>
-<div id="leftcontent" class="leftcontent">
- <ul id="contacts">
- <?php echo $this->inc("part.contacts"); ?>
- </ul>
-</div>
-<div id="bottomcontrols">
- <form>
- <button class="svg" id="contacts_newcontact" title="<?php echo $l->t('Add Contact'); ?>"><img class="svg" src="<?php echo OCP\Util::linkTo('contacts', 'img/contact-new.svg'); ?>" alt="<?php echo $l->t('Add Contact'); ?>" /></button>
- <button class="svg" id="chooseaddressbook" title="<?php echo $l->t('Addressbooks'); ?>"><img class="svg" src="core/img/actions/settings.svg" alt="<?php echo $l->t('Addressbooks'); ?>" /></button>
- </form>
+<div id="leftcontent">
+ <div id="contacts">
+ </div>
+ <div id="bottomcontrols">
+ <form>
+ <button class="svg" id="contacts_newcontact" title="<?php echo $l->t('Add Contact'); ?>"><img class="svg" src="<?php echo OCP\Util::linkTo('contacts', 'img/contact-new.svg'); ?>" alt="<?php echo $l->t('Add Contact'); ?>" /></button>
+ <button class="svg" id="chooseaddressbook" title="<?php echo $l->t('Addressbooks'); ?>"><img class="svg" src="core/img/actions/settings.svg" alt="<?php echo $l->t('Addressbooks'); ?>" /></button>
+ </form>
+ </div>
</div>
<div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>">
<?php
diff --git a/apps/contacts/templates/part.contact.php b/apps/contacts/templates/part.contact.php
index ca682baaf80..5757563fe5b 100644
--- a/apps/contacts/templates/part.contact.php
+++ b/apps/contacts/templates/part.contact.php
@@ -33,15 +33,15 @@ $id = isset($_['id']) ? $_['id'] : '';
</span>
<dl id="identityprops" class="form">
<dt class="hidden" id="org_label" data-element="ORG"><label for="org"><?php echo $l->t('Organization'); ?></label></dt>
- <dd class="propertycontainer hidden" id="org_value" data-element="ORG"><input id="org" required="required" name="value[ORG]" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('Organization'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
+ <dd class="propertycontainer hidden" id="org_value" data-element="ORG"><input id="org" required="required" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('Organization'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
<dt class="hidden" id="nickname_label" data-element="NICKNAME"><label for="nickname"><?php echo $l->t('Nickname'); ?></label></dt>
- <dd class="propertycontainer hidden" id="nickname_value" data-element="NICKNAME"><input id="nickname" required="required" name="value[NICKNAME]" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('Enter nickname'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
+ <dd class="propertycontainer hidden" id="nickname_value" data-element="NICKNAME"><input id="nickname" required="required" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('Enter nickname'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
<dt class="hidden" id="url_label" data-element="URL"><label for="url"><?php echo $l->t('Web site'); ?></label></dt>
- <dd class="propertycontainer hidden" id="url_value" data-element="URL"><input id="url" required="required" name="value[URL]" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('http://www.somesite.com'); ?>" /><a role="button" class="action globe" title="<?php echo $l->t('Go to web site'); ?>"><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
+ <dd class="propertycontainer hidden" id="url_value" data-element="URL"><input id="url" required="required" type="url" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('http://www.somesite.com'); ?>" /><a role="button" class="action globe" title="<?php echo $l->t('Go to web site'); ?>"><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
<dt class="hidden" id="bday_label" data-element="BDAY"><label for="bday"><?php echo $l->t('Birthday'); ?></label></dt>
<dd class="propertycontainer hidden" id="bday_value" data-element="BDAY"><input id="bday" required="required" name="value" type="text" class="contacts_property big" value="" placeholder="<?php echo $l->t('dd-mm-yyyy'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
<dt class="hidden" id="categories_label" data-element="CATEGORIES"><label for="categories"><?php echo $l->t('Groups'); ?></label></dt>
- <dd class="propertycontainer hidden" id="categories_value" data-element="CATEGORIES"><input id="categories" required="required" name="value[CATEGORIES]" type="text" class="contacts_property bold" name="value" value="" placeholder="
+ <dd class="propertycontainer hidden" id="categories_value" data-element="CATEGORIES"><input id="categories" required="required" type="text" class="contacts_property bold" name="value" value="" placeholder="
<?php echo $l->t('Separate groups with commas'); ?>" />
<a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a><a role="button" class="action edit" title="<?php echo $l->t('Edit groups'); ?>"></a></dd>
</dl>
@@ -121,19 +121,3 @@ $id = isset($_['id']) ? $_['id'] : '';
<div id="edit_photo_dialog" title="Edit photo">
<div id="edit_photo_dialog_img"></div>
</div>
-<script language="Javascript">
-$(document).ready(function(){
- if('<?php echo $id; ?>'!='') {
- $.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':'<?php echo $id; ?>'},function(jsondata){
- if(jsondata.status == 'success'){
- $('#leftcontent li[data-id="<?php echo $id; ?>"]').addClass('active');
- Contacts.UI.Card.loadContact(jsondata.data);
- Contacts.UI.loadHandlers();
- }
- else{
- OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
- }
- });
- }
-});
-</script>
diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php
index 00a61f72fdd..f0b14c8e5f2 100644
--- a/apps/contacts/templates/part.contacts.php
+++ b/apps/contacts/templates/part.contacts.php
@@ -1,12 +1,10 @@
-<?php foreach( $_['contacts'] as $contact ):
- $display = trim($contact['fullname']);
- if(!$display) {
- $vcard = OC_Contacts_App::getContactVCard($contact['id']);
- if(!is_null($vcard)) {
- $struct = OC_Contacts_VCard::structureContact($vcard);
- $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]';
- }
+<?php
+foreach($_['books'] as $id => $addressbook) {
+ echo '<h3 class="addressbook" data-id="'.$id.'">'.$addressbook['displayname'].'</h3>';
+ echo '<ul class="contacts hidden" data-id="'.$id.'">';
+ foreach($addressbook['contacts'] as $contact) {
+ echo '<li role="button" data-bookid="'.$contact['addressbookid'].'" data-id="'.$contact['id'].'"><a href="index.php?id='.$contact['id'].'" style="background: url('.link_to('contacts','thumbnail.php').'?id='.$contact['id'].') no-repeat scroll 0 0 transparent;">'.$contact['displayname'].'</a></li>';
}
+ echo '</ul>';
+}
?>
- <li role="button" book-id="<?php echo $contact['addressbookid']; ?>" data-id="<?php echo $contact['id']; ?>"><a href="index.php?id=<?php echo $contact['id']; ?>"><?php echo $display; ?></a></li>
-<?php endforeach; ?>
diff --git a/apps/contacts/templates/part.cropphoto.php b/apps/contacts/templates/part.cropphoto.php
index 1079afc808a..6d7b1e44777 100644
--- a/apps/contacts/templates/part.cropphoto.php
+++ b/apps/contacts/templates/part.cropphoto.php
@@ -4,7 +4,7 @@ $tmpkey = $_['tmpkey'];
$requesttoken = $_['requesttoken'];
OCP\Util::writeLog('contacts','templates/part.cropphoto.php: tmpkey: '.$tmpkey, OCP\Util::DEBUG);
?>
-<script language="Javascript">
+<script type="text/javascript">
jQuery(function($) {
$('#cropbox').Jcrop({
onChange: showCoords,
diff --git a/apps/contacts/templates/part.edit_address_dialog.php b/apps/contacts/templates/part.edit_address_dialog.php
index 7684795f348..d5ea95ba465 100644
--- a/apps/contacts/templates/part.edit_address_dialog.php
+++ b/apps/contacts/templates/part.edit_address_dialog.php
@@ -1,13 +1,9 @@
<?php
$adr = isset($_['adr'])?$_['adr']:array();
-$id = $_['id'];
-$types = array();
-foreach(isset($adr['parameters']['TYPE'])?array($adr['parameters']['TYPE']):array() as $type) {
- $types[] = strtoupper($type);
-}
+$id = isset($_['id'])?$_['id']:array();
+$types = isset($_['types'])?$_['types']:array();
?>
<div id="edit_address_dialog" title="<?php echo $l->t('Edit address'); ?>">
-<!-- ?php print_r($types); ? -->
<fieldset id="address">
<dl class="form">
<dt>
@@ -22,43 +18,43 @@ foreach(isset($adr['parameters']['TYPE'])?array($adr['parameters']['TYPE']):arra
<label class="label" for="adr_pobox"><?php echo $l->t('PO Box'); ?></label>
</dt>
<dd>
- <input type="text" id="adr_pobox" name="value[ADR][0]" placeholder="<?php echo $l->t('PO Box'); ?>" value="<?php echo isset($adr['value'][0])?$adr['value'][0]:''; ?>">
+ <input type="text" id="adr_pobox" name="value[ADR][0]" placeholder="<?php echo $l->t('PO Box'); ?>" value="<?php echo isset($adr[0])?$adr[0]:''; ?>">
</dd>
<dt>
<label class="label" for="adr_street"><?php echo $l->t('Street address'); ?></label>
</dt>
<dd>
- <input type="text" id="adr_street" name="value[ADR][2]" placeholder="<?php echo $l->t('Street and number'); ?>" value="<?php echo isset($adr['value'][2])?$adr['value'][2]:''; ?>">
+ <input type="text" id="adr_street" name="value[ADR][2]" placeholder="<?php echo $l->t('Street and number'); ?>" value="<?php echo isset($adr[2])?$adr[2]:''; ?>">
</dd>
<dt>
<label class="label" for="adr_extended"><?php echo $l->t('Extended'); ?></label>
</dt>
<dd>
- <input type="text" id="adr_extended" name="value[ADR][1]" placeholder="<?php echo $l->t('Apartment number etc.'); ?>" value="<?php echo isset($adr['value'][1])?$adr['value'][1]:''; ?>">
+ <input type="text" id="adr_extended" name="value[ADR][1]" placeholder="<?php echo $l->t('Apartment number etc.'); ?>" value="<?php echo isset($adr[1])?$adr[1]:''; ?>">
</dd>
<dt>
<label class="label" for="adr_city"><?php echo $l->t('City'); ?></label>
</dt>
<dd>
- <input type="text" id="adr_city" name="value[ADR][3]" placeholder="<?php echo $l->t('City'); ?>" value="<?php echo isset($adr['value'][3])?$adr['value'][3]:''; ?>">
+ <input type="text" id="adr_city" name="value[ADR][3]" placeholder="<?php echo $l->t('City'); ?>" value="<?php echo isset($adr[3])?$adr[3]:''; ?>">
</dd>
<dt>
<label class="label" for="adr_region"><?php echo $l->t('Region'); ?></label>
</dt>
<dd>
- <input type="text" id="adr_region" name="value[ADR][4]" placeholder="<?php echo $l->t('E.g. state or province'); ?>" value="<?php echo isset($adr['value'][4])?$adr['value'][4]:''; ?>">
+ <input type="text" id="adr_region" name="value[ADR][4]" placeholder="<?php echo $l->t('E.g. state or province'); ?>" value="<?php echo isset($adr[4])?$adr[4]:''; ?>">
</dd>
<dt>
<label class="label" for="adr_zipcode"><?php echo $l->t('Zipcode'); ?></label>
</dt>
<dd>
- <input type="text" id="adr_zipcode" name="value[ADR][5]" placeholder="<?php echo $l->t('Postal code'); ?>" value="<?php echo isset($adr['value'][5])?$adr['value'][5]:''; ?>">
+ <input type="text" id="adr_zipcode" name="value[ADR][5]" placeholder="<?php echo $l->t('Postal code'); ?>" value="<?php echo isset($adr[5])?$adr[5]:''; ?>">
</dd>
<dt>
<label class="label" for="adr_country"><?php echo $l->t('Country'); ?></label>
</dt>
<dd>
- <input type="text" id="adr_country" name="value[ADR][6]" placeholder="<?php echo $l->t('Country'); ?>" value="<?php echo isset($adr['value'][6])?$adr['value'][6]:''; ?>">
+ <input type="text" id="adr_country" name="value[ADR][6]" placeholder="<?php echo $l->t('Country'); ?>" value="<?php echo isset($adr[6])?$adr[6]:''; ?>">
</dd>
</dl>
</fieldset>
diff --git a/apps/contacts/templates/part.edit_name_dialog.php b/apps/contacts/templates/part.edit_name_dialog.php
index be45f9a5b06..f984c232a30 100644
--- a/apps/contacts/templates/part.edit_name_dialog.php
+++ b/apps/contacts/templates/part.edit_name_dialog.php
@@ -22,7 +22,7 @@ $addressbooks = isset($_['addressbooks'])?$_['addressbooks']:null;
<?php }} ?>
<dt><label for="pre"><?php echo $l->t('Hon. prefixes'); ?></label></dt>
<dd>
- <input name="pre" id="pre" value="<?php echo isset($name['value'][3]) ? $name['value'][3] : ''; ?>" type="text" list="prefixes" />
+ <input name="pre" id="pre" value="<?php echo isset($name[3]) ? $name[3] : ''; ?>" type="text" list="prefixes" />
<datalist id="prefixes">
<option value="<?php echo $l->t('Miss'); ?>">
<option value="<?php echo $l->t('Ms'); ?>">
@@ -33,14 +33,14 @@ $addressbooks = isset($_['addressbooks'])?$_['addressbooks']:null;
</datalist>
</dd>
<dt><label for="giv"><?php echo $l->t('Given name'); ?></label></dt>
- <dd><input name="giv" id="giv" value="<?php echo isset($name['value'][1]) ? $name['value'][1] : ''; ?>" type="text" /></dd>
+ <dd><input name="giv" id="giv" value="<?php echo isset($name[1]) ? $name[1] : ''; ?>" type="text" /></dd>
<dt><label for="add"><?php echo $l->t('Additional names'); ?></label></dt>
- <dd><input name="add" id="add" value="<?php echo isset($name['value'][2]) ? $name['value'][2] : ''; ?>" type="text" /></dd>
+ <dd><input name="add" id="add" value="<?php echo isset($name[2]) ? $name[2] : ''; ?>" type="text" /></dd>
<dt><label for="fam"><?php echo $l->t('Family name'); ?></label></dt>
- <dd><input name="fam" id="fam" value="<?php echo isset($name['value'][0]) ? $name['value'][0] : ''; ?>" type="text" /></dd>
+ <dd><input name="fam" id="fam" value="<?php echo isset($name[0]) ? $name[0] : ''; ?>" type="text" /></dd>
<dt><label for="suf"><?php echo $l->t('Hon. suffixes'); ?></label></dt>
<dd>
- <input name="suf" id="suf" value="<?php echo isset($name['value'][4]) ? $name['value'][4] : ''; ?>" type="text" list="suffixes" />
+ <input name="suf" id="suf" value="<?php echo isset($name[4]) ? $name[4] : ''; ?>" type="text" list="suffixes" />
<datalist id="suffixes">
<option value="<?php echo $l->t('J.D.'); ?>">
<option value="<?php echo $l->t('M.D.'); ?>">