2020-07-16 00:18:27 -04:00
( function ( global , $ ) {
2020-07-24 11:40:00 -04:00
// Define core
let codiad = global . codiad ,
scripts = document . getElementsByTagName ( 'script' ) ,
path = scripts [ scripts . length - 1 ] . src . split ( '?' ) [ 0 ] ,
curpath = path . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) + '/' ;
2020-07-16 00:18:27 -04:00
$ ( document ) . ready ( function ( ) {
2020-07-24 11:40:00 -04:00
codiad . install . init ( ) ;
} ) ;
codiad . install = {
2020-08-19 22:14:12 -04:00
data : { } ,
2020-07-24 11:40:00 -04:00
dbconditions : {
2020-07-16 00:18:27 -04:00
storage : {
values : [
{
action : "hide" ,
value : "filesystem" ,
} ,
{
action : "show" ,
value : "mysql" ,
} ,
{
action : "show" ,
value : "pgsql" ,
}
] ,
} ,
2020-07-24 11:40:00 -04:00
} ,
d : { } ,
form : null ,
2020-07-16 00:18:27 -04:00
2020-07-24 11:40:00 -04:00
init : function ( ) {
2020-07-16 00:18:27 -04:00
2020-07-27 13:20:12 -04:00
let _ = this ;
2020-07-24 11:40:00 -04:00
this . d = {
2020-07-16 00:18:27 -04:00
2020-07-24 11:40:00 -04:00
storage : {
default : "" ,
element : $ ( '<select></select>' ) ,
label : "Data Storage Method: " ,
name : "storage" ,
options : {
"Filesystem" : "filesystem" ,
"MySQL" : "mysql" ,
"PostgreSQL" : "pgsql" ,
} ,
required : true ,
type : "select" ,
2020-07-16 00:18:27 -04:00
} ,
2020-07-24 11:40:00 -04:00
dbhost : {
2020-07-27 13:20:12 -04:00
conditions : $ . extend ( true , { } , _ . dbconditions ) ,
2020-07-24 11:40:00 -04:00
default : "localhost" ,
label : "Database Host: " ,
type : "text" ,
} ,
dbname : {
2020-07-27 13:20:12 -04:00
conditions : $ . extend ( true , { } , _ . dbconditions ) ,
2020-07-24 11:40:00 -04:00
default : "" ,
label : "Database Name: " ,
type : "text" ,
} ,
dbuser : {
2020-07-27 13:20:12 -04:00
conditions : $ . extend ( true , { } , _ . dbconditions ) ,
2020-07-24 11:40:00 -04:00
default : "" ,
label : "Database User: " ,
type : "text" ,
} ,
dbpass : {
2020-07-27 13:20:12 -04:00
conditions : $ . extend ( true , { } , _ . dbconditions ) ,
2020-07-24 11:40:00 -04:00
default : "" ,
label : "Database Password: " ,
type : "text" ,
} ,
dbpass1 : {
2020-07-27 13:20:12 -04:00
conditions : $ . extend ( true , { } , _ . dbconditions ) ,
2020-07-24 11:40:00 -04:00
default : "" ,
label : "Repeat Password: " ,
type : "text" ,
} ,
} ;
this . form = new codiad . forms ( {
2020-07-27 13:20:12 -04:00
data : _ . d ,
2020-07-24 11:40:00 -04:00
container : $ ( "#installation" ) ,
submit _label : "Check Data Storage Method" ,
} ) ;
this . form . submit = async function ( ) {
2020-07-16 00:18:27 -04:00
2020-07-24 11:40:00 -04:00
let _this = this ;
let invalid _values ;
2020-07-16 00:18:27 -04:00
2020-07-24 11:40:00 -04:00
if ( _this . saving ) {
return ;
}
2020-07-16 00:18:27 -04:00
2020-07-24 11:40:00 -04:00
_this . saving = true ;
let data = await _this . m . get _values ( ) ;
let submit = _this . v . controls . find ( ` [type="submit"] ` ) ;
2020-07-16 00:18:27 -04:00
2020-08-19 22:14:12 -04:00
_ . data = data ;
2020-07-24 11:40:00 -04:00
submit . attr ( "disabled" , true ) ;
submit . text ( "Submitting ..." ) ;
2020-07-16 00:18:27 -04:00
2020-07-24 11:40:00 -04:00
let response = await codiad . common . ajax ( "./index.php" , "POST" , data ) ;
console . log ( response ) ;
let r = JSON . parse ( response ) ;
if ( r . status == "error" ) {
2020-08-19 22:14:12 -04:00
console . log ( "Error message" , r . message ) ;
let duplicate = false ;
let message = "" ;
if ( r . tables ) {
let total _tables = r . tables . length ;
for ( let i = 0 ; i < total _tables ; i ++ ) {
if ( r . tables [ i ] . error _type === "duplicate" ) {
duplicate = true ;
break ;
}
}
let bypass = window . confirm ( "It seems like one or more the tables you are attempting to create already exist. Are you absolutely sure you would like to overwrite the current tables with the default ones? This will wipe all information in the tables!" ) ;
if ( bypass === true ) {
let bypass2 = window . confirm ( "Are you absolutely sure? This action WILL delete all data from all tables. Files in the workspace directory WILL NOT be deleted by this action." ) ;
if ( bypass2 === true ) {
data . override = "true" ;
let response = await codiad . common . ajax ( "./index.php" , "POST" , data ) ;
console . log ( "User is overriding." ) ;
console . log ( response ) ;
_ . user _setup ( ) ;
}
}
} else {
codiad . message . error ( r . message ) ;
$ ( "#data_status" ) . html ( "<br><br>Data Status:<br>" + r . value ) ;
submit . text ( _this . submit _label ) ;
submit . attr ( "disabled" , false ) ;
_this . saving = false ;
}
2020-07-27 13:20:12 -04:00
} else {
_ . user _setup ( ) ;
2020-07-24 11:40:00 -04:00
}
submit . text ( _this . submit _label ) ;
submit . attr ( "disabled" , false ) ;
_this . saving = false ;
}
2020-07-27 13:20:12 -04:00
} ,
2020-08-19 22:14:12 -04:00
2020-07-27 13:20:12 -04:00
user _setup : function ( ) {
2020-08-19 22:14:12 -04:00
let _ = codiad . install ;
2020-07-27 13:20:12 -04:00
let _this = this ;
this . d = {
username : {
default : "" ,
label : "Username: " ,
type : "text" ,
} ,
password : {
default : "" ,
label : "Password: " ,
type : "text" ,
} ,
2020-08-19 22:14:12 -04:00
password1 : {
2020-07-27 13:20:12 -04:00
default : "" ,
label : "Repeat Password: " ,
type : "text" ,
} ,
} ;
this . form = new codiad . forms ( {
data : _this . d ,
container : $ ( "#installation" ) ,
submit _label : "Create User" ,
} ) ;
this . form . submit = async function ( ) {
let _this = this ;
let invalid _values ;
if ( _this . saving ) {
return ;
}
_this . saving = true ;
let data = await _this . m . get _values ( ) ;
let submit = _this . v . controls . find ( ` [type="submit"] ` ) ;
submit . attr ( "disabled" , true ) ;
submit . text ( "Submitting ..." ) ;
2020-08-19 22:14:12 -04:00
data . storage = _ . data . storage ;
if ( _ . data . dbhost ) {
data . dbhost = _ . data . dbhost ;
data . dbname = _ . data . dbname ;
data . dbuser = _ . data . dbuser ;
data . dbpass = _ . data . dbpass ;
}
2020-07-27 13:20:12 -04:00
let response = await codiad . common . ajax ( "./index.php" , "POST" , data ) ;
console . log ( response ) ;
let r = JSON . parse ( response ) ;
if ( r . status == "error" ) {
codiad . message . error ( r . message ) ;
2020-08-19 22:14:12 -04:00
$ ( "#data_status" ) . html ( "<br><br>User Status:<br>" + r . value ) ;
} else {
$ ( "#data_status" ) . html ( "<br><br>User Status:<br>Testing User data" ) ;
window . location . href = "./../" ;
2020-07-27 13:20:12 -04:00
}
submit . text ( _this . submit _label ) ;
submit . attr ( "disabled" , false ) ;
_this . saving = false ;
}
} ,
2020-07-24 11:40:00 -04:00
} ;
2020-07-16 00:18:27 -04:00
} ) ( this , jQuery ) ;