diff --git a/ajax/deletecard.php b/ajax/deletecard.php index e26dfd6e..5675aef5 100644 --- a/ajax/deletecard.php +++ b/ajax/deletecard.php @@ -19,6 +19,11 @@ * License along with this library. If not, see . * */ +function bailOut($msg) { + OC_JSON::error(array('data' => array('message' => $msg))); + OC_Log::write('contacts','ajax/saveproperty.php: '.$msg, OC_Log::DEBUG); + exit(); +} // Init owncloud require_once('../../../lib/base.php'); @@ -27,7 +32,10 @@ require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$id = $_GET['id']; +$id = isset($_GET['id'])?$_GET['id']:null; +if(!$id) { + bailOut(OC_Contacts_App::$l10n->t('id is not set.')); +} $card = OC_Contacts_App::getContactObject( $id ); OC_Contacts_VCard::delete($id); diff --git a/js/contacts.js b/js/contacts.js index e1827027..d314878c 100644 --- a/js/contacts.js +++ b/js/contacts.js @@ -213,19 +213,27 @@ Contacts={ honpre:'', honsuf:'', data:undefined, - update:function() { + update:function(id) { // Make sure proper DOM is loaded. - console.log('Card.update(), #n: ' + $('#n').length); + var newid; + console.log('Card.update(), id: ' + id); console.log('Card.update(), #contacts: ' + $('#contacts li').length); - if($('#n').length == 0 && $('#contacts li').length > 0) { + if(id == undefined) { + newid = $('#contacts li:first-child').data('id'); + } else { + newid = id; + } + if($('#contacts li').length > 0) { $.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){ if(jsondata.status == 'success'){ $('#rightcontent').html(jsondata.data.page); Contacts.UI.loadHandlers(); if($('#contacts li').length > 0) { - var firstid = $('#contacts li:first-child').data('id'); - console.log('trying to load: ' + firstid); - $.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':firstid},function(jsondata){ + //var newid = $('#contacts li:first-child').data('id'); + //$('#contacts li:first-child').addClass('active'); + $('#leftcontent li[data-id="'+newid+'"]').addClass('active'); + console.log('trying to load: ' + newid); + $.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){ if(jsondata.status == 'success'){ Contacts.UI.Card.loadContact(jsondata.data); } else{ @@ -300,35 +308,49 @@ Contacts={ } }); }, - delete: function() { + delete:function() { $('#contacts_deletecard').tipsy('hide'); - $.getJSON('ajax/deletecard.php',{'id':this.id},function(jsondata){ - if(jsondata.status == 'success'){ - $('#leftcontent [data-id="'+jsondata.data.id+'"]').remove(); - $('#rightcontent').data('id',''); - //$('#rightcontent').empty(); - this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = ''; - this.data = undefined; - // Load first in list. - if($('#contacts li').length > 0) { - Contacts.UI.Card.update(); - } else { - // load intro page - $.getJSON('ajax/loadintro.php',{},function(jsondata){ - if(jsondata.status == 'success'){ - id = ''; - $('#rightcontent').data('id',''); - $('#rightcontent').html(jsondata.data.page); + OC.dialogs.confirm(t('contacts', 'Are you sure you want to delete this contact?'), t('contacts', 'Warning'), function(answer) { + if(answer == true) { + $.getJSON('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 newlistitem = curlistitem.prev(); + console.log('Previous: ' + newlistitem); + if(newlistitem == undefined) { + newlistitem = curlistitem.next(); } - else{ - OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + curlistitem.remove(); + if(newlistitem != undefined) { + newid = newlistitem.data('id'); } - }); - } - } - else{ - OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); - //alert(jsondata.data.message); + $('#rightcontent').data('id',newid); + //$('#rightcontent').empty(); + this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = ''; + this.data = undefined; + // Load first in list. + if($('#contacts li').length > 0) { + Contacts.UI.Card.update(newid); + } else { + // load intro page + $.getJSON('ajax/loadintro.php',{},function(jsondata){ + if(jsondata.status == 'success'){ + id = ''; + $('#rightcontent').data('id',''); + $('#rightcontent').html(jsondata.data.page); + } + else{ + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + } + }); + } + } + else{ + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + //alert(jsondata.data.message); + } + }); } }); return false; @@ -1232,6 +1254,7 @@ $(document).ready(function(){ */ $('#leftcontent li').live('click',function(){ var id = $(this).data('id'); + $(this).addClass('active'); var oldid = $('#rightcontent').data('id'); if(oldid != 0){ $('#leftcontent li[data-id="'+oldid+'"]').removeClass('active'); diff --git a/templates/part.contact.php b/templates/part.contact.php index a93069fa..7e6dedb8 100644 --- a/templates/part.contact.php +++ b/templates/part.contact.php @@ -131,6 +131,7 @@ $(document).ready(function(){ if(''!='') { $.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':''},function(jsondata){ if(jsondata.status == 'success'){ + $('#leftcontent li[data-id=""]').addClass('active'); Contacts.UI.Card.loadContact(jsondata.data); } else{