@ -171,13 +171,14 @@ Contacts={
} ) ; * /
// Name has changed. Update it and reorder.
// TODO: Take addressbook into account
$ ( '#fn' ) . change ( function ( ) {
var name = $ ( '#fn' ) . val ( ) . strip _tags ( ) ;
var item = $ ( '# contacts [data-id="' + Contacts . UI . Card . id + '"]' ) ;
var item = $ ( '. contacts [data-id="' + Contacts . UI . Card . id + '"]' ) ;
$ ( item ) . find ( 'a' ) . html ( name ) ;
Contacts . UI . Card . fn = name ;
var added = false ;
$ ( '#c ontacts l i' ) . each ( function ( ) {
$ ( '.contacts li[data-bookid="' + C ontacts . UI . Card . book id + '"] ') . each ( function ( ) {
if ( $ ( this ) . text ( ) . toLowerCase ( ) > name . toLowerCase ( ) ) {
$ ( this ) . before ( item ) . fadeIn ( 'fast' ) ;
added = true ;
@ -185,7 +186,7 @@ Contacts={
}
} ) ;
if ( ! added ) {
$ ( '#leftcontent ul' ) . append ( item ) ;
$ ( '#leftcontent ul[data-id="' + Contacts . UI . Card . bookid + '"] ' ) . append ( item ) ;
}
Contacts . UI . Contacts . scrollTo ( Contacts . UI . Card . id ) ;
} ) ;
@ -245,19 +246,21 @@ Contacts={
honpre : '' ,
honsuf : '' ,
data : undefined ,
update : function ( id ) {
var newid ;
update : function ( id , bookid ) {
var newid , firstitem ;
if ( ! id ) {
newid = $ ( '#contacts li:first-child' ) . data ( 'id' ) ;
firstitem = $ ( '#contacts:first-child li:first-child' ) ;
newid = firstitem . data ( 'id' ) ;
bookid = firstitem . data ( 'bookid' ) ;
} else {
newid = id ;
}
var localLoadContact = function ( id ) {
if ( $ ( '# contacts li' ) . length > 0 ) {
$ ( '#leftcontent li[data-id="' + newid + '"]' ) . addClass ( 'active' ) ;
var localLoadContact = function ( newid , book id) {
if ( $ ( '. contacts li' ) . length > 0 ) {
firstitem . addClass ( 'active' ) ;
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'contactdetails.php' ) , { 'id' : newid } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
Contacts . UI . Card . loadContact ( jsondata . data ) ;
Contacts . UI . Card . loadContact ( jsondata . data , bookid ) ;
} else {
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
}
@ -271,14 +274,14 @@ Contacts={
if ( jsondata . status == 'success' ) {
$ ( '#rightcontent' ) . html ( jsondata . data . page ) . ready ( function ( ) {
Contacts . UI . loadHandlers ( ) ;
localLoadContact ( newid ) ;
localLoadContact ( newid , bookid ) ;
} ) ;
} else {
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
}
} ) ;
}
else if ( $ ( '# contacts li' ) . length == 0 ) {
else if ( $ ( '. contacts li' ) . length == 0 ) {
// load intro page
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'loadintro.php' ) , { } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
@ -291,7 +294,7 @@ Contacts={
} ) ;
}
else {
localLoadContact ( ) ;
localLoadContact ( newid , bookid ) ;
}
} ,
doExport : function ( ) {
@ -315,7 +318,7 @@ Contacts={
var id = jsondata . data . id ;
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'contactdetails.php' ) , { 'id' : id } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
Contacts . UI . Card . loadContact ( jsondata . data ) ;
Contacts . UI . Card . loadContact ( jsondata . data , aid ) ;
$ ( '#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(' + OC . filePath ( 'contacts' , '' , 'thumbnail.php' ) + '?id=' + jsondata . data . id + ') no-repeat scroll 0% 0% transparent;">' + Contacts . UI . Card . fn + '</a></li>' ) ;
var added = false ;
@ -370,7 +373,7 @@ Contacts={
if ( answer == true ) {
$ . post ( OC . filePath ( 'contacts' , 'ajax' , 'deletecard.php' ) , { 'id' : Contacts . UI . Card . id } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
var newid = '' ;
var newid = '' , bookid ;
var curlistitem = $ ( '#leftcontent [data-id="' + jsondata . data . id + '"]' ) ;
var newlistitem = curlistitem . prev ( ) ;
if ( newlistitem == undefined ) {
@ -379,13 +382,14 @@ Contacts={
curlistitem . remove ( ) ;
if ( newlistitem != undefined ) {
newid = newlistitem . data ( 'id' ) ;
bookid = newlistitem . data ( 'id' ) ;
}
$ ( '#rightcontent' ) . data ( 'id' , newid ) ;
this . id = this . fn = this . fullname = this . shortname = this . famname = this . givname = this . addname = this . honpre = this . honsuf = '' ;
this . data = undefined ;
if ( $ ( '# contacts li' ) . length > 0 ) { // Load first in list.
Contacts . UI . Card . update ( newid ) ;
if ( $ ( '. contacts li' ) . length > 0 ) { // Load first in list.
Contacts . UI . Card . update ( newid , bookid ) ;
} else {
// load intro page
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'loadintro.php' ) , { } , function ( jsondata ) {
@ -408,9 +412,10 @@ Contacts={
} ) ;
return false ;
} ,
loadContact : function ( jsondata ) {
loadContact : function ( jsondata , bookid ) {
this . data = jsondata ;
this . id = this . data . id ;
this . bookid = bookid ;
$ ( '#rightcontent' ) . data ( 'id' , this . id ) ;
this . populateNameFields ( ) ;
this . loadPhoto ( ) ;
@ -1498,39 +1503,50 @@ Contacts={
update : function ( ) {
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'contacts.php' ) , { } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
$ ( '#contacts' ) . html ( jsondata . data . page ) ;
$ ( '#contacts' ) . html ( jsondata . data . page ) . ready ( function ( ) {
/ * s e t T i m e o u t ( f u n c t i o n ( ) {
$ ( '.contacts li' ) . unbind ( 'inview' ) ;
$ ( '.contacts li:visible' ) . bind ( 'inview' , function ( event , isInView , visiblePartX , visiblePartY ) {
if ( isInView ) {
if ( ! $ ( this ) . find ( 'a' ) . attr ( 'style' ) ) {
$ ( this ) . find ( 'a' ) . css ( 'background' , 'url(' + OC . filePath ( 'contacts' , '' , 'thumbnail.php' ) + '?id=' + $ ( this ) . data ( 'id' ) + ') no-repeat' ) ;
}
}
} ) } , 100 ) ;
setTimeout ( Contacts . UI . Contacts . lazyupdate , 500 ) ; * /
} ) ;
Contacts . UI . Card . update ( ) ;
}
else {
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
}
} ) ;
setTimeout ( function ( ) {
$ ( '#contacts li' ) . unbind ( 'inview' ) ;
$ ( '#contacts li' ) . bind ( 'inview' , function ( event , isInView , visiblePartX , visiblePartY ) {
/ * s e t T i m e o u t ( f u n c t i o n ( ) {
$ ( '. contacts li' ) . unbind ( 'inview' ) ;
$ ( '.contacts li:visible ' ) . bind ( 'inview' , function ( event , isInView , visiblePartX , visiblePartY ) {
if ( isInView ) {
if ( ! $ ( this ) . find ( 'a' ) . attr ( 'style' ) ) {
$ ( this ) . find ( 'a' ) . css ( 'background' , 'url(' + OC . filePath ( 'contacts' , '' , 'thumbnail.php' ) + '?id=' + $ ( this ) . data ( 'id' ) + ') no-repeat' ) ;
}
}
} ) } , 500 ) ;
setTimeout ( Contacts . UI . Contacts . lazyupdate , 500 ) ;
setTimeout ( Contacts . UI . Contacts . lazyupdate , 500 ) ; * /
} ,
// Add thumbnails to the contact list as they become visible in the viewport.
lazyupdate : function ( ) {
$ ( '# contacts li' ) . live ( 'inview' , function ( ) {
$ ( '. contacts li' ) . live ( 'inview' , function ( ) {
if ( ! $ ( this ) . find ( 'a' ) . attr ( 'style' ) ) {
$ ( this ) . find ( 'a' ) . css ( 'background' , 'url(' + OC . filePath ( 'contacts' , '' , 'thumbnail.php' ) + '?id=' + $ ( this ) . data ( 'id' ) + ') no-repeat' ) ;
}
} ) ;
} ,
refreshThumbnail : function ( id ) {
var item = $ ( '# contacts [data-id="' + id + '"]' ) . find ( 'a' ) ;
var item = $ ( '. contacts [data-id="' + id + '"]' ) . find ( 'a' ) ;
item . html ( Contacts . UI . Card . fn ) ;
item . css ( 'background' , 'url(' + OC . filePath ( 'contacts' , '' , 'thumbnail.php' ) + '?id=' + id + '&refresh=1' + Math . random ( ) + ') no-repeat' ) ;
} ,
scrollTo : function ( id ) {
$ ( '# contacts' ) . animate ( {
$ ( '. contacts' ) . animate ( {
scrollTop : $ ( '#leftcontent li[data-id="' + id + '"]' ) . offset ( ) . top - 20 } , 'slow' , 'swing' ) ;
}
}
@ -1552,24 +1568,25 @@ $(document).ready(function(){
$ ( '#contacts_newcontact' ) . keydown ( Contacts . UI . Card . editNew ) ;
// Load a contact.
$ ( '# contacts' ) . keydown ( function ( event ) {
$ ( '. contacts' ) . keydown ( function ( event ) {
if ( event . which == 13 ) {
$ ( '# contacts' ) . click ( ) ;
$ ( '. contacts' ) . click ( ) ;
}
} ) ;
$ ( '#contacts' ) . click ( function ( event ) {
$ ( document ) . on ( 'click' , '.contacts' , function ( event ) {
var $tgt = $ ( event . target ) ;
if ( $tgt . is ( 'li' ) || $tgt . is ( 'a' ) ) {
var item = $tgt . is ( 'li' ) ? $ ( $tgt ) : ( $tgt ) . parent ( ) ;
var id = item . data ( 'id' ) ;
var bookid = item . data ( 'bookid' ) ;
item . addClass ( 'active' ) ;
var oldid = $ ( '#rightcontent' ) . data ( 'id' ) ;
if ( oldid != 0 ) {
$ ( '# contacts li[data-id="' + oldid + '"]' ) . removeClass ( 'active' ) ;
$ ( '. contacts li[data-id="' + oldid + '"]' ) . removeClass ( 'active' ) ;
}
$ . getJSON ( OC . filePath ( 'contacts' , 'ajax' , 'contactdetails.php' ) , { 'id' : id } , function ( jsondata ) {
if ( jsondata . status == 'success' ) {
Contacts . UI . Card . loadContact ( jsondata . data ) ;
Contacts . UI . Card . loadContact ( jsondata . data , bookid ) ;
}
else {
OC . dialogs . alert ( jsondata . data . message , t ( 'contacts' , 'Error' ) ) ;
@ -1579,7 +1596,12 @@ $(document).ready(function(){
return false ;
} ) ;
$ ( '#contacts li' ) . bind ( 'inview' , function ( event , isInView , visiblePartX , visiblePartY ) {
$ ( document ) . on ( 'click' , '.addressbook' , function ( event ) {
$ ( this ) . next ( ) . slideToggle ( 300 ) ;
return false ;
} ) ;
/ * $ ( ' . c o n t a c t s l i ' ) . b i n d ( ' i n v i e w ' , f u n c t i o n ( e v e n t , i s I n V i e w , v i s i b l e P a r t X , v i s i b l e P a r t Y ) {
if ( isInView ) { //NOTE: I've kept all conditions for future reference ;-)
// element is now visible in the viewport
if ( visiblePartY == 'top' ) {
@ -1591,14 +1613,14 @@ $(document).ready(function(){
if ( ! $ ( this ) . find ( 'a' ) . attr ( 'style' ) ) {
//alert($(this).data('id') + ' has background: ' + $(this).attr('style'));
$ ( this ) . find ( 'a' ) . css ( 'background' , 'url(' + OC . filePath ( 'contacts' , '' , 'thumbnail.php' ) + '?id=' + $ ( this ) . data ( 'id' ) + ') no-repeat' ) ;
} / * else {
alert ( $ ( this ) . data ( 'id' ) + ' has style ' + $ ( this ) . attr ( 'style' ) . match ( 'url' ) ) ;
} * /
} // else {
// alert($(this).data('id') + ' has style ' + $(this).attr('style').match('url'));
//}
}
} else {
// element has gone out of viewport
}
} ) ;
} ) ; * /
$ ( '.contacts_property' ) . live ( 'change' , function ( ) {
Contacts . UI . Card . saveProperty ( this ) ;
@ -1678,3 +1700,4 @@ $(document).ready(function(){
$ ( '#contacts_propertymenu_dropdown a' ) . click ( propertyMenuItem ) ;
$ ( '#contacts_propertymenu_dropdown a' ) . keydown ( propertyMenuItem ) ;
} ) ;
Contacts . UI . Contacts . update ( ) ;