1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-01 13:24:10 +01:00
OwncloudContactsOfficial/js/interface.js

166 lines
5.3 KiB
JavaScript
Raw Normal View History

2011-08-06 22:32:06 +02:00
$(document).ready(function(){
2011-09-08 23:36:47 +02:00
/*-------------------------------------------------------------------------
* Actions for startup
*-----------------------------------------------------------------------*/
if( $('#leftcontent li').length > 0 ){
$('#leftcontent li').first().addClass('active');
}
2011-08-09 13:53:58 +02:00
2011-09-08 23:36:47 +02:00
/*-------------------------------------------------------------------------
* Event handlers
*-----------------------------------------------------------------------*/
2011-08-11 10:08:02 +02:00
$('#leftcontent li').live('click',function(){
var id = $(this).data('id');
2011-09-08 23:36:47 +02:00
var oldid = $('#rightcontent').data('id');
if(oldid != 0){
$('#leftcontent li[data-id="'+oldid+'"]').removeClass('active');
}
2011-08-09 13:53:58 +02:00
$.getJSON('ajax/getdetails.php',{'id':id},function(jsondata){
2011-08-06 22:32:06 +02:00
if(jsondata.status == 'success'){
2011-08-11 10:08:02 +02:00
$('#rightcontent').data('id',jsondata.data.id);
$('#rightcontent').html(jsondata.data.page);
2011-09-08 23:36:47 +02:00
$('#leftcontent li[data-id="'+jsondata.data.id+'"]').addClass('active');
2011-08-06 22:32:06 +02:00
}
else{
alert(jsondata.data.message);
}
});
return false;
});
2011-08-06 23:29:25 +02:00
2011-08-09 13:53:58 +02:00
$('#contacts_deletecard').live('click',function(){
2011-08-11 10:08:02 +02:00
var id = $('#rightcontent').data('id');
2011-08-09 13:53:58 +02:00
$.getJSON('ajax/deletecard.php',{'id':id},function(jsondata){
if(jsondata.status == 'success'){
2011-08-11 10:08:02 +02:00
$('#leftcontent [data-id="'+jsondata.data.id+'"]').remove();
$('#rightcontent').data('id','');
$('#rightcontent').empty();
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
});
return false;
});
$('#contacts_addproperty').live('click',function(){
2011-08-11 10:08:02 +02:00
var id = $('#rightcontent').data('id');
2011-08-09 13:53:58 +02:00
$.getJSON('ajax/showaddproperty.php',{'id':id},function(jsondata){
if(jsondata.status == 'success'){
2011-08-11 10:08:02 +02:00
$('#rightcontent').append(jsondata.data.page);
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
});
2011-08-06 23:29:25 +02:00
return false;
});
2011-08-09 13:53:58 +02:00
$('#contacts_addpropertyform [name="name"]').live('change',function(){
$('#contacts_addpropertyform #contacts_addresspart').remove();
$('#contacts_addpropertyform #contacts_phonepart').remove();
$('#contacts_addpropertyform #contacts_fieldpart').remove();
$('#contacts_addpropertyform #contacts_generic').remove();
if($(this).val() == 'ADR'){
$('#contacts_addresspart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
}
else if($(this).val() == 'TEL'){
$('#contacts_phonepart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
}
else{
$('#contacts_generic').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
}
});
$('#contacts_addpropertyform input[type="submit"]').live('click',function(){
$.post('ajax/addproperty.php',$('#contacts_addpropertyform').serialize(),function(jsondata){
if(jsondata.status == 'success'){
2011-10-07 23:01:44 +02:00
$('#contacts_details').append(jsondata.data.page);
2011-08-09 13:53:58 +02:00
$('#contacts_addpropertyform').remove();
$('#contacts_addcontactsparts').remove();
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
}, 'json');
return false;
});
$('#contacts_newcontact').click(function(){
$.getJSON('ajax/showaddcard.php',{},function(jsondata){
if(jsondata.status == 'success'){
2011-08-11 10:08:02 +02:00
$('#rightcontent').data('id','');
$('#rightcontent').html(jsondata.data.page);
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
});
return false;
});
$('#contacts_addcardform input[type="submit"]').live('click',function(){
$.post('ajax/addcard.php',$('#contacts_addcardform').serialize(),function(jsondata){
if(jsondata.status == 'success'){
2011-08-11 10:08:02 +02:00
$('#rightcontent').data('id',jsondata.data.id);
$('#rightcontent').html(jsondata.data.page);
$('#leftcontent .active').removeClass('active');
$('#leftcontent ul').append('<li data-id="'+jsondata.data.id+'" class="active"><a href="index.php?id='+jsondata.data.id+'">'+jsondata.data.name+'</a></li>');
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
}, 'json');
return false;
});
2011-08-14 23:48:43 +02:00
$('.contacts_details_property [data-use="edit"]').live('click',function(){
2011-08-11 10:08:02 +02:00
var id = $('#rightcontent').data('id');
var checksum = $(this).parent().parent().data('checksum');
$.getJSON('ajax/showsetproperty.php',{'id': id, 'checksum': checksum },function(jsondata){
2011-08-09 13:53:58 +02:00
if(jsondata.status == 'success'){
2011-08-14 23:48:43 +02:00
$('.contacts_details_property[data-checksum="'+checksum+'"] .contacts_details_right').html(jsondata.data.page);
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
});
return false;
});
$('#contacts_setpropertyform input[type="submit"]').live('click',function(){
2011-10-07 22:38:19 +02:00
$.post('ajax/setproperty.php',$(this).parent('form').serialize(),function(jsondata){
2011-08-09 13:53:58 +02:00
if(jsondata.status == 'success'){
2011-08-14 23:48:43 +02:00
$('.contacts_details_property[data-checksum="'+jsondata.data.oldchecksum+'"]').replaceWith(jsondata.data.page);
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
},'json');
return false;
});
2011-08-14 23:48:43 +02:00
$('.contacts_details_property [data-use="delete"]').live('click',function(){
2011-08-11 10:08:02 +02:00
var id = $('#rightcontent').data('id');
var checksum = $(this).parent().parent().data('checksum');
$.getJSON('ajax/deleteproperty.php',{'id': id, 'checksum': checksum },function(jsondata){
2011-08-09 13:53:58 +02:00
if(jsondata.status == 'success'){
2011-08-14 23:48:43 +02:00
$('.contacts_details_property[data-checksum="'+checksum+'"]').remove();
2011-08-09 13:53:58 +02:00
}
else{
alert(jsondata.data.message);
}
});
return false;
});
2011-08-14 23:48:43 +02:00
$('.contacts_details_property').live('mouseenter',function(){
2011-08-09 13:53:58 +02:00
$(this).find('span').show();
});
2011-08-14 23:48:43 +02:00
$('.contacts_details_property').live('mouseleave',function(){
2011-08-09 13:53:58 +02:00
$(this).find('span').hide();
});
2011-08-06 22:32:06 +02:00
});