aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-03-29 15:24:32 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-03-29 15:25:24 +0200
commit11f7eeb63a441a71ab90ea31001471562215a94d (patch)
treeebf1721cc08f9b483fd9561560fe2c06333fc828
parentb559952806d1af4e20853d60fc339828b28b9a71 (diff)
downloadnextcloud-server-11f7eeb63a441a71ab90ea31001471562215a94d.tar.gz
nextcloud-server-11f7eeb63a441a71ab90ea31001471562215a94d.zip
Improve actions on delete.
-rw-r--r--apps/contacts/ajax/deletecard.php10
-rw-r--r--apps/contacts/js/contacts.js87
-rw-r--r--apps/contacts/templates/part.contact.php1
3 files changed, 65 insertions, 33 deletions
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
index e26dfd6ebfe..5675aef5f15 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/deletecard.php
@@ -19,6 +19,11 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
+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/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js
index e1827027453..d314878cc0a 100644
--- a/apps/contacts/js/contacts.js
+++ b/apps/contacts/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/apps/contacts/templates/part.contact.php b/apps/contacts/templates/part.contact.php
index a93069fa722..7e6dedb843b 100644
--- a/apps/contacts/templates/part.contact.php
+++ b/apps/contacts/templates/part.contact.php
@@ -131,6 +131,7 @@ $(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);
}
else{