2022-11-27 20:20:18 +00:00
< div class = " hmax " >
< div id = " tabs " ></ div >
2022-11-28 00:45:53 +00:00
< div id = " tabs-item " data - id = " { id} " >
2022-11-28 14:21:46 +00:00
< a href = " javascript:window.view.instance.load_content(' { id}',true) " >
2022-11-27 20:20:18 +00:00
< div class = " tab-content " >
2022-11-28 00:45:53 +00:00
< i class = " fa fa- { icon} fa-fw " ></ i >
2022-11-27 20:20:18 +00:00
< span > { title } </ span >
</ div >
</ a >
</ div >
< div id = " content " >
< div id = " container " ></ div >
</ div >
2022-11-24 01:35:00 +00:00
</ div >
< script >
2022-11-28 00:45:53 +00:00
window . view . instance = {
show_config : function () {
window . location . hash = window . location . hash . replace ( '#instance/' , '#instance_config/' );
},
2022-11-28 02:03:20 +00:00
do : {
new_accounts : {
approve : function ( _id ) {
window . view . instance . do . new_accounts . _perform ( 'approve' , _id );
},
reject : function ( _id ) {
window . view . instance . do . new_accounts . _perform ( 'reject' , _id );
},
_perform : function ( action , _id ) {
const hargs = get_hash_arguments ();
http . get ( `api/v1/http/${hargs.software}/accounts/${action}/?instance=${hargs.instance}&id=${_id}` ,
{}, function ( js ) {
2022-11-28 14:45:55 +00:00
window . view . instance . load_content ( 'new-accounts' );
2022-11-28 02:03:20 +00:00
});
},
},
},
load : {
new_accounts : function () {
const hargs = get_hash_arguments ();
E . http_template ( 'instance/new-account' , function ( html ) {
E . element ( '#window-instance #container' ) . innerHTML = html ;
http . get ( `api/v1/database/${hargs.software}/get-pending-users/?instance=${hargs.instance}` ,
{}, function ( js ) {
E . template ( 'new-accounts' , function ( TPL ) {
2022-11-28 14:45:55 +00:00
if (( js . count === undefined || js . account === null )
|| js . count === 0 )
return 'There is not any pending accounts' ;
var tpl = TPL ;
tpl = tpl . replaceAll ( '{count}' , js . count );
tpl = tpl . replaceAll ( '{id}' , js . account . id );
tpl = tpl . replaceAll ( '{text}' , html2text ( js . account . text ));
tpl = tpl . replaceAll ( '{email}' , html2text ( js . account . email ));
tpl = tpl . replaceAll ( '{username}' , html2text ( js . account . username ));
tpl = tpl . replaceAll ( '{ip_address}' , html2text ( js . account . sign_up_ip ));
return tpl ;
2022-11-28 02:03:20 +00:00
});
console . log ( js );
});
});
},
2022-12-03 17:54:18 +00:00
filter_users : function () {
E . http_template ( 'instance/filter-users' , function ( html ) {
E . element ( '#window-instance #container' ) . innerHTML = html ;
2022-12-03 23:29:04 +00:00
E . elemid ( 'profile-search-type-simple' ) . onchange = function ( e ) {
if ( e . target . checked ) {
E . element ( 'textarea[name="profile"]' ) . setAttribute ( 'placeholder' , 'Input your text here' );
E . element ( 'textarea[name="profile"]' ) . removeAttribute ( 'disabled' );
}
};
E . elemid ( 'profile-search-type-expr' ) . onchange = function ( e ) {
if ( e . target . checked ) {
E . element ( 'textarea[name="profile"]' ) . setAttribute ( 'placeholder' , '(words "apple banana" AND contains "i like apples") OR words "pineapple strawberry"' );
E . element ( 'textarea[name="profile"]' ) . removeAttribute ( 'disabled' );
}
};
E . elemid ( 'profile-search-type-empty' ) . onchange = function ( e ) {
if ( e . target . checked ) {
E . element ( 'textarea[name="profile"]' ) . setAttribute ( 'placeholder' , '<Profile content is empty>' );
E . element ( 'textarea[name="profile"]' ) . setAttribute ( 'disabled' , 'disabled' );
}
}
2022-12-03 17:54:18 +00:00
E . custom . btncollapse_render ();
});
},
2022-11-28 02:03:20 +00:00
},
2022-11-28 14:21:46 +00:00
load_content : function ( content , hashload ) {
hashload = hashload === undefined ? false : hashload ;
2022-11-28 15:52:57 +00:00
const _empty_content = function () {
E . element ( '#window-instance #container' ) . innerHTML = '' ;
};
2022-11-28 00:45:53 +00:00
switch ( content ) {
case 'home' :
2022-11-28 15:52:57 +00:00
_empty_content ();
2022-11-28 00:45:53 +00:00
window . location . hash = '#home' ;
return ;
case 'settings' :
2022-11-28 15:52:57 +00:00
_empty_content ();
2022-11-28 00:45:53 +00:00
return window . view . instance . show_config ();
2022-11-28 02:03:20 +00:00
default :
2022-11-28 14:21:46 +00:00
if ( hashload === true )
return set_hash_argument ( 'content' , content );
2022-11-28 15:52:57 +00:00
_empty_content ();
2022-11-28 02:03:20 +00:00
return window . view . instance
. load [ content . replaceAll ( '-' , '_' )]();
2022-11-28 00:45:53 +00:00
}
},
};
2022-11-24 23:21:52 +00:00
function title__instance () {}
2022-11-24 01:35:00 +00:00
function load__instance ( args ) {
2022-11-28 02:03:20 +00:00
const hargs = get_hash_arguments ();
2022-11-24 01:35:00 +00:00
const _error400 = function ( msg ) {
msg = msg || 'Parameters are not correct' ;
console . log ( 'TODO: handle error correctly' );
};
const _paint = function () {
2022-11-27 20:20:18 +00:00
const menu = [
{
2022-11-28 00:45:53 +00:00
id : 'home' ,
title : '' ,
icon : 'home' ,
},
{
id : 'filter-users' ,
title : 'Users filter' ,
icon : 'user' ,
2022-11-27 20:20:18 +00:00
},
{
2022-11-28 00:45:53 +00:00
id : 'filter-posts' ,
title : 'Posts filter' ,
icon : 'file-text' ,
2022-11-27 20:20:18 +00:00
},
{
2022-11-28 00:45:53 +00:00
id : 'new-accounts' ,
2022-11-27 20:20:18 +00:00
title : 'New accounts' ,
2022-11-28 00:45:53 +00:00
icon : 'user-plus' ,
},
{
id : 'settings' ,
title : hargs [ 'instance' ],
icon : 'gear' ,
2022-11-27 20:20:18 +00:00
},
];
E . template ( 'tabs' , function ( TPL ) {
var html = '' ;
for ( var i = 0 ; i < menu . length ; i ++ ) {
var tpl = TPL ;
2022-11-28 00:45:53 +00:00
tpl = tpl . replaceAll ( '{id}' , menu [ i ][ 'id' ]);
2022-11-27 20:20:18 +00:00
tpl = tpl . replaceAll ( '{title}' , menu [ i ][ 'title' ]);
2022-11-28 00:45:53 +00:00
tpl = tpl . replaceAll ( '{icon}' , menu [ i ][ 'icon' ]);
2022-11-27 20:20:18 +00:00
html += tpl ;
}
return html ;
});
2022-11-28 13:25:12 +00:00
if ( hargs [ 'content' ] !== undefined )
window . view . instance . load_content ( hargs [ 'content' ]);
2022-11-24 01:35:00 +00:00
};
const _main = function () {
if ( hargs [ 'software' ] === undefined ||
! window . vars [ 'instance_config' ][ 'supported_ap_software' ]
. includes ( hargs [ 'software' ]))
return _error400 ();
if ( hargs [ 'instance' ] === undefined )
return _error400 ();
var found = false ;
for ( var i = 0 ; i < window . vars [ 'instance_config' ][ 'hosts' ][ hargs [ 'software' ]] . length ; i ++ )
{
const item = window . vars [ 'instance_config' ][ 'hosts' ][ hargs [ 'software' ]][ i ];
if ( item [ 'instance' ] === hargs [ 'instance' ]) {
window . vars [ 'current_instance' ] = item ;
found = true ;
break ;
}
}
if ( ! found )
return _error400 ();
2022-11-24 23:21:52 +00:00
apcontrol_title ( `Instance (${hargs['instance']})` );
const config = parse_ini_config ( window . vars [ 'current_instance' ][ 'config' ]);
2022-11-27 20:20:18 +00:00
const musthave = window . consts [ 'instance_config' ][ hargs [ 'software' ]][ 'musthave' ];
for ( var i = 0 ; i < musthave . length ; i ++ ) {
if ( config [ musthave [ i ]] === undefined ) {
2022-11-28 00:45:53 +00:00
window . view . instance . show_config ();
2022-11-27 20:20:18 +00:00
return false ;
2022-11-24 23:21:52 +00:00
}
}
return _paint ();
2022-11-24 01:35:00 +00:00
};
if ( window . vars [ 'instance_config' ] === undefined ) {
http . get ( 'api/v1/config/get' ,{}, function ( data ) {
window . vars [ 'instance_config' ] = JSON . parse ( data );
_main ();
});
} else { _main () }
}
</ script >