2012-02-06 07:32:57 +01:00
function ucwords ( str ) {
return ( str + '' ) . replace ( /^([a-z])|\s+([a-z])/g , function ( $1 ) {
return $1 . toUpperCase ( ) ;
} ) ;
}
String . prototype . strip _tags = function ( ) {
tags = this ;
stripped = tags . replace ( /[\<\>]/gi , "" ) ;
return stripped ;
2012-02-21 22:31:35 +01:00
} ;
2012-02-06 07:32:57 +01:00
Contacts = {
UI : {
notImplemented : function ( ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'Sorry, this functionality has not been implemented yet' ) , t ( 'contacts' , 'Not implemented' ) ) ;
2012-02-06 07:32:57 +01:00
} ,
searchOSM : function ( obj ) {
var adr = Contacts . UI . propertyContainerFor ( obj ) . find ( '.adr' ) . val ( ) ;
console . log ( 'adr 1: ' + adr ) ;
if ( adr == undefined ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'Couldn\'t get a valid address.' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
return ;
}
// FIXME: I suck at regexp. /Tanghus
var adrarr = adr . split ( ';' ) ;
var adrstr = '' ;
if ( adrarr [ 2 ] . trim ( ) != '' ) {
adrstr = adrstr + adrarr [ 2 ] . trim ( ) + ',' ;
}
if ( adrarr [ 3 ] . trim ( ) != '' ) {
adrstr = adrstr + adrarr [ 3 ] . trim ( ) + ',' ;
}
if ( adrarr [ 4 ] . trim ( ) != '' ) {
adrstr = adrstr + adrarr [ 4 ] . trim ( ) + ',' ;
}
if ( adrarr [ 5 ] . trim ( ) != '' ) {
adrstr = adrstr + adrarr [ 5 ] . trim ( ) + ',' ;
}
if ( adrarr [ 6 ] . trim ( ) != '' ) {
adrstr = adrstr + adrarr [ 6 ] . trim ( ) ;
}
console . log ( 'adrstr: "' + adrstr + '"' ) ;
adrstr = encodeURIComponent ( adrstr ) ;
console . log ( 'adrstr 2: ' + adrstr ) ;
var uri = 'http://open.mapquestapi.com/nominatim/v1/search.php?q=' + adrstr + '&limit=10&addressdetails=1&zoom=' ;
console . log ( 'uri: ' + uri ) ;
var newWindow = window . open ( uri , '_blank' ) ;
newWindow . focus ( ) ;
} ,
mailTo : function ( obj ) {
var adr = Contacts . UI . propertyContainerFor ( $ ( obj ) ) . find ( 'input[type="email"]' ) . val ( ) . trim ( ) ;
if ( adr == '' ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'Please enter an email address.' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
return ;
}
window . location . href = 'mailto:' + adr ;
} ,
propertyContainerFor : function ( obj ) {
return $ ( obj ) . parents ( '.propertycontainer' ) . first ( ) ;
} ,
checksumFor : function ( obj ) {
return $ ( obj ) . parents ( '.propertycontainer' ) . first ( ) . data ( 'checksum' ) ;
} ,
propertyTypeFor : function ( obj ) {
return $ ( obj ) . parents ( '.propertycontainer' ) . first ( ) . data ( 'element' ) ;
} ,
2012-04-03 03:28:12 +02:00
/ * s h o w H i d e C o n t a c t I n f o : f u n c t i o n ( ) {
2012-03-05 22:02:44 +01:00
var show = ( $ ( '#emaillist li.propertycontainer' ) . length > 0 || $ ( '#phonelist li.propertycontainer' ) . length > 0 || $ ( '#addressdisplay dl.propertycontainer' ) . length > 0 ) ;
2012-02-06 14:18:40 +01:00
console . log ( 'showHideContactInfo: ' + show ) ;
if ( show ) {
$ ( '#contact_communication' ) . show ( ) ;
} else {
$ ( '#contact_communication' ) . hide ( ) ;
}
2012-04-03 03:28:12 +02:00
} , * /
/ * c h e c k L i s t F o r : f u n c t i o n ( o b j ) {
2012-02-06 07:32:57 +01:00
var type = $ ( obj ) . parents ( '.propertycontainer' ) . first ( ) . data ( 'element' ) ;
console . log ( 'checkListFor: ' + type ) ;
switch ( type ) {
case 'EMAIL' :
console . log ( 'emails: ' + $ ( '#emaillist>li' ) . length ) ;
2012-03-05 22:02:44 +01:00
if ( $ ( '#emaillist li.propertycontainer' ) . length == 0 ) {
2012-02-06 07:32:57 +01:00
$ ( '#emails' ) . hide ( ) ;
}
break ;
case 'TEL' :
console . log ( 'phones: ' + $ ( '#phonelist>li' ) . length ) ;
2012-03-05 22:02:44 +01:00
if ( $ ( '#phonelist li.propertycontainer' ) . length == 0 ) {
2012-02-06 07:32:57 +01:00
$ ( '#phones' ) . hide ( ) ;
}
break ;
case 'ADR' :
console . log ( 'addresses: ' + $ ( '#addressdisplay>dl' ) . length ) ;
2012-03-05 22:02:44 +01:00
if ( $ ( '#addressdisplay dl.propertycontainer' ) . length == 0 ) {
2012-02-06 07:32:57 +01:00
$ ( '#addresses' ) . hide ( ) ;
}
break ;
case 'NICKNAME' :
case 'ORG' :
case 'BDAY' :
break ;
}
2012-04-03 03:28:12 +02:00
} , * /
2012-02-06 07:32:57 +01:00
loading : function ( obj , state ) {
if ( state ) {
$ ( obj ) . addClass ( 'loading' ) ;
} else {
$ ( obj ) . removeClass ( 'loading' ) ;
}
} ,
showCardDAVUrl : function ( username , bookname ) {
$ ( '#carddav_url' ) . val ( totalurl + '/' + username + '/' + bookname ) ;
$ ( '#carddav_url' ) . show ( ) ;
$ ( '#carddav_url_close' ) . show ( ) ;
} ,
loadListHandlers : function ( ) {
//$('.add,.delete').hide();
2012-04-07 16:03:11 +02:00
$ ( '.globe,.mail,.delete,.edit,.tip' ) . tipsy ( ) ;
2012-02-06 07:32:57 +01:00
$ ( '.addresscard,.propertylist li,.propertycontainer' ) . hover (
function ( ) {
$ ( this ) . find ( '.globe,.mail,.delete,.edit' ) . fadeIn ( 100 ) ;
} ,
function ( ) {
$ ( this ) . find ( '.globe,.mail,.delete,.edit' ) . fadeOut ( 100 ) ;
}
) ;
} ,
loadHandlers : function ( ) {
2012-02-09 19:04:07 +01:00
//console.log('loadHandlers');
2012-02-06 07:32:57 +01:00
/ *
$ ( '.formfloat' ) . hover (
function ( ) {
$ ( this ) . find ( '.add' ) . fadeIn ( 500 ) ;
} ,
function ( ) {
$ ( this ) . find ( '.add' ) . fadeOut ( 500 ) ;
}
) ; * /
2012-02-10 16:40:40 +01:00
//$('#fn').jec();
$ ( '#fn_select' ) . combobox ( {
'id' : 'fn' ,
'name' : 'value' ,
2012-04-03 03:28:12 +02:00
'classes' : [ 'contacts_property' , 'huge' , 'tip' , 'float' ] ,
'attributes' : { 'placeholder' : t ( 'contacts' , 'Enter name' ) } ,
2012-02-10 16:40:40 +01:00
'title' : t ( 'contacts' , 'Format custom, Short name, Full name, Reverse or Reverse with comma' ) } ) ;
//$('.jecEditableOption').attr('title', t('contacts','Custom'));
2012-02-06 07:32:57 +01:00
$ ( '#bday' ) . datepicker ( {
dateFormat : 'dd-mm-yy'
} ) ;
2012-03-12 14:12:27 +01:00
/ * $ ( ' # c a t e g o r i e s _ v a l u e ' ) . f i n d ( ' s e l e c t ' ) . m u l t i s e l e c t ( {
2012-03-07 16:39:56 +01:00
noneSelectedText : t ( 'contacts' , 'Select categories' ) ,
header : false ,
selectedList : 6 ,
classes : 'categories'
2012-03-12 14:12:27 +01:00
} ) ; * /
2012-02-06 07:32:57 +01:00
// Style phone types
2012-03-05 22:02:44 +01:00
$ ( '#phonelist' ) . find ( 'select.contacts_property' ) . multiselect ( {
2012-02-06 07:32:57 +01:00
noneSelectedText : t ( 'contacts' , 'Select type' ) ,
header : false ,
selectedList : 4 ,
classes : 'typelist'
} ) ;
$ ( '#add_email' ) . click ( function ( ) {
Contacts . UI . Card . addMail ( ) ;
} ) ;
$ ( '#add_phone' ) . click ( function ( ) {
Contacts . UI . Card . addPhone ( ) ;
} ) ;
// $('#add_address').click(function(){
// Contacts.UI.Card.editAddress();
// return false;
// });
$ ( '#edit_name' ) . click ( function ( ) {
Contacts . UI . Card . editName ( ) ;
return false ;
} ) ;
/* Initialize the photo edit dialog */
$ ( '#edit_photo_dialog' ) . dialog ( { autoOpen : false , modal : true , height : 'auto' , width : 'auto' } ) ;
$ ( '#edit_photo_dialog' ) . dialog ( 'option' , 'buttons' , [
{
text : "Ok" ,
click : function ( ) {
Contacts . UI . Card . savePhoto ( this ) ;
$ ( this ) . dialog ( 'close' ) ;
}
} ,
{
text : "Cancel" ,
click : function ( ) { $ ( this ) . dialog ( 'close' ) ; }
}
] ) ;
2012-03-12 14:12:27 +01:00
$ ( '#categories' ) . multiple _autocomplete ( { source : categories } ) ;
2012-04-03 03:28:12 +02:00
$ ( '.button,.action,.tip' ) . tipsy ( ) ;
$ ( '#contacts_deletecard' ) . tipsy ( { gravity : 'ne' } ) ;
$ ( '#contacts_downloadcard' ) . tipsy ( { gravity : 'ne' } ) ;
2012-02-06 07:32:57 +01:00
Contacts . UI . loadListHandlers ( ) ;
} ,
Card : {
id : '' ,
fn : '' ,
fullname : '' ,
shortname : '' ,
famname : '' ,
givname : '' ,
addname : '' ,
honpre : '' ,
honsuf : '' ,
data : undefined ,
2012-03-29 15:24:32 +02:00
update : function ( id ) {
2012-02-14 13:57:11 +01:00
// Make sure proper DOM is loaded.
2012-03-29 15:24:32 +02:00
var newid ;
console . log ( 'Card.update(), id: ' + id ) ;
2012-02-14 13:57:11 +01:00
console . log ( 'Card.update(), #contacts: ' + $ ( '#contacts li' ) . length ) ;
2012-03-29 15:24:32 +02:00
if ( id == undefined ) {
newid = $ ( '#contacts li:first-child' ) . data ( 'id' ) ;
} else {
newid = id ;
}
if ( $ ( '#contacts li' ) . length > 0 ) {
2012-02-14 13:57:11 +01:00
$ . 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 ) {
2012-03-29 15:24:32 +02:00
//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 ) {
2012-02-14 13:57:11 +01:00
if ( jsondata . status == 'success' ) {
Contacts . UI . Card . loadContact ( jsondata . data ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-14 13:57:11 +01:00
}
} ) ;
}
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-14 13:57:11 +01:00
}
} ) ;
}
if ( $ ( '#contacts li' ) . length == 0 ) {
// load intro page
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'loadintro.php' ) , { } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
id = '' ;
$ ( '#rightcontent' ) . data ( 'id' , '' ) ;
$ ( '#rightcontent' ) . html ( jsondata . data . page ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-14 13:57:11 +01:00
}
} ) ;
}
} ,
2012-04-10 21:53:36 +02:00
doExport : function ( ) {
2012-02-06 07:32:57 +01:00
document . location . href = OC . linkTo ( 'contacts' , 'export.php' ) + '?contactid=' + this . id ;
//$.get(OC.linkTo('contacts', 'export.php'),{'contactid':this.id},function(jsondata){
//});
} ,
2012-04-10 21:53:36 +02:00
doImport : function ( ) {
2012-02-14 10:34:52 +01:00
Contacts . UI . notImplemented ( ) ;
} ,
2012-04-03 03:28:12 +02:00
add : function ( n , fn , aid , isnew ) { // add a new contact
2012-02-14 10:34:52 +01:00
console . log ( 'Add contact: ' + n + ', ' + fn + ' ' + aid ) ;
2012-04-09 16:29:35 +02:00
var card = $ ( '#card' ) [ 0 ] ;
if ( ! card ) {
console . log ( 'Loading proper card DOM' ) ;
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'loadcard.php' ) , { } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
$ ( '#rightcontent' ) . html ( jsondata . data . page ) ;
Contacts . UI . loadHandlers ( ) ;
} else {
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
}
} ) ;
}
2012-02-14 10:34:52 +01:00
$ . post ( OC . filePath ( 'contacts' , 'ajax' , 'addcontact.php' ) , { n : n , fn : fn , aid : aid } ,
function ( jsondata ) {
if ( jsondata . status == 'success' ) {
$ ( '#rightcontent' ) . data ( 'id' , jsondata . data . id ) ;
var id = jsondata . data . id ;
$ . getJSON ( 'ajax/contactdetails.php' , { 'id' : id } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
Contacts . UI . loadHandlers ( ) ;
Contacts . UI . Card . loadContact ( jsondata . data ) ;
$ ( '#leftcontent .active' ) . removeClass ( 'active' ) ;
var item = '<li data-id="' + jsondata . data . id + '" class="active"><a href="index.php?id=' + jsondata . data . id + '" style="background: url(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 ( ) {
if ( $ ( this ) . text ( ) . toLowerCase ( ) > Contacts . UI . Card . fn . toLowerCase ( ) ) {
$ ( this ) . before ( item ) . fadeIn ( 'fast' ) ;
added = true ;
return false ;
}
} ) ;
if ( ! added ) {
$ ( '#leftcontent ul' ) . append ( item ) ;
}
2012-04-03 03:28:12 +02:00
if ( isnew ) {
Contacts . UI . Card . addProperty ( 'EMAIL' ) ;
Contacts . UI . Card . addProperty ( 'TEL' ) ;
Contacts . UI . Card . addProperty ( 'NICKNAME' ) ;
Contacts . UI . Card . addProperty ( 'ORG' ) ;
Contacts . UI . Card . addProperty ( 'CATEGORIES' ) ;
$ ( '#fn' ) . focus ( ) ;
2012-04-07 16:03:11 +02:00
$ ( '#fn' ) . select ( ) ;
2012-04-03 03:28:12 +02:00
}
2012-02-14 10:34:52 +01:00
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-14 10:34:52 +01:00
//alert(jsondata.data.message);
}
} ) ;
$ ( '#contact_identity' ) . show ( ) ;
$ ( '#actionbar' ) . show ( ) ;
// TODO: Add to contacts list.
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-14 10:34:52 +01:00
//alert(jsondata.data.message);
}
} ) ;
} ,
2012-04-10 21:53:36 +02:00
doDelete : function ( ) {
2012-02-06 07:32:57 +01:00
$ ( '#contacts_deletecard' ) . tipsy ( 'hide' ) ;
2012-03-29 15:24:32 +02:00
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 ( ) ;
2012-02-14 10:34:52 +01:00
}
2012-03-29 15:24:32 +02:00
curlistitem . remove ( ) ;
if ( newlistitem != undefined ) {
newid = newlistitem . data ( 'id' ) ;
2012-02-14 10:34:52 +01:00
}
2012-03-29 15:24:32 +02:00
$ ( '#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);
}
} ) ;
2012-02-06 07:32:57 +01:00
}
} ) ;
return false ;
} ,
loadContact : function ( jsondata ) {
2012-04-03 03:28:12 +02:00
//$('#contact_communication').hide();
2012-02-06 07:32:57 +01:00
this . data = jsondata ;
this . id = this . data . id ;
2012-02-14 10:34:52 +01:00
$ ( '#rightcontent' ) . data ( 'id' , this . id ) ;
2012-03-07 16:39:56 +01:00
console . log ( 'loaded: ' + this . data . FN [ 0 ] [ 'value' ] ) ;
2012-02-06 07:32:57 +01:00
this . populateNameFields ( ) ;
2012-03-12 14:12:27 +01:00
//this.loadCategories();
2012-02-06 07:32:57 +01:00
this . loadPhoto ( ) ;
this . loadMails ( ) ;
this . loadPhones ( ) ;
this . loadAddresses ( ) ;
this . loadSingleProperties ( ) ;
2012-03-07 16:39:56 +01:00
if ( this . data . NOTE ) {
$ ( '#note' ) . data ( 'checksum' , this . data . NOTE [ 0 ] [ 'checksum' ] ) ;
$ ( '#note' ) . find ( 'textarea' ) . val ( this . data . NOTE [ 0 ] [ 'value' ] ) ;
$ ( '#note' ) . show ( ) ;
} else {
$ ( '#note' ) . data ( 'checksum' , '' ) ;
$ ( '#note' ) . find ( 'textarea' ) . val ( '' ) ;
2012-04-03 03:28:12 +02:00
//$('#note').hide();
2012-03-07 16:39:56 +01:00
}
2012-02-06 07:32:57 +01:00
} ,
loadSingleProperties : function ( ) {
2012-03-12 14:12:27 +01:00
var props = [ 'BDAY' , 'NICKNAME' , 'ORG' , 'CATEGORIES' ] ;
2012-02-06 07:32:57 +01:00
// Clear all elements
2012-03-05 22:02:44 +01:00
$ ( '#ident .propertycontainer' ) . each ( function ( ) {
2012-02-06 07:32:57 +01:00
if ( props . indexOf ( $ ( this ) . data ( 'element' ) ) > - 1 ) {
$ ( this ) . data ( 'checksum' , '' ) ;
$ ( this ) . find ( 'input' ) . val ( '' ) ;
$ ( this ) . hide ( ) ;
$ ( this ) . prev ( ) . hide ( ) ;
}
} ) ;
for ( var prop in props ) {
if ( this . data [ props [ prop ] ] != undefined ) {
$ ( '#contacts_propertymenu a[data-type="' + props [ prop ] + '"]' ) . parent ( ) . hide ( ) ;
var property = this . data [ props [ prop ] ] [ 0 ] ;
var value = property [ 'value' ] , checksum = property [ 'checksum' ] ;
switch ( props [ prop ] ) {
case 'BDAY' :
var val = $ . datepicker . parseDate ( 'yy-mm-dd' , value . substring ( 0 , 10 ) ) ;
value = $ . datepicker . formatDate ( 'dd-mm-yy' , val ) ;
$ ( '#contact_identity' ) . find ( '#bday' ) . val ( value ) ;
$ ( '#contact_identity' ) . find ( '#bday_value' ) . data ( 'checksum' , checksum ) ;
$ ( '#contact_identity' ) . find ( '#bday_label' ) . show ( ) ;
$ ( '#contact_identity' ) . find ( '#bday_value' ) . show ( ) ;
break ;
case 'NICKNAME' :
$ ( '#contact_identity' ) . find ( '#nickname' ) . val ( value ) ;
$ ( '#contact_identity' ) . find ( '#nickname_value' ) . data ( 'checksum' , checksum ) ;
$ ( '#contact_identity' ) . find ( '#nickname_label' ) . show ( ) ;
$ ( '#contact_identity' ) . find ( '#nickname_value' ) . show ( ) ;
break ;
case 'ORG' :
$ ( '#contact_identity' ) . find ( '#org' ) . val ( value ) ;
$ ( '#contact_identity' ) . find ( '#org_value' ) . data ( 'checksum' , checksum ) ;
$ ( '#contact_identity' ) . find ( '#org_label' ) . show ( ) ;
$ ( '#contact_identity' ) . find ( '#org_value' ) . show ( ) ;
break ;
2012-03-12 14:12:27 +01:00
case 'CATEGORIES' :
2012-03-07 21:50:55 +01:00
$ ( '#contact_identity' ) . find ( '#categories' ) . val ( value ) ;
$ ( '#contact_identity' ) . find ( '#categories_value' ) . data ( 'checksum' , checksum ) ;
$ ( '#contact_identity' ) . find ( '#categories_label' ) . show ( ) ;
$ ( '#contact_identity' ) . find ( '#categories_value' ) . show ( ) ;
2012-03-12 14:12:27 +01:00
break ;
2012-02-06 07:32:57 +01:00
}
2012-02-06 08:04:06 +01:00
} else {
$ ( '#contacts_propertymenu a[data-type="' + props [ prop ] + '"]' ) . parent ( ) . show ( ) ;
2012-02-06 07:32:57 +01:00
}
}
} ,
populateNameFields : function ( ) {
2012-02-06 14:18:40 +01:00
this . fn = '' ; this . fullname = '' ; this . givname = '' ; this . famname = '' ; this . addname = '' ; this . honpre = '' ; this . honsuf = '' ;
2012-02-06 07:32:57 +01:00
var full = '' ;
var narray = undefined ;
this . fn = this . data . FN [ 0 ] [ 'value' ] ;
if ( this . data . N == undefined ) {
narray = [ this . fn , '' , '' , '' , '' ] ; // Checking for non-existing 'N' property :-P
full = this . fn ;
} else {
narray = this . data . N [ 0 ] [ 'value' ] ;
}
2012-03-09 07:36:05 +01:00
this . famname = narray [ 0 ] || '' ;
this . givname = narray [ 1 ] || '' ;
this . addname = narray [ 2 ] || '' ;
this . honpre = narray [ 3 ] || '' ;
this . honsuf = narray [ 4 ] || '' ;
2012-02-06 07:32:57 +01:00
if ( this . honpre . length > 0 ) {
this . fullname += this . honpre + ' ' ;
}
if ( this . givname . length > 0 ) {
this . fullname += ' ' + this . givname ;
}
if ( this . addname . length > 0 ) {
this . fullname += ' ' + this . addname ;
}
if ( this . famname . length > 0 ) {
this . fullname += ' ' + this . famname ;
}
if ( this . honsuf . length > 0 ) {
this . fullname += ', ' + this . honsuf ;
}
$ ( '#n' ) . html ( this . fullname ) ;
2012-02-10 16:40:40 +01:00
$ ( '#fn_select option' ) . remove ( ) ;
$ ( '#fn_select' ) . combobox ( 'value' , this . fn ) ;
var names = [ this . fullname , this . givname + ' ' + this . famname , this . famname + ' ' + this . givname , this . famname + ', ' + this . givname ] ;
2012-03-05 22:03:33 +01:00
if ( this . data . ORG ) {
names [ names . length ] = this . data . ORG [ 0 ] . value ;
}
2012-02-10 16:40:40 +01:00
$ . each ( names , function ( key , value ) {
$ ( '#fn_select' )
. append ( $ ( '<option></option>' )
. text ( value ) ) ;
} ) ;
2012-02-06 07:32:57 +01:00
$ ( '#contact_identity' ) . find ( '*[data-element="N"]' ) . data ( 'checksum' , this . data . N [ 0 ] [ 'checksum' ] ) ;
$ ( '#contact_identity' ) . find ( '*[data-element="FN"]' ) . data ( 'checksum' , this . data . FN [ 0 ] [ 'checksum' ] ) ;
2012-02-14 13:57:11 +01:00
$ ( '#contact_identity' ) . show ( ) ;
2012-02-06 07:32:57 +01:00
} ,
2012-03-07 16:39:56 +01:00
hasCategory : function ( category ) {
2012-02-17 09:35:18 +01:00
if ( this . data . CATEGORIES ) {
2012-03-12 16:44:16 +01:00
var categories = this . data . CATEGORIES [ 0 ] [ 'value' ] . split ( /,\s*/ ) ;
for ( var c in categories ) {
2012-03-07 16:39:56 +01:00
var cat = this . data . CATEGORIES [ 0 ] [ 'value' ] [ c ] ;
2012-03-12 16:44:16 +01:00
console . log ( 'hasCategory: ' + cat + ' === ' + category + '?' ) ;
2012-03-07 16:39:56 +01:00
if ( typeof cat === 'string' && ( cat . toUpperCase ( ) === category . toUpperCase ( ) ) ) {
2012-03-12 16:44:16 +01:00
console . log ( 'Yes' ) ;
2012-03-07 16:39:56 +01:00
return true ;
}
}
2012-02-17 09:35:18 +01:00
}
2012-03-07 16:39:56 +01:00
return false ;
} ,
2012-03-12 21:55:54 +01:00
categoriesChanged : function ( newcategories ) { // Categories added/deleted.
2012-04-12 23:08:48 +02:00
categories = $ . map ( newcategories , function ( v ) { return v ; } ) ;
console . log ( 'categoriesChanged for ' + Contacts . UI . Card . id + ' : ' + categories ) ;
$ ( '#categories' ) . multiple _autocomplete ( 'option' , 'source' , categories ) ;
2012-03-12 16:44:16 +01:00
var categorylist = $ ( '#categories_value' ) . find ( 'input' ) ;
2012-03-12 16:47:29 +01:00
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'categories/categoriesfor.php' ) , { 'id' : Contacts . UI . Card . id } , function ( jsondata ) {
2012-03-07 16:39:56 +01:00
if ( jsondata . status == 'success' ) {
2012-03-12 16:44:16 +01:00
console . log ( 'Setting checksum: ' + jsondata . data . checksum + ', value: ' + jsondata . data . value ) ;
2012-03-07 16:39:56 +01:00
$ ( '#categories_value' ) . data ( 'checksum' , jsondata . data . checksum ) ;
2012-03-12 16:44:16 +01:00
categorylist . val ( jsondata . data . value ) ;
2012-03-07 16:39:56 +01:00
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-03-07 16:39:56 +01:00
}
} ) ;
} ,
2012-03-12 16:44:16 +01:00
/*loadCategories:function(){ / / On loading contact .
2012-03-07 16:39:56 +01:00
var categories = $ ( '#categories_value' ) . find ( 'select' ) ;
2012-02-17 09:35:18 +01:00
if ( this . data . CATEGORIES ) {
2012-03-07 16:39:56 +01:00
$ ( '#categories_value' ) . data ( 'checksum' , this . data . CATEGORIES [ 0 ] [ 'checksum' ] ) ;
} else {
$ ( '#categories_value' ) . data ( 'checksum' , '' ) ;
2012-02-17 09:35:18 +01:00
}
2012-03-07 16:39:56 +01:00
categories . find ( 'option' ) . each ( function ( ) {
if ( Contacts . UI . Card . hasCategory ( $ ( this ) . val ( ) ) ) {
$ ( this ) . attr ( 'selected' , 'selected' ) ;
} else {
$ ( this ) . removeAttr ( 'selected' ) ;
}
} ) ;
categories . multiselect ( 'refresh' ) ;
2012-03-12 16:44:16 +01:00
} , * /
2012-02-06 07:32:57 +01:00
editNew : function ( ) { // add a new contact
2012-02-06 14:18:40 +01:00
this . id = '' ; this . fn = '' ; this . fullname = '' ; this . givname = '' ; this . famname = '' ; this . addname = '' ; this . honpre = '' ; this . honsuf = '' ;
2012-04-03 03:28:12 +02:00
Contacts . UI . Card . add ( ';;;;' , '' , '' , true ) ;
/ * $ . g e t J S O N ( O C . f i l e P a t h ( ' c o n t a c t s ' , ' a j a x ' , ' n e w c o n t a c t . p h p ' ) , { } , f u n c t i o n ( j s o n d a t a ) {
2012-02-06 07:32:57 +01:00
if ( jsondata . status == 'success' ) {
id = '' ;
$ ( '#rightcontent' ) . data ( 'id' , '' ) ;
$ ( '#rightcontent' ) . html ( jsondata . data . page ) ;
2012-04-03 03:28:12 +02:00
//Contacts.UI.Card.editName();
2012-03-07 16:39:56 +01:00
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
//alert(jsondata.data.message);
}
2012-04-03 03:28:12 +02:00
} ) ; * /
2012-02-06 07:32:57 +01:00
} ,
2012-02-09 19:04:07 +01:00
savePropertyInternal : function ( name , fields , oldchecksum , checksum ) {
// TODO: Add functionality for new fields.
2012-03-07 16:39:56 +01:00
console . log ( 'savePropertyInternal: ' + name + ', fields: ' + fields + 'checksum: ' + checksum ) ;
console . log ( 'savePropertyInternal: ' + this . data [ name ] ) ;
var multivalue = [ 'CATEGORIES' ] ;
2012-02-09 19:04:07 +01:00
var params = { } ;
2012-03-07 16:39:56 +01:00
var value = multivalue . indexOf ( name ) != - 1 ? new Array ( ) : undefined ;
2012-02-09 19:04:07 +01:00
jQuery . each ( fields , function ( i , field ) {
//.substring(11,'parameters[TYPE][]'.indexOf(']'))
if ( field . name . substring ( 0 , 5 ) === 'value' ) {
2012-03-07 16:39:56 +01:00
if ( multivalue . indexOf ( name ) != - 1 ) {
value . push ( field . value ) ;
} else {
value = field . value ;
}
2012-02-09 19:04:07 +01:00
} else if ( field . name . substring ( 0 , 10 ) === 'parameters' ) {
var p = field . name . substring ( 11 , 'parameters[TYPE][]' . indexOf ( ']' ) ) ;
if ( ! ( p in params ) ) {
params [ p ] = [ ] ;
}
params [ p ] . push ( field . value ) ;
}
} ) ;
for ( var i in this . data [ name ] ) {
if ( this . data [ name ] [ i ] [ 'checksum' ] == oldchecksum ) {
this . data [ name ] [ i ] [ 'checksum' ] = checksum ;
this . data [ name ] [ i ] [ 'value' ] = value ;
this . data [ name ] [ i ] [ 'parameters' ] = params ;
}
}
} ,
2012-02-06 07:32:57 +01:00
saveProperty : function ( obj ) {
// I couldn't get the selector to filter on 'contacts_property' so I filter by hand here :-/
if ( ! $ ( obj ) . hasClass ( 'contacts_property' ) ) {
2012-03-07 16:39:56 +01:00
console . log ( 'Filtering out object.' + obj ) ;
2012-02-06 07:32:57 +01:00
return false ;
}
if ( $ ( obj ) . hasClass ( 'nonempty' ) && $ ( obj ) . val ( ) . trim ( ) == '' ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'This property has to be non-empty.' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
return false ;
}
container = $ ( obj ) . parents ( '.propertycontainer' ) . first ( ) ; // get the parent holding the metadata.
Contacts . UI . loading ( container , true ) ;
var checksum = container . data ( 'checksum' ) ;
var name = container . data ( 'element' ) ;
2012-02-09 19:04:07 +01:00
console . log ( 'saveProperty: ' + name ) ;
2012-03-05 22:02:44 +01:00
var fields = container . find ( 'input.contacts_property,select.contacts_property' ) . serializeArray ( ) ;
2012-03-13 02:55:17 +01:00
var q = container . find ( 'input.contacts_property,select.contacts_property,textarea.contacts_property' ) . serialize ( ) ;
2012-02-06 07:32:57 +01:00
if ( q == '' || q == undefined ) {
console . log ( 'Couldn\'t serialize elements.' ) ;
Contacts . UI . loading ( container , false ) ;
return false ;
}
q = q + '&id=' + this . id + '&name=' + name ;
if ( checksum != undefined && checksum != '' ) { // save
q = q + '&checksum=' + checksum ;
console . log ( 'Saving: ' + q ) ;
2012-03-07 16:39:56 +01:00
$ ( obj ) . attr ( 'disabled' , 'disabled' ) ;
2012-02-06 07:32:57 +01:00
$ . post ( 'ajax/saveproperty.php' , q , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
container . data ( 'checksum' , jsondata . data . checksum ) ;
2012-02-09 19:04:07 +01:00
Contacts . UI . Card . savePropertyInternal ( name , fields , checksum , jsondata . data . checksum ) ;
2012-02-06 07:32:57 +01:00
Contacts . UI . loading ( container , false ) ;
2012-03-07 16:39:56 +01:00
$ ( obj ) . removeAttr ( 'disabled' ) ;
2012-02-06 07:32:57 +01:00
return true ;
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
Contacts . UI . loading ( container , false ) ;
2012-03-07 16:39:56 +01:00
$ ( obj ) . removeAttr ( 'disabled' ) ;
2012-02-06 07:32:57 +01:00
return false ;
}
} , 'json' ) ;
} else { // add
console . log ( 'Adding: ' + q ) ;
2012-03-07 16:39:56 +01:00
$ ( obj ) . attr ( 'disabled' , 'disabled' ) ;
2012-02-06 07:32:57 +01:00
$ . post ( 'ajax/addproperty.php' , q , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
container . data ( 'checksum' , jsondata . data . checksum ) ;
2012-02-09 19:04:07 +01:00
// TODO: savePropertyInternal doesn't know about new fields
//Contacts.UI.Card.savePropertyInternal(name, fields, checksum, jsondata.data.checksum);
2012-02-06 07:32:57 +01:00
Contacts . UI . loading ( container , false ) ;
2012-03-07 16:39:56 +01:00
$ ( obj ) . removeAttr ( 'disabled' ) ;
2012-02-06 07:32:57 +01:00
return true ;
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
Contacts . UI . loading ( container , false ) ;
2012-03-07 16:39:56 +01:00
$ ( obj ) . removeAttr ( 'disabled' ) ;
2012-02-06 07:32:57 +01:00
return false ;
}
} , 'json' ) ;
}
} ,
2012-04-03 03:28:12 +02:00
addProperty : function ( type ) {
//var type = $(obj).data('type');
2012-02-06 07:32:57 +01:00
console . log ( 'addProperty:' + type ) ;
switch ( type ) {
case 'PHOTO' :
2012-03-07 16:39:56 +01:00
this . loadPhoto ( true ) ;
2012-02-06 07:32:57 +01:00
$ ( '#file_upload_form' ) . show ( ) ;
2012-02-07 03:17:28 +01:00
$ ( '#contacts_propertymenu a[data-type="' + type + '"]' ) . parent ( ) . hide ( ) ;
2012-03-27 12:26:59 +02:00
$ ( '#file_upload_start' ) . trigger ( 'click' ) ;
2012-02-06 07:32:57 +01:00
break ;
2012-03-07 16:39:56 +01:00
case 'NOTE' :
$ ( '#note' ) . show ( ) ;
$ ( '#contacts_propertymenu a[data-type="' + type + '"]' ) . parent ( ) . hide ( ) ;
2012-03-27 12:26:59 +02:00
$ ( '#note' ) . find ( 'textarea' ) . focus ( ) ;
2012-03-07 16:39:56 +01:00
break ;
2012-02-06 07:32:57 +01:00
case 'EMAIL' :
if ( $ ( '#emaillist>li' ) . length == 1 ) {
$ ( '#emails' ) . show ( ) ;
}
Contacts . UI . Card . addMail ( ) ;
2012-04-03 03:28:12 +02:00
//Contacts.UI.showHideContactInfo();
2012-02-06 07:32:57 +01:00
break ;
case 'TEL' :
if ( $ ( '#phonelist>li' ) . length == 1 ) {
$ ( '#phones' ) . show ( ) ;
}
Contacts . UI . Card . addPhone ( ) ;
2012-04-03 03:28:12 +02:00
//Contacts.UI.showHideContactInfo();
2012-02-06 07:32:57 +01:00
break ;
case 'ADR' :
if ( $ ( '#addressdisplay>dl' ) . length == 1 ) {
$ ( '#addresses' ) . show ( ) ;
}
Contacts . UI . Card . editAddress ( 'new' , true ) ;
2012-04-03 03:28:12 +02:00
//Contacts.UI.showHideContactInfo();
2012-02-06 07:32:57 +01:00
break ;
case 'NICKNAME' :
case 'ORG' :
case 'BDAY' :
2012-03-07 21:50:55 +01:00
case 'CATEGORIES' :
2012-02-06 07:32:57 +01:00
$ ( 'dl dt[data-element="' + type + '"],dd[data-element="' + type + '"]' ) . show ( ) ;
2012-03-27 12:26:59 +02:00
$ ( 'dd[data-element="' + type + '"]' ) . find ( 'input' ) . focus ( ) ;
2012-02-06 07:32:57 +01:00
$ ( '#contacts_propertymenu a[data-type="' + type + '"]' ) . parent ( ) . hide ( ) ;
break ;
}
} ,
deleteProperty : function ( obj , type ) {
//console.log('deleteProperty, id: ' + this.id);
Contacts . UI . loading ( obj , true ) ;
var checksum = Contacts . UI . checksumFor ( obj ) ;
if ( checksum != undefined ) {
$ . getJSON ( 'ajax/deleteproperty.php' , { 'id' : this . id , 'checksum' : checksum } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
if ( type == 'list' ) {
Contacts . UI . propertyContainerFor ( obj ) . remove ( ) ;
2012-04-03 03:28:12 +02:00
//Contacts.UI.showHideContactInfo();
//Contacts.UI.checkListFor(obj);
2012-02-06 07:32:57 +01:00
} else if ( type == 'single' ) {
var proptype = Contacts . UI . propertyTypeFor ( obj ) ;
console . log ( 'deleteProperty, hiding: ' + proptype ) ;
2012-03-13 14:56:03 +01:00
var othertypes = [ 'NOTE' , 'PHOTO' ] ;
if ( othertypes . indexOf ( proptype ) != - 1 ) {
console . log ( 'NOTE or PHOTO' ) ;
2012-03-13 02:55:17 +01:00
Contacts . UI . propertyContainerFor ( obj ) . hide ( ) ;
Contacts . UI . propertyContainerFor ( obj ) . data ( 'checksum' , '' ) ;
2012-03-27 10:12:30 +02:00
if ( proptype == 'PHOTO' ) {
console . log ( 'Delete PHOTO' ) ;
Contacts . UI . Contacts . refreshThumbnail ( Contacts . UI . Card . id ) ;
2012-03-27 12:26:59 +02:00
} else if ( proptype == 'NOTE' ) {
$ ( '#note' ) . find ( 'textarea' ) . val ( '' ) ;
2012-03-27 10:12:30 +02:00
}
2012-03-13 02:55:17 +01:00
} else {
$ ( 'dl dt[data-element="' + proptype + '"],dd[data-element="' + proptype + '"]' ) . hide ( ) ;
$ ( 'dl dd[data-element="' + proptype + '"]' ) . data ( 'checksum' , '' ) ;
2012-03-27 12:26:59 +02:00
$ ( 'dl dd[data-element="' + proptype + '"]' ) . find ( 'input' ) . val ( '' ) ;
2012-03-13 02:55:17 +01:00
}
2012-02-06 07:32:57 +01:00
$ ( '#contacts_propertymenu a[data-type="' + proptype + '"]' ) . parent ( ) . show ( ) ;
Contacts . UI . loading ( obj , false ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , '\'deleteProperty\' called without type argument. Please report at bugs.owncloud.org' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
Contacts . UI . loading ( obj , false ) ;
}
}
else {
Contacts . UI . loading ( obj , false ) ;
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
} ) ;
} else { // Property hasn't been saved so there's nothing to delete.
if ( type == 'list' ) {
Contacts . UI . propertyContainerFor ( obj ) . remove ( ) ;
2012-04-03 03:28:12 +02:00
//Contacts.UI.showHideContactInfo();
//Contacts.UI.checkListFor(obj);
2012-02-06 07:32:57 +01:00
} else if ( type == 'single' ) {
var proptype = Contacts . UI . propertyTypeFor ( obj ) ;
console . log ( 'deleteProperty, hiding: ' + proptype ) ;
$ ( 'dl dt[data-element="' + proptype + '"],dd[data-element="' + proptype + '"]' ) . hide ( ) ;
$ ( '#contacts_propertymenu a[data-type="' + proptype + '"]' ) . parent ( ) . show ( ) ;
Contacts . UI . loading ( obj , false ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , '\'deleteProperty\' called without type argument. Please report at bugs.owncloud.org' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
}
} ,
editName : function ( ) {
2012-02-06 14:18:40 +01:00
var isnew = ( this . id == '' ) ;
2012-02-06 07:32:57 +01:00
/* Initialize the name edit dialog */
2012-02-06 07:32:57 +01:00
if ( $ ( '#edit_name_dialog' ) . dialog ( 'isOpen' ) == true ) {
$ ( '#edit_name_dialog' ) . dialog ( 'moveToTop' ) ;
} else { // TODO: If id=='' call addcontact.php (or whatever name) instead and reload view with id.
2012-03-07 16:39:56 +01:00
$ ( '#dialog_holder' ) . load ( OC . filePath ( 'contacts' , 'ajax' , 'editname.php' ) + '?id=' + this . id , function ( jsondata ) {
if ( jsondata . status != 'error' ) {
$ ( '#edit_name_dialog' ) . dialog ( {
2012-02-06 14:18:40 +01:00
modal : ( isnew && true || false ) ,
closeOnEscape : ( isnew == '' && false || true ) ,
title : ( isnew && t ( 'contacts' , 'Add contact' ) || t ( 'contacts' , 'Edit name' ) ) ,
2012-02-06 07:32:57 +01:00
height : 'auto' , width : 'auto' ,
buttons : {
'Ok' : function ( ) {
Contacts . UI . Card . saveName ( this ) ;
$ ( this ) . dialog ( 'destroy' ) . remove ( ) ;
} ,
'Cancel' : function ( ) { $ ( this ) . dialog ( 'destroy' ) . remove ( ) ; }
} ,
close : function ( event , ui ) {
$ ( this ) . dialog ( 'destroy' ) . remove ( ) ;
//return event;
} / * ,
open : function ( event , ui ) {
// load 'N' property - maybe :-P
} * /
2012-03-07 16:39:56 +01:00
} ) ;
} else {
2012-03-12 14:12:27 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-03-07 16:39:56 +01:00
}
2012-02-06 07:32:57 +01:00
} ) ;
}
} ,
saveName : function ( dlg ) {
console . log ( 'saveName, id: ' + this . id ) ;
2012-02-06 14:18:40 +01:00
var n = new Array ( $ ( dlg ) . find ( '#fam' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#giv' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#add' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#pre' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#suf' ) . val ( ) . strip _tags ( ) ) ;
2012-02-06 07:32:57 +01:00
this . famname = n [ 0 ] ;
this . givname = n [ 1 ] ;
this . addname = n [ 2 ] ;
this . honpre = n [ 3 ] ;
this . honsuf = n [ 4 ] ;
2012-02-10 07:21:56 +01:00
this . fullname = '' ;
2012-02-08 08:33:51 +01:00
2012-02-06 07:32:57 +01:00
$ ( '#n' ) . val ( n . join ( ';' ) ) ;
if ( n [ 3 ] . length > 0 ) {
this . fullname = n [ 3 ] + ' ' ;
}
this . fullname += n [ 1 ] + ' ' + n [ 2 ] + ' ' + n [ 0 ] ;
if ( n [ 4 ] . length > 0 ) {
this . fullname += ', ' + n [ 4 ] ;
}
2012-02-10 16:40:40 +01:00
$ ( '#fn_select option' ) . remove ( ) ;
//$('#fn_select').combobox('value', this.fn);
2012-03-07 16:39:56 +01:00
var tmp = [ this . fullname , this . givname + ' ' + this . famname , this . famname + ' ' + this . givname , this . famname + ', ' + this . givname ] ;
var names = new Array ( ) ;
for ( var name in tmp ) {
console . log ( 'idx: ' + names . indexOf ( tmp [ name ] ) ) ;
if ( names . indexOf ( tmp [ name ] ) == - 1 ) {
names . push ( tmp [ name ] ) ;
}
}
2012-02-10 16:40:40 +01:00
$ . each ( names , function ( key , value ) {
$ ( '#fn_select' )
. append ( $ ( '<option></option>' )
. text ( value ) ) ;
} ) ;
2012-02-06 07:32:57 +01:00
if ( this . id == '' ) {
var aid = $ ( dlg ) . find ( '#aid' ) . val ( ) ;
2012-02-06 14:18:40 +01:00
Contacts . UI . Card . add ( n . join ( ';' ) , $ ( '#short' ) . text ( ) , aid ) ;
2012-02-06 07:32:57 +01:00
} else {
Contacts . UI . Card . saveProperty ( $ ( '#n' ) ) ;
}
} ,
loadAddresses : function ( ) {
$ ( '#addresses' ) . hide ( ) ;
2012-03-05 22:02:44 +01:00
$ ( '#addressdisplay dl.propertycontainer' ) . remove ( ) ;
2012-02-06 07:32:57 +01:00
for ( var adr in this . data . ADR ) {
$ ( '#addressdisplay dl' ) . first ( ) . clone ( ) . insertAfter ( $ ( '#addressdisplay dl' ) . last ( ) ) . show ( ) ;
$ ( '#addressdisplay dl' ) . last ( ) . removeClass ( 'template' ) . addClass ( 'propertycontainer' ) ;
$ ( '#addressdisplay dl' ) . last ( ) . data ( 'checksum' , this . data . ADR [ adr ] [ 'checksum' ] ) ;
var adrarray = this . data . ADR [ adr ] [ 'value' ] ;
var adrtxt = '' ;
if ( adrarray [ 0 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adrarray [ 0 ] . strip _tags ( ) + '</li>' ;
}
if ( adrarray [ 1 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adrarray [ 1 ] . strip _tags ( ) + '</li>' ;
}
if ( adrarray [ 2 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adrarray [ 2 ] . strip _tags ( ) + '</li>' ;
}
if ( adrarray [ 3 ] . length > 0 || adrarray [ 5 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adrarray [ 5 ] . strip _tags ( ) + ' ' + adrarray [ 3 ] . strip _tags ( ) + '</li>' ;
}
if ( adrarray [ 4 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adrarray [ 4 ] . strip _tags ( ) + '</li>' ;
}
if ( adrarray [ 6 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adrarray [ 6 ] . strip _tags ( ) + '</li>' ;
}
$ ( '#addressdisplay dl' ) . last ( ) . find ( '.addresslist' ) . html ( adrtxt ) ;
var types = new Array ( ) ;
var ttypes = new Array ( ) ;
for ( var param in this . data . ADR [ adr ] [ 'parameters' ] ) {
if ( param . toUpperCase ( ) == 'TYPE' ) {
types . push ( t ( 'contacts' , ucwords ( this . data . ADR [ adr ] [ 'parameters' ] [ param ] . toLowerCase ( ) ) ) ) ;
ttypes . push ( this . data . ADR [ adr ] [ 'parameters' ] [ param ] ) ;
}
}
$ ( '#addressdisplay dl' ) . last ( ) . find ( '.adr_type_label' ) . text ( types . join ( '/' ) ) ;
$ ( '#addressdisplay dl' ) . last ( ) . find ( '.adr_type' ) . val ( ttypes . join ( ',' ) ) ;
$ ( '#addressdisplay dl' ) . last ( ) . find ( '.adr' ) . val ( adrarray . join ( ';' ) ) ;
$ ( '#addressdisplay dl' ) . last ( ) . data ( 'checksum' , this . data . ADR [ adr ] [ 'checksum' ] ) ;
}
if ( $ ( '#addressdisplay dl' ) . length > 1 ) {
$ ( '#addresses' ) . show ( ) ;
2012-02-06 08:15:23 +01:00
$ ( '#contact_communication' ) . show ( ) ;
2012-02-06 07:32:57 +01:00
}
Contacts . UI . loadListHandlers ( ) ;
return false ;
} ,
editAddress : function ( obj , isnew ) {
console . log ( 'editAddress' ) ;
var container = undefined ;
var q = q = '?id=' + this . id ;
if ( obj === 'new' ) {
isnew = true ;
$ ( '#addressdisplay dl' ) . first ( ) . clone ( ) . insertAfter ( $ ( '#addressdisplay dl' ) . last ( ) ) . show ( ) ;
container = $ ( '#addressdisplay dl' ) . last ( ) ;
container . removeClass ( 'template' ) . addClass ( 'propertycontainer' ) ;
Contacts . UI . loadListHandlers ( ) ;
} else {
q = q + '&checksum=' + Contacts . UI . checksumFor ( obj ) ;
}
/* Initialize the address edit dialog */
if ( $ ( '#edit_address_dialog' ) . dialog ( 'isOpen' ) == true ) {
$ ( '#edit_address_dialog' ) . dialog ( 'moveToTop' ) ;
} else {
2012-03-07 16:39:56 +01:00
$ ( '#dialog_holder' ) . load ( OC . filePath ( 'contacts' , 'ajax' , 'editaddress.php' ) + q , function ( jsondata ) {
if ( jsondata . status != 'error' ) {
$ ( '#edit_address_dialog' ) . dialog ( {
2012-02-06 07:32:57 +01:00
/*modal: true,*/
height : 'auto' , width : 'auto' ,
buttons : {
'Ok' : function ( ) {
if ( isnew ) {
Contacts . UI . Card . saveAddress ( this , $ ( '#addressdisplay dl:last-child' ) . find ( 'input' ) . first ( ) , isnew ) ;
} else {
Contacts . UI . Card . saveAddress ( this , obj , isnew ) ;
}
$ ( this ) . dialog ( 'destroy' ) . remove ( ) ;
} ,
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'destroy' ) . remove ( ) ;
if ( isnew ) {
container . remove ( ) ;
}
2012-04-03 03:28:12 +02:00
//Contacts.UI.showHideContactInfo();
2012-02-06 07:32:57 +01:00
}
} ,
close : function ( event , ui ) {
//alert('close');
$ ( this ) . dialog ( 'destroy' ) . remove ( ) ;
if ( isnew ) {
container . remove ( ) ;
}
2012-04-03 03:28:12 +02:00
//Contacts.UI.showHideContactInfo();
2012-04-03 07:29:47 +02:00
} ,
2012-02-06 07:32:57 +01:00
open : function ( event , ui ) {
2012-04-03 07:29:47 +02:00
$ ( "#adr_city" ) . autocomplete ( {
source : function ( request , response ) {
$ . ajax ( {
url : "http://ws.geonames.org/searchJSON" ,
dataType : "jsonp" ,
data : {
featureClass : "P" ,
style : "full" ,
maxRows : 12 ,
2012-04-03 08:13:10 +02:00
lang : lang ,
2012-04-03 07:29:47 +02:00
name _startsWith : request . term
} ,
success : function ( data ) {
response ( $ . map ( data . geonames , function ( item ) {
/ * f o r ( v a r k e y i n i t e m ) {
console . log ( key + ': ' + item [ key ] ) ;
} * /
return {
label : item . name + ( item . adminName1 ? ", " + item . adminName1 : "" ) + ", " + item . countryName ,
value : item . name ,
country : item . countryName
}
} ) ) ;
}
} ) ;
} ,
minLength : 2 ,
select : function ( event , ui ) {
2012-04-03 08:13:10 +02:00
if ( ui . item && $ ( '#adr_country' ) . val ( ) . trim ( ) . length == 0 ) {
2012-04-03 07:29:47 +02:00
$ ( '#adr_country' ) . val ( ui . item . country ) ;
}
/ * l o g ( u i . i t e m ?
"Selected: " + ui . item . label :
"Nothing selected, input was " + this . value ) ; * /
} ,
open : function ( ) {
$ ( this ) . removeClass ( "ui-corner-all" ) . addClass ( "ui-corner-top" ) ;
} ,
close : function ( ) {
$ ( this ) . removeClass ( "ui-corner-top" ) . addClass ( "ui-corner-all" ) ;
}
} ) ;
$ ( "#adr_country" ) . autocomplete ( {
source : function ( request , response ) {
$ . ajax ( {
url : "http://ws.geonames.org/searchJSON" ,
dataType : "jsonp" ,
data : {
/*featureClass: "A",*/
featureCode : "PCLI" ,
/*countryBias: "true",*/
/*style: "full",*/
2012-04-03 08:13:10 +02:00
lang : lang ,
2012-04-03 07:29:47 +02:00
maxRows : 12 ,
name _startsWith : request . term
} ,
success : function ( data ) {
response ( $ . map ( data . geonames , function ( item ) {
for ( var key in item ) {
console . log ( key + ': ' + item [ key ] ) ;
}
return {
label : item . name ,
value : item . name
}
} ) ) ;
}
} ) ;
} ,
minLength : 2 ,
select : function ( event , ui ) {
/ * i f ( u i . i t e m ) {
$ ( '#adr_country' ) . val ( ui . item . country ) ;
}
log ( ui . item ?
"Selected: " + ui . item . label :
"Nothing selected, input was " + this . value ) ; * /
} ,
open : function ( ) {
$ ( this ) . removeClass ( "ui-corner-all" ) . addClass ( "ui-corner-top" ) ;
} ,
close : function ( ) {
$ ( this ) . removeClass ( "ui-corner-top" ) . addClass ( "ui-corner-all" ) ;
}
} ) ;
}
2012-03-07 16:39:56 +01:00
} ) ;
} else {
alert ( jsondata . data . message ) ;
}
2012-02-06 07:32:57 +01:00
} ) ;
}
} ,
saveAddress : function ( dlg , obj , isnew ) {
if ( isnew ) {
container = $ ( '#addressdisplay dl' ) . last ( ) ;
obj = $ ( '#addressdisplay dl:last-child' ) . find ( 'input' ) . first ( ) ;
} else {
checksum = Contacts . UI . checksumFor ( obj ) ;
container = Contacts . UI . propertyContainerFor ( obj ) ;
}
2012-02-18 11:42:58 +01:00
var adr = new Array ( $ ( dlg ) . find ( '#adr_pobox' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#adr_extended' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#adr_street' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#adr_city' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#adr_region' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#adr_zipcode' ) . val ( ) . strip _tags ( ) , $ ( dlg ) . find ( '#adr_country' ) . val ( ) . strip _tags ( ) ) ;
2012-02-06 07:32:57 +01:00
$ ( container ) . find ( '.adr' ) . val ( adr . join ( ';' ) ) ;
$ ( container ) . find ( '.adr_type' ) . val ( $ ( dlg ) . find ( '#adr_type' ) . val ( ) ) ;
$ ( container ) . find ( '.adr_type_label' ) . html ( t ( 'contacts' , ucwords ( $ ( dlg ) . find ( '#adr_type' ) . val ( ) . toLowerCase ( ) ) ) ) ;
Contacts . UI . Card . saveProperty ( $ ( container ) . find ( 'input' ) . first ( ) ) ;
var adrtxt = '' ;
if ( adr [ 0 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adr [ 0 ] + '</li>' ;
}
if ( adr [ 1 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adr [ 1 ] + '</li>' ;
}
if ( adr [ 2 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adr [ 2 ] + '</li>' ;
}
if ( adr [ 3 ] . length > 0 || adr [ 5 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adr [ 5 ] + ' ' + adr [ 3 ] + '</li>' ;
}
if ( adr [ 4 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adr [ 4 ] + '</li>' ;
}
if ( adr [ 6 ] . length > 0 ) {
adrtxt = adrtxt + '<li>' + adr [ 6 ] + '</li>' ;
}
$ ( container ) . find ( '.addresslist' ) . html ( adrtxt ) ;
} ,
uploadPhoto : function ( filelist ) {
if ( ! filelist ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'No files selected for upload.' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
return ;
}
//var file = filelist.item(0);
var file = filelist [ 0 ] ;
var target = $ ( '#file_upload_target' ) ;
var form = $ ( '#file_upload_form' ) ;
var totalSize = 0 ;
if ( file . size > $ ( '#max_upload' ) . val ( ) ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'The file you are trying to upload exceed the maximum size for file uploads on this server.' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
return ;
} else {
target . load ( function ( ) {
var response = jQuery . parseJSON ( target . contents ( ) . text ( ) ) ;
if ( response != undefined && response . status == 'success' ) {
Contacts . UI . Card . editPhoto ( response . data . id , response . data . tmp ) ;
//alert('File: ' + file.tmp + ' ' + file.name + ' ' + file.mime);
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( response . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
} ) ;
form . submit ( ) ;
}
} ,
2012-03-07 16:39:56 +01:00
loadPhoto : function ( force ) {
2012-04-03 03:28:12 +02:00
//if(this.data.PHOTO||force==true) {
2012-02-17 09:35:18 +01:00
$ . getJSON ( 'ajax/loadphoto.php' , { 'id' : this . id } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
//alert(jsondata.data.page);
2012-03-13 14:56:03 +01:00
$ ( '#file_upload_form' ) . data ( 'checksum' , jsondata . data . checksum ) ;
2012-02-17 09:35:18 +01:00
$ ( '#contacts_details_photo_wrapper' ) . html ( jsondata . data . page ) ;
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-17 09:35:18 +01:00
}
} ) ;
2012-02-06 07:32:57 +01:00
$ ( '#file_upload_form' ) . show ( ) ;
$ ( '#contacts_propertymenu a[data-type="PHOTO"]' ) . parent ( ) . hide ( ) ;
2012-04-03 03:28:12 +02:00
/ * } e l s e {
2012-02-17 09:35:18 +01:00
$ ( '#contacts_details_photo_wrapper' ) . empty ( ) ;
2012-02-06 07:32:57 +01:00
$ ( '#file_upload_form' ) . hide ( ) ;
$ ( '#contacts_propertymenu a[data-type="PHOTO"]' ) . parent ( ) . show ( ) ;
2012-04-03 03:28:12 +02:00
} * /
2012-02-06 07:32:57 +01:00
} ,
editPhoto : function ( id , tmp _path ) {
//alert('editPhoto: ' + tmp_path);
$ . getJSON ( 'ajax/cropphoto.php' , { 'tmp_path' : tmp _path , 'id' : this . id } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
//alert(jsondata.data.page);
$ ( '#edit_photo_dialog_img' ) . html ( jsondata . data . page ) ;
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
} ) ;
if ( $ ( '#edit_photo_dialog' ) . dialog ( 'isOpen' ) == true ) {
$ ( '#edit_photo_dialog' ) . dialog ( 'moveToTop' ) ;
} else {
$ ( '#edit_photo_dialog' ) . dialog ( 'open' ) ;
}
} ,
savePhoto : function ( ) {
var target = $ ( '#crop_target' ) ;
var form = $ ( '#cropform' ) ;
form . submit ( ) ;
target . load ( function ( ) {
var response = jQuery . parseJSON ( target . contents ( ) . text ( ) ) ;
if ( response != undefined && response . status == 'success' ) {
// load cropped photo.
$ ( '#contacts_details_photo_wrapper' ) . html ( response . data . page ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( response . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
} ) ;
2012-03-27 10:12:30 +02:00
Contacts . UI . Contacts . refreshThumbnail ( this . id ) ;
2012-02-06 07:32:57 +01:00
} ,
addMail : function ( ) {
//alert('addMail');
2012-03-05 22:02:44 +01:00
$ ( '#emaillist li.template:first-child' ) . clone ( ) . appendTo ( $ ( '#emaillist' ) ) . show ( ) ;
$ ( '#emaillist li.template:last-child' ) . removeClass ( 'template' ) . addClass ( 'propertycontainer' ) ;
2012-02-06 07:32:57 +01:00
$ ( '#emaillist li:last-child' ) . find ( 'input[type="email"]' ) . focus ( ) ;
Contacts . UI . loadListHandlers ( ) ;
return false ;
} ,
loadMails : function ( ) {
$ ( '#emails' ) . hide ( ) ;
2012-03-05 22:02:44 +01:00
$ ( '#emaillist li.propertycontainer' ) . remove ( ) ;
2012-02-06 07:32:57 +01:00
for ( var mail in this . data . EMAIL ) {
this . addMail ( ) ;
//$('#emaillist li:first-child').clone().appendTo($('#emaillist')).show();
$ ( '#emaillist li:last-child' ) . data ( 'checksum' , this . data . EMAIL [ mail ] [ 'checksum' ] )
$ ( '#emaillist li:last-child' ) . find ( 'input[type="email"]' ) . val ( this . data . EMAIL [ mail ] [ 'value' ] ) ;
for ( var param in this . data . EMAIL [ mail ] [ 'parameters' ] ) {
if ( param . toUpperCase ( ) == 'PREF' ) {
$ ( '#emaillist li:last-child' ) . find ( 'input[type="checkbox"]' ) . attr ( 'checked' , 'checked' )
}
}
}
if ( $ ( '#emaillist li' ) . length > 1 ) {
$ ( '#emails' ) . show ( ) ;
2012-02-06 08:15:23 +01:00
$ ( '#contact_communication' ) . show ( ) ;
2012-02-06 07:32:57 +01:00
}
$ ( '#emaillist li:last-child' ) . find ( 'input[type="text"]' ) . focus ( ) ;
Contacts . UI . loadListHandlers ( ) ;
return false ;
} ,
addPhone : function ( ) {
2012-03-05 22:02:44 +01:00
$ ( '#phonelist li.template:first-child' ) . clone ( ) . appendTo ( $ ( '#phonelist' ) ) ; //.show();
$ ( '#phonelist li.template:last-child' ) . find ( 'select' ) . addClass ( 'contacts_property' ) ;
$ ( '#phonelist li.template:last-child' ) . removeClass ( 'template' ) . addClass ( 'propertycontainer' ) ;
2012-02-06 07:32:57 +01:00
$ ( '#phonelist li:last-child' ) . find ( 'input[type="text"]' ) . focus ( ) ;
Contacts . UI . loadListHandlers ( ) ;
$ ( '#phonelist li:last-child' ) . find ( 'select' ) . multiselect ( {
noneSelectedText : t ( 'contacts' , 'Select type' ) ,
header : false ,
selectedList : 4 ,
classes : 'typelist'
} ) ;
$ ( '#phonelist li:last-child' ) . show ( ) ;
return false ;
} ,
loadPhones : function ( ) {
$ ( '#phones' ) . hide ( ) ;
2012-03-05 22:02:44 +01:00
$ ( '#phonelist li.propertycontainer' ) . remove ( ) ;
2012-02-06 07:32:57 +01:00
for ( var phone in this . data . TEL ) {
this . addPhone ( ) ;
$ ( '#phonelist li:last-child' ) . find ( 'select' ) . multiselect ( 'destroy' ) ;
$ ( '#phonelist li:last-child' ) . data ( 'checksum' , this . data . TEL [ phone ] [ 'checksum' ] )
$ ( '#phonelist li:last-child' ) . find ( 'input[type="text"]' ) . val ( this . data . TEL [ phone ] [ 'value' ] ) ;
for ( var param in this . data . TEL [ phone ] [ 'parameters' ] ) {
if ( param . toUpperCase ( ) == 'PREF' ) {
$ ( '#phonelist li:last-child' ) . find ( 'input[type="checkbox"]' ) . attr ( 'checked' , 'checked' ) ;
}
else if ( param . toUpperCase ( ) == 'TYPE' ) {
for ( ptype in this . data . TEL [ phone ] [ 'parameters' ] [ param ] ) {
var pt = this . data . TEL [ phone ] [ 'parameters' ] [ param ] [ ptype ] ;
$ ( '#phonelist li:last-child' ) . find ( 'select option' ) . each ( function ( ) {
2012-02-09 19:04:07 +01:00
if ( $ ( this ) . val ( ) . toUpperCase ( ) == pt . toUpperCase ( ) ) {
2012-02-06 07:32:57 +01:00
$ ( this ) . attr ( 'selected' , 'selected' ) ;
}
} ) ;
}
}
}
$ ( '#phonelist li:last-child' ) . find ( 'select' ) . multiselect ( {
noneSelectedText : t ( 'contacts' , 'Select type' ) ,
header : false ,
selectedList : 4 ,
classes : 'typelist'
} ) ;
}
if ( $ ( '#phonelist li' ) . length > 1 ) {
$ ( '#phones' ) . show ( ) ;
2012-02-06 08:15:23 +01:00
$ ( '#contact_communication' ) . show ( ) ;
2012-02-06 07:32:57 +01:00
}
return false ;
} ,
} ,
Addressbooks : {
overview : function ( ) {
if ( $ ( '#chooseaddressbook_dialog' ) . dialog ( 'isOpen' ) == true ) {
$ ( '#chooseaddressbook_dialog' ) . dialog ( 'moveToTop' ) ;
} else {
2012-03-07 16:39:56 +01:00
$ ( '#dialog_holder' ) . load ( OC . filePath ( 'contacts' , 'ajax' , 'chooseaddressbook.php' ) , function ( jsondata ) {
if ( jsondata . status != 'error' ) {
$ ( '#chooseaddressbook_dialog' ) . dialog ( {
width : 600 ,
close : function ( event , ui ) {
$ ( this ) . dialog ( 'destroy' ) . remove ( ) ;
}
} ) ;
} else {
alert ( jsondata . data . message ) ;
}
2012-02-06 07:32:57 +01:00
} ) ;
}
} ,
activation : function ( checkbox , bookid )
{
$ . post ( OC . filePath ( 'contacts' , 'ajax' , 'activation.php' ) , { bookid : bookid , active : checkbox . checked ? 1 : 0 } ,
function ( data ) {
if ( data . status == 'success' ) {
checkbox . checked = data . active == 1 ;
Contacts . UI . Contacts . update ( ) ;
}
} ) ;
} ,
newAddressbook : function ( object ) {
var tr = $ ( document . createElement ( 'tr' ) )
. load ( OC . filePath ( 'contacts' , 'ajax' , 'addbook.php' ) ) ;
$ ( object ) . closest ( 'tr' ) . after ( tr ) . hide ( ) ;
/* TODO: Shouldn't there be some kinda error checking here? */
} ,
editAddressbook : function ( object , bookid ) {
var tr = $ ( document . createElement ( 'tr' ) )
. load ( OC . filePath ( 'contacts' , 'ajax' , 'editaddressbook.php' ) + "?bookid=" + bookid ) ;
$ ( object ) . closest ( 'tr' ) . after ( tr ) . hide ( ) ;
} ,
deleteAddressbook : function ( bookid ) {
var check = confirm ( "Do you really want to delete this address book?" ) ;
if ( check == false ) {
return false ;
} else {
$ . post ( OC . filePath ( 'contacts' , 'ajax' , 'deletebook.php' ) , { id : bookid } ,
2012-02-20 15:24:54 +01:00
function ( jsondata ) {
if ( jsondata . status == 'success' ) {
2012-02-06 07:32:57 +01:00
$ ( '#chooseaddressbook_dialog' ) . dialog ( 'destroy' ) . remove ( ) ;
Contacts . UI . Contacts . update ( ) ;
Contacts . UI . Addressbooks . overview ( ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
//alert('Error: ' + data.message);
}
} ) ;
}
} ,
2012-04-10 21:53:36 +02:00
doImport : function ( ) {
2012-02-06 07:32:57 +01:00
Contacts . UI . notImplemented ( ) ;
} ,
submit : function ( button , bookid ) {
2012-02-20 15:24:54 +01:00
var displayname = $ ( "#displayname_" + bookid ) . val ( ) . trim ( ) ;
2012-02-06 07:32:57 +01:00
var active = $ ( "#edit_active_" + bookid + ":checked" ) . length ;
var description = $ ( "#description_" + bookid ) . val ( ) ;
2012-02-20 15:24:54 +01:00
if ( displayname . length == 0 ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'Displayname cannot be empty.' ) , t ( 'contacts' , 'Error' ) ) ;
2012-02-20 15:24:54 +01:00
return false ;
}
2012-02-06 07:32:57 +01:00
var url ;
if ( bookid == 'new' ) {
url = OC . filePath ( 'contacts' , 'ajax' , 'createaddressbook.php' ) ;
} else {
url = OC . filePath ( 'contacts' , 'ajax' , 'updateaddressbook.php' ) ;
}
$ . post ( url , { id : bookid , name : displayname , active : active , description : description } ,
2012-02-20 15:24:54 +01:00
function ( jsondata ) {
if ( jsondata . status == 'success' ) {
2012-02-21 23:15:26 +01:00
$ ( button ) . closest ( 'tr' ) . prev ( ) . html ( jsondata . page ) . show ( ) . next ( ) . remove ( ) ;
2012-02-20 15:24:54 +01:00
Contacts . UI . Contacts . update ( ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
} ) ;
} ,
cancel : function ( button , bookid ) {
$ ( button ) . closest ( 'tr' ) . prev ( ) . show ( ) . next ( ) . remove ( ) ;
}
} ,
Contacts : {
2012-04-07 16:03:11 +02:00
// Reload the contacts list.
2012-02-06 07:32:57 +01:00
update : function ( ) {
2012-02-14 13:57:11 +01:00
console . log ( 'Contacts.update, start' ) ;
2012-02-06 07:32:57 +01:00
$ . getJSON ( 'ajax/contacts.php' , { } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
$ ( '#contacts' ) . html ( jsondata . data . page ) ;
2012-02-14 13:57:11 +01:00
Contacts . UI . Card . update ( ) ;
2012-02-06 07:32:57 +01:00
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
//alert(jsondata.data.message);
}
} ) ;
setTimeout ( Contacts . UI . Contacts . lazyupdate , 500 ) ;
} ,
2012-04-07 16:03:11 +02:00
// Add thumbnails to the contact list as they become visible in the viewport.
2012-02-06 07:32:57 +01:00
lazyupdate : function ( ) {
$ ( '#contacts li' ) . live ( 'inview' , function ( ) {
if ( ! $ ( this ) . find ( 'a' ) . attr ( 'style' ) ) {
$ ( this ) . find ( 'a' ) . css ( 'background' , 'url(thumbnail.php?id=' + $ ( this ) . data ( 'id' ) + ') no-repeat' ) ;
}
} ) ;
2012-03-27 10:12:30 +02:00
} ,
refreshThumbnail : function ( id ) {
$ ( '#contacts [data-id="' + id + '"]' ) . find ( 'a' ) . css ( 'background' , 'url(thumbnail.php?id=' + id + '&refresh=1' + Math . random ( ) + ') no-repeat' ) ;
2012-02-06 07:32:57 +01:00
}
}
}
}
$ ( document ) . ready ( function ( ) {
Contacts . UI . loadHandlers ( ) ;
2012-03-12 14:12:27 +01:00
OCCategories . changed = Contacts . UI . Card . categoriesChanged ;
OCCategories . app = 'contacts' ;
2012-02-06 07:32:57 +01:00
$ ( '#chooseaddressbook' ) . click ( function ( ) {
Contacts . UI . Addressbooks . overview ( ) ;
return false ;
} ) ;
$ ( '#contacts_newcontact' ) . click ( function ( ) {
Contacts . UI . Card . editNew ( ) ;
} ) ;
/ * *
* Load the details view for a contact .
* /
$ ( '#leftcontent li' ) . live ( 'click' , function ( ) {
var id = $ ( this ) . data ( 'id' ) ;
2012-03-29 15:24:32 +02:00
$ ( this ) . addClass ( 'active' ) ;
2012-02-06 07:32:57 +01:00
var oldid = $ ( '#rightcontent' ) . data ( 'id' ) ;
if ( oldid != 0 ) {
$ ( '#leftcontent li[data-id="' + oldid + '"]' ) . removeClass ( 'active' ) ;
}
$ . getJSON ( 'ajax/contactdetails.php' , { 'id' : id } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
Contacts . UI . Card . loadContact ( jsondata . data ) ;
}
else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
//alert(jsondata.data.message);
}
} ) ;
return false ;
} ) ;
$ ( '#contacts_deletecard' ) . live ( 'click' , function ( ) {
2012-04-10 21:53:36 +02:00
Contacts . UI . Card . doDelete ( ) ;
2012-02-06 07:32:57 +01:00
} ) ;
$ ( '#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' ) {
// top part of element is visible
} else if ( visiblePartY == 'bottom' ) {
// bottom part of element is visible
} else {
// whole part of element is visible
if ( ! $ ( this ) . find ( 'a' ) . attr ( 'style' ) ) {
//alert($(this).data('id') + ' has background: ' + $(this).attr('style'));
$ ( this ) . find ( 'a' ) . css ( 'background' , 'url(thumbnail.php?id=' + $ ( this ) . data ( 'id' ) + ') no-repeat' ) ;
} / * else {
alert ( $ ( this ) . data ( 'id' ) + ' has style ' + $ ( this ) . attr ( 'style' ) . match ( 'url' ) ) ;
} * /
}
} else {
// element has gone out of viewport
}
} ) ;
$ ( '.button' ) . tipsy ( ) ;
// Triggers invisible file input
$ ( '#contacts_details_photo' ) . live ( 'click' , function ( ) {
$ ( '#file_upload_start' ) . trigger ( 'click' ) ;
return false ;
} ) ;
// NOTE: For some reason the selector doesn't work when I select by '.contacts_property' too...
// I do the filtering in the event handler instead.
2012-03-07 16:39:56 +01:00
//$('input[type="text"],input[type="checkbox"],input[type="email"],input[type="tel"],input[type="date"], select').live('change', function(){
$ ( '.contacts_property' ) . live ( 'change' , function ( ) {
2012-02-06 07:32:57 +01:00
Contacts . UI . Card . saveProperty ( this ) ;
} ) ;
2012-04-21 20:36:17 +02:00
$ ( '#fn' ) . blur ( function ( ) {
if ( $ ( '#fn' ) . val ( ) == '' ) {
OC . dialogs . alert ( t ( 'contacts' , 'The name field cannot be empty. Please enter a name for this contact.' ) , t ( 'contacts' , 'Name is empty' ) , function ( ) { $ ( '#fn' ) . focus ( ) ; } ) ;
$ ( '#fn' ) . focus ( ) ;
return false ;
}
} ) ;
2012-02-06 07:32:57 +01:00
// Name has changed. Update it and reorder.
$ ( '#fn' ) . live ( 'change' , function ( ) {
var name = $ ( '#fn' ) . val ( ) ;
var item = $ ( '#contacts [data-id="' + Contacts . UI . Card . id + '"]' ) . clone ( ) ;
$ ( '#contacts [data-id="' + Contacts . UI . Card . id + '"]' ) . remove ( ) ;
$ ( item ) . find ( 'a' ) . html ( name ) ;
var added = false ;
$ ( '#contacts li' ) . each ( function ( ) {
if ( $ ( this ) . text ( ) . toLowerCase ( ) > name . toLowerCase ( ) ) {
$ ( this ) . before ( item ) . fadeIn ( 'fast' ) ;
added = true ;
return false ;
}
} ) ;
if ( ! added ) {
$ ( '#leftcontent ul' ) . append ( item ) ;
}
} ) ;
/ * *
* Profile picture upload handling
* /
// New profile picture selected
$ ( '#file_upload_start' ) . live ( 'change' , function ( ) {
Contacts . UI . Card . uploadPhoto ( this . files ) ;
} ) ;
$ ( '#contacts_details_photo' ) . bind ( 'dragover' , function ( event ) {
console . log ( 'dragover' ) ;
$ ( event . target ) . css ( 'background-color' , 'red' ) ;
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
} ) ;
$ ( '#contacts_details_photo' ) . bind ( 'dragleave' , function ( event ) {
console . log ( 'dragleave' ) ;
$ ( event . target ) . css ( 'background-color' , 'white' ) ;
//event.stopPropagation();
//event.preventDefault();
} ) ;
$ ( '#contacts_details_photo' ) . bind ( 'drop' , function ( event ) {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
console . log ( 'drop' ) ;
$ ( event . target ) . css ( 'background-color' , 'white' )
$ . fileUpload ( event . originalEvent . dataTransfer . files ) ;
} ) ;
/ * *
* Upload function for dropped files . Should go in the Contacts class / object .
* /
$ . fileUpload = function ( files ) {
var file = files [ 0 ] ;
console . log ( 'size: ' + file . size ) ;
if ( file . size > $ ( '#max_upload' ) . val ( ) ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'The file you are trying to upload exceed the maximum size for file uploads on this server.' ) , t ( 'contacts' , 'Upload too large' ) ) ;
2012-02-06 07:32:57 +01:00
return ;
}
if ( file . type . indexOf ( "image" ) != 0 ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'Only image files can be used as profile picture.' ) , t ( 'contacts' , 'Wrong file type' ) ) ;
2012-02-06 07:32:57 +01:00
return ;
}
var xhr = new XMLHttpRequest ( ) ;
if ( ! xhr . upload ) {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( t ( 'contacts' , 'Your browser doesn\'t support AJAX upload. Please click on the profile picture to select a photo to upload.' ) , t ( 'contacts' , 'Error' ) )
2012-02-06 07:32:57 +01:00
}
fileUpload = xhr . upload ,
xhr . onreadystatechange = function ( ) {
if ( xhr . readyState == 4 ) {
response = $ . parseJSON ( xhr . responseText ) ;
if ( response . status == 'success' ) {
if ( xhr . status == 200 ) {
Contacts . UI . Card . editPhoto ( response . data . id , response . data . tmp ) ;
} else {
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( xhr . status + ': ' + xhr . responseText , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
} else {
//alert(xhr.responseText);
2012-03-07 22:57:37 +01:00
OC . dialogs . alert ( response . data . message , t ( 'contacts' , 'Error' ) ) ;
2012-02-06 07:32:57 +01:00
}
// stop loading indicator
//$('#contacts_details_photo_progress').hide();
}
} ;
fileUpload . onprogress = function ( e ) {
if ( e . lengthComputable ) {
var _progress = Math . round ( ( e . loaded * 100 ) / e . total ) ;
if ( _progress != 100 ) {
$ ( '#contacts_details_photo_progress' ) . text ( _progress + '%' ) ;
$ ( '#contacts_details_photo_progress' ) . val ( _progress ) ;
}
}
} ;
// Start loading indicator.
//$('#contacts_details_photo_progress').show()();
xhr . open ( "POST" , 'ajax/uploadphoto.php?id=' + Contacts . UI . Card . id + '&imagefile=' + encodeURIComponent ( file . name ) , true ) ;
xhr . setRequestHeader ( 'Cache-Control' , 'no-cache' ) ;
xhr . setRequestHeader ( 'X-Requested-With' , 'XMLHttpRequest' ) ;
xhr . setRequestHeader ( 'X_FILE_NAME' , encodeURIComponent ( file . name ) ) ;
//xhr.setRequestHeader("X_FILENAME", file.name);
xhr . setRequestHeader ( 'X-File-Size' , file . size ) ;
xhr . setRequestHeader ( 'Content-Type' , file . type ) ;
xhr . send ( file ) ;
}
2012-03-07 16:39:56 +01:00
$ ( 'body' ) . live ( 'click' , function ( e ) {
if ( ! $ ( e . target ) . is ( '#contacts_propertymenu_button' ) ) {
$ ( '#contacts_propertymenu' ) . hide ( ) ;
}
} ) ;
2012-02-09 19:04:07 +01:00
$ ( '#contacts_propertymenu_button' ) . live ( 'click' , function ( ) {
2012-03-07 16:39:56 +01:00
var menu = $ ( '#contacts_propertymenu' ) ;
if ( menu . is ( ':hidden' ) ) {
menu . show ( ) ;
menu . find ( 'ul' ) . focus ( ) ;
} else {
menu . hide ( ) ;
}
2012-02-09 19:04:07 +01:00
} ) ;
2012-02-06 07:32:57 +01:00
$ ( '#contacts_propertymenu a' ) . live ( 'click' , function ( ) {
2012-04-03 03:28:12 +02:00
var type = $ ( this ) . data ( 'type' ) ;
Contacts . UI . Card . addProperty ( type ) ;
2012-02-09 19:04:07 +01:00
$ ( '#contacts_propertymenu' ) . hide ( ) ;
2012-02-06 07:32:57 +01:00
} ) ;
} ) ;