2010-12-17 14:41:45 +00:00
var max _search _results = 8 ;
var groups _visible = true ;
var passwords _visible = false ;
function pwitem _update ( ) {
$ ( '#error' ) . html ( '' ) ;
2013-02-26 01:18:39 +00:00
$ ( '#passwordinfo' ) . hide ( ) ;
$ ( '#info' ) . html ( 'Fetching...' ) ;
2010-12-17 14:41:45 +00:00
$ . post ( 'getpw.php' , { id : $ ( this ) . attr ( 'id' ) . replace ( /^pw_/ , '' ) } , function ( pwxml ) {
pwinfo = $ ( 'result' , pwxml ) ;
if ( pwinfo . length > 0 )
{
2013-02-26 01:18:39 +00:00
$ ( '#passwordinfo > ul > li:eq(0) > span' ) . html ( $ ( 'short' , pwinfo ) . text ( ) ) ;
$ ( '#passwordinfo > ul > li:eq(1) > span' ) . html ( $ ( 'long' , pwinfo ) . text ( ) ) ;
$ ( '#passwordinfo > ul > li:eq(2) > span' ) . html ( $ ( 'username' , pwinfo ) . text ( ) ) ;
$ ( '#passwordinfo > ul > li:eq(3) > span' ) . html ( $ ( 'password' , pwinfo ) . text ( ) ) ;
$ ( '#passwordinfo > ul > li:eq(4) > span' ) . html ( $ ( 'additional' , pwinfo ) . text ( ) ) ;
$ ( '#info' ) . html ( '' ) ;
$ ( '#passwordinfo' ) . show ( ) ;
2010-12-17 14:41:45 +00:00
}
} ) ;
} ;
$ ( document ) . ready ( function ( ) {
$ ( '#passwords' ) . hide ( ) ;
$ ( '#query' ) . keyup ( function ( e ) {
if ( $ ( '#query' ) . val ( ) . length > 2 )
{
$ ( '#error' ) . html ( '' ) ;
$ ( '#results' ) . html ( 'Searching...' ) ;
$ ( '#passwordgroups' ) . hide ( ) ;
$ ( '#passwords' ) . hide ( ) ;
output = '' ;
$ . post ( 'results.php' , { querytext : $ ( '#query' ) . val ( ) } , function ( listxml ) {
results = $ ( 'row' , listxml ) ;
$ ( '#info' ) . html ( 'Search for "' + $ ( 'query' , listxml ) . text ( ) + '" ready after ' + $ ( 'elapsed-time' , listxml ) . text ( ) + ' seconds. ' + results . length + ' records found' + ( ( results . length > max _search _results ) ? ' (top ' + max _search _results + ' shown)' : '' ) + '.' ) ;
if ( results . length > 0 )
{
output += '<ul>' ;
for ( i = 0 ; i < results . length ; i ++ )
{
output += '<li class="pwitem" id="pw_' + $ ( 'id' , results [ i ] ) . text ( ) + '">' + $ ( 'short' , results [ i ] ) . text ( ) + '</li>' ;
if ( i == max _search _results - 1 )
{
break ;
}
}
output += '</ul>' ;
}
$ ( '#results' ) . html ( output ) ;
$ ( '.pwitem' ) . click ( pwitem _update ) ;
} ) ;
}
else
{
$ ( '#error' ) . html ( 'The search string must be at least 3 characters long to search' ) ;
$ ( '#results' ) . html ( '' ) ;
$ ( '#info' ) . html ( '' ) ;
if ( groups _visible )
{
$ ( '#passwordgroups' ) . show ( ) ;
}
else if ( passwords _visible )
{
$ ( '#passwords' ) . show ( ) ;
}
}
} ) ;
$ ( '#clearsearch' ) . click ( function ( e ) {
$ ( '#error' ) . html ( '' ) ;
$ ( '#info' ) . html ( '' ) ;
$ ( '#results' ) . html ( '' ) ;
2013-02-26 01:18:39 +00:00
$ ( '#passwordinfo' ) . hide ( ) ;
2010-12-17 14:41:45 +00:00
$ ( '#query' ) . val ( '' ) ;
if ( groups _visible )
{
$ ( '#passwordgroups' ) . show ( ) ;
}
else if ( passwords _visible )
{
$ ( '#passwords' ) . show ( ) ;
}
} ) ;
pwgnames = $ ( '.pwgname' ) ;
for ( a = 0 ; a < pwgnames . length ; a ++ )
{
$ . post ( 'getpwgname.php' , { name : pwgnames [ a ] . id . replace ( /^pwgname_/ , '' ) } , function ( pwgxml ) {
name = $ ( 'name' , pwgxml ) . text ( ) ;
$ ( '#pwgname_' + name ) . html ( $ ( 'description' , pwgxml ) . text ( ) ) ;
} ) ;
}
$ ( '.pwgname' ) . click ( function ( e ) {
pwgid = this . id . replace ( /^pwgname_/ , '' ) ;
$ ( '#openedgroupname' ) . html ( pwgid ) ;
$ ( '#passwordlist' ) . html ( 'Fetching, please wait...' ) ;
$ . post ( 'getpwgname.php' , { name : pwgid } , function ( pwgxml ) {
$ ( '#openedgroupname' ) . html ( $ ( 'description' , pwgxml ) . text ( ) ) ;
} ) ;
$ . post ( 'getpasswordlist.php' , { group : pwgid } , function ( listxml ) {
results = $ ( 'row' , listxml ) ;
if ( results . length > 0 )
{
output = '<ul>' ;
for ( i = 0 ; i < results . length ; i ++ )
{
output += '<li class="pwitem" id="pw_' + $ ( 'id' , results [ i ] ) . text ( ) + '">' + $ ( 'short' , results [ i ] ) . text ( ) + '</li>' ;
}
output += '</ul>' ;
}
$ ( '#passwordlist' ) . html ( output ) ;
$ ( '.pwitem' ) . click ( pwitem _update ) ;
} ) ;
$ ( '#passwordgroups' ) . hide ( ) ;
$ ( '#passwords' ) . show ( ) ;
} ) ;
$ ( '#showpasswordgroups' ) . click ( function ( e ) {
$ ( '#passwordgroups' ) . show ( ) ;
$ ( '#passwords' ) . hide ( ) ;
2013-02-26 01:18:39 +00:00
$ ( '#passwordinfo' ) . hide ( ) ;
2010-12-17 14:41:45 +00:00
} ) ;
} ) ;