Implemented undelete for contacts.
This commit is contained in:
parent
51bafd32d6
commit
e07cd26571
|
@ -18,6 +18,7 @@ Contacts={
|
||||||
* timeout: The timeout in seconds before the notification disappears. Default 10.
|
* timeout: The timeout in seconds before the notification disappears. Default 10.
|
||||||
* timeouthandler: A function to run on timeout.
|
* timeouthandler: A function to run on timeout.
|
||||||
* clickhandler: A function to run on click. If a timeouthandler is given it will be cancelled.
|
* clickhandler: A function to run on click. If a timeouthandler is given it will be cancelled.
|
||||||
|
* data: An object that will be passed as argument to the timeouthandler and clickhandler functions.
|
||||||
*/
|
*/
|
||||||
notify:function(params) {
|
notify:function(params) {
|
||||||
var notifier = $('#notification');
|
var notifier = $('#notification');
|
||||||
|
@ -25,13 +26,22 @@ Contacts={
|
||||||
notifier.fadeIn();
|
notifier.fadeIn();
|
||||||
var timer = setTimeout(function() {
|
var timer = setTimeout(function() {
|
||||||
notifier.fadeOut();
|
notifier.fadeOut();
|
||||||
if(params.timeouthandler && $.isFunction(params.timeouthandler)) { params.timeouthandler();}
|
if(params.timeouthandler && $.isFunction(params.timeouthandler)) {
|
||||||
|
params.timeouthandler(notifier.data(dataid));
|
||||||
|
notifier.off('click');
|
||||||
|
notifier.data(dataid, null);
|
||||||
|
}
|
||||||
}, params.timeout && $.isNumeric(params.timeout) ? parseInt(params.timeout)*1000 : 10000);
|
}, params.timeout && $.isNumeric(params.timeout) ? parseInt(params.timeout)*1000 : 10000);
|
||||||
|
var dataid = timer.toString();
|
||||||
|
if(params.data) {
|
||||||
|
notifier.data(dataid, params.data);
|
||||||
|
}
|
||||||
if(params.clickhandler && $.isFunction(params.clickhandler)) {
|
if(params.clickhandler && $.isFunction(params.clickhandler)) {
|
||||||
notifier.on('click', function() {
|
notifier.on('click', function() {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
notifier.off('click');
|
notifier.off('click');
|
||||||
params.clickhandler();
|
params.clickhandler(notifier.data(dataid));
|
||||||
|
notifier.data(dataid, null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -216,10 +226,10 @@ Contacts={
|
||||||
Contacts.UI.Contacts.scrollTo(Contacts.UI.Card.id);
|
Contacts.UI.Contacts.scrollTo(Contacts.UI.Card.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#contacts_deletecard').click( function() { Contacts.UI.Card.doDelete();return false;} );
|
$('#contacts_deletecard').click( function() { Contacts.UI.Card.delayedDelete();return false;} );
|
||||||
$('#contacts_deletecard').keydown( function(event) {
|
$('#contacts_deletecard').keydown( function(event) {
|
||||||
if(event.which == 13 || event.which == 32) {
|
if(event.which == 13 || event.which == 32) {
|
||||||
Contacts.UI.Card.doDelete();
|
Contacts.UI.Card.delayedDelete();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
@ -450,19 +460,16 @@ Contacts={
|
||||||
localAddcontact(n, fn, aid, isnew);
|
localAddcontact(n, fn, aid, isnew);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
doDelete:function() {
|
delayedDelete:function() {
|
||||||
$('#contacts_deletecard').tipsy('hide');
|
$('#contacts_deletecard').tipsy('hide');
|
||||||
OC.dialogs.confirm(t('contacts', 'Are you sure you want to delete this contact?'), t('contacts', 'Warning'), function(answer) {
|
|
||||||
if(answer == true) {
|
|
||||||
$.post(OC.filePath('contacts', 'ajax', 'deletecard.php'),{'id':Contacts.UI.Card.id},function(jsondata){
|
|
||||||
if(jsondata.status == 'success'){
|
|
||||||
var newid = '', bookid;
|
var newid = '', bookid;
|
||||||
var curlistitem = $('#contacts li[data-id="'+jsondata.data.id+'"]');
|
var curlistitem = $('#contacts li[data-id="'+Contacts.UI.Card.id+'"]');
|
||||||
|
curlistitem.removeClass('active');
|
||||||
var newlistitem = curlistitem.prev('li');
|
var newlistitem = curlistitem.prev('li');
|
||||||
if(!newlistitem) {
|
if(!newlistitem) {
|
||||||
newlistitem = curlistitem.next('li');
|
newlistitem = curlistitem.next('li');
|
||||||
}
|
}
|
||||||
curlistitem.remove();
|
curlistitem.detach();
|
||||||
if($(newlistitem).is('li')) {
|
if($(newlistitem).is('li')) {
|
||||||
newid = newlistitem.data('id');
|
newid = newlistitem.data('id');
|
||||||
bookid = newlistitem.data('bookid');
|
bookid = newlistitem.data('bookid');
|
||||||
|
@ -486,11 +493,23 @@ Contacts={
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
Contacts.UI.notify({
|
||||||
else{
|
data:curlistitem,
|
||||||
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
|
message:t('contacts','Click to undo deletion of "') + curlistitem.find('a').text() + '"',
|
||||||
|
timeouthandler:function(contact) {
|
||||||
|
Contacts.UI.Card.doDelete(contact.data('id'));
|
||||||
|
delete contact;
|
||||||
|
},
|
||||||
|
clickhandler:function(contact) {
|
||||||
|
Contacts.UI.Contacts.insertContact({contact:contact});
|
||||||
|
Contacts.UI.notify({message:t('contacts', 'Cancelled deletion of: "') + curlistitem.find('a').text() + '"'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
doDelete:function(id) {
|
||||||
|
$.post(OC.filePath('contacts', 'ajax', 'deletecard.php'),{'id':id},function(jsondata) {
|
||||||
|
if(jsondata.status == 'error'){
|
||||||
|
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
@ -1516,17 +1535,20 @@ Contacts={
|
||||||
alert('Dropping address books not implemented yet');
|
alert('Dropping address books not implemented yet');
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @params params An object with the propeties 'contactlist':a jquery object of the ul to insert into,
|
* @params params An object with the properties 'contactlist':a jquery object of the ul to insert into,
|
||||||
* 'contacts':a jquery object of all items in the list and either 'data': an object with the properties
|
* 'contacts':a jquery object of all items in the list and either 'data': an object with the properties
|
||||||
* id, addressbookid and displayname or 'contact': a listitem to be inserted directly.
|
* id, addressbookid and displayname or 'contact': a listitem to be inserted directly.
|
||||||
* If 'contacts' is defined the new contact will be inserted alphabetically into the list, otherwise
|
* If 'contactlist' or 'contacts' aren't defined they will be search for based in the properties in 'data'.
|
||||||
* it will be appended.
|
|
||||||
*/
|
*/
|
||||||
insertContact:function(params) {
|
insertContact:function(params) {
|
||||||
if(!params.contactlist) {
|
if(!params.contactlist) {
|
||||||
params['contactlist'] = params.data
|
// FIXME: Check if contact really exists.
|
||||||
? $('#contacts ul[data-id="'+params.data.addressbookid+'"]')
|
var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
|
||||||
: contact.data('bookid');
|
params.contactlist = $('#contacts ul[data-id="'+bookid+'"]');
|
||||||
|
}
|
||||||
|
if(!params.contacts) {
|
||||||
|
var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid');
|
||||||
|
params.contacts = $('#contacts ul[data-id="'+bookid+'"] li');
|
||||||
}
|
}
|
||||||
var contact = params.data
|
var contact = params.data
|
||||||
? $('<li data-id="'+params.data.id+'" data-bookid="'+params.data.addressbookid+'" role="button"><a href="'+OC.linkTo('contacts', 'index.php')+'&id='+params.data.id+'" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+params.data.id+') no-repeat scroll 0% 0% transparent;">'+params.data.displayname+'</a></li>')
|
? $('<li data-id="'+params.data.id+'" data-bookid="'+params.data.addressbookid+'" role="button"><a href="'+OC.linkTo('contacts', 'index.php')+'&id='+params.data.id+'" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+params.data.id+') no-repeat scroll 0% 0% transparent;">'+params.data.displayname+'</a></li>')
|
||||||
|
|
Loading…
Reference in New Issue