`+App.getName()+`
`;
setEvents(){
super.setEvents();
$( this.node ).find( '.link-logout' ).click( this.handleLogoutNavigation(this) );
$( this.node ).find( '.link-my-account' ).click( this.handleMyAccountNavigation(this) );
}
// Navigation Management
handleLogoutNavigation( inst ){
return (event) => {
inst.logout();
};
}
handleMyAccountNavigation( inst ){
return (event) => {
let route = '';
let me = Context.getMe();
if( me ){
let model = Auth.getModel();
route = model.getRoute('update');
Viewport.navigate( route+'/myaccount', {'object':me} );
}
};
}
logout(){
Auth.logout();
}
}class SidebarComponent extends Component{
tpl = `
`;
afterRender(){
super.afterRender();
this.refresh();
}
refresh(){
$( this.node ).find('ul').html('');
let routes = Viewport.routes;
if( routes ){
let links = [];
for( let offset in routes ){
let route = routes[offset];
if( route.sidebar && route.class ){
let isGranted = !route.acl || Auth.isGranted( route.acl );
if( isGranted ){
let instance = eval( 'new '+route.class+'()' );
if( instance && Tools.isFunction(instance.createLink) ){
let link = instance.createLink();
let position = parseInt(route.sidebar.position) ? parseInt(route.sidebar.position) : 0;
let group = '#sidebar-group' + (route.sidebar.group ? '-'+route.sidebar.group : '');
if( !links[ group ] ){
links[ group ] = [];
}
if( !links[ group ][ position ] ){
links[ group ][ position ] = {'link':link, 'group':group};
} else {
links[ group ].splice( position, 0, {'link':link, 'group':group} );
}
}
}
}
}
for( let group in links ){
let groupLinks = links[ group ];
for( let link of groupLinks ){
if( link ){
$( this.node ).find(group).removeClass('hidden');
$( this.node ).find(group+' ul').append( $('
',{'class':'mb-2'}).append(link.link) );
}
}
}
}
}
}class ChangePasswordFormComponent extends FormComponent{
tpl = `
`+Lang.t('Back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
beforeRender(){
this.parameters.model = Auth.getModel();
}
afterRender(){
super.afterRender();
let email = this.getParameter( 'email' );
if( email){
$( this.node ).find( '[name="email"]' ).val( email );
}
this.sendOTP();
}
setEvents(){
super.setEvents();
$( this.node ).find( '.input-toggle-visibility' ).click( this.handleTogglePasswordVisibility(this) );
$( this.node ).find( '.link-login' ).click( this.handleLoginNavigation(this) );
$( this.node ).find( '.link-resend' ).click( this.handleResendOTP(this) );
}
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' );
$( this.node ).find( '[name="password"], [name="password-confirm"]' ).removeClass( 'border-red-700' );
let password = $( this.node ).find( '[name="password"]' ).val();
let confirm = $( this.node ).find( '[name="password-confirm"]' ).val();
if( password && password!='' ){
if( password.length>5 ){
if( password == confirm ){
super.submit();
} else {
this.submitError( {'error':'password-mismatch'} );
}
} else {
this.submitError( {'error':'password-invalid-format'} );
}
} else {
this.submitError( {'error':'password-missing'} );
}
}
submitData( formData, onSuccess, onError ){
let model = this.getParameter('model');
if( model ){
model.renewPassword( formData, onSuccess, onError );
}
}
// Logic Management
submitSuccess( response ){
if( response.success ){
Toaster.render( 'check', Lang.t('Password updated'), 'success' );
Context.setProfile( Auth.getProfile() );
Context.setMe( response.result );
Context.setToken( response.token );
Auth.setToken( response.token, Context.getProfile() );
} else {
this.lostPasswordError( response );
}
}
submitError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
$( this.node ).find( '[name="email"]' ).addClass( 'border-red-700' );
break;
case 'otp-code-invalid':
$( this.node ).find( '[name="otp"]' ).val('').focus();
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
handleResendOTP( inst ){
return (event) => {
inst.sendOTP();
};
}
sendOTP(){
let email = $( this.node ).find( '[name="email"]' ).val();
if( email ){
let send_route = this.getParameter( 'send' );
if( send_route ){
let type = Auth.getProfile();
send_route = '/'+type+send_route;
WebService.call( send_route, {'email':email}, 'POST', false, this.handleSendOTPSuccess( this ), this.handleSendOTPError( this ) );
}
} else {
this.otpError( {'error':'security-error'} );
}
}
handleSendOTPSuccess( inst ){
return (response) => {
if( response.success ){
Toaster.render( 'check', Lang.t('Security code sent'), 'success' );
} else {
inst.sendOTPError( response );
}
}
}
handleSendOTPError( inst ){
return (response) => {
inst.sendOTPError( response );
}
}
sendOTPError( response ){
this.loginError( {'error':'security-error'} );
}
// Navigation Management
handleLoginNavigation( inst ){
return (event) => {
let parameters = Object.assign( this.parameters, {"route":"/login"} );
Viewport.navigate( '/login', parameters );
};
}
// UI Management
handleTogglePasswordVisibility( inst ){
return ( event ) => {
inst.togglePasswordVisibility();
};
}
togglePasswordVisibility(){
let isVisible = this.isPasswordVisible();
if( isVisible ){
this.unsetPasswordVisible();
} else {
this.setPasswordVisible();
}
}
isPasswordVisible(){
return $( this.node ).find( '[name="password"], [name="password-confirm"]' ).attr( 'type' ) == 'text';
}
setPasswordVisible(){
$( this.node ).find( '[name="password"], [name="password-confirm"]' ).attr( 'type', 'text' );
$( this.node ).find('.input-toggle-visibility .fa').removeClass( 'fa-eye-slash text-gray-500' ).addClass( 'fa-eye text-gray-600' );
}
unsetPasswordVisible(){
$( this.node ).find( '[name="password"], [name="password-confirm"]' ).attr( 'type', 'password' );
$( this.node ).find('.input-toggle-visibility .fa').removeClass( 'fa-eye text-gray-600' ).addClass( 'fa-eye-slash text-gray-500' );
}
}class LoginFormComponent extends FormComponent{
tpl = `
`+Lang.t('Not already member?')+`
`+Lang.t('Join us now.')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
beforeRender(){
this.parameters.model = Auth.getModel();
}
setEvents(){
super.setEvents();
$( this.node ).find( '.input-toggle-visibility' ).click( this.handleTogglePasswordVisibility(this) );
$( this.node ).find( '.link-forgot-password' ).click( this.handleForgotPasswordNavigation(this) );
$( this.node ).find( '.link-register' ).click( this.handleRegisterNavigation(this) );
}
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' );
$( this.node ).find( '[name="password"]' ).removeClass( 'border-red-700' );
super.submit();
}
submitData( formData, onSuccess, onError ){
let model = this.getParameter('model');
if( model ){
model.login( formData, onSuccess, onError );
}
}
// Logic Management
submitSuccess( response ){
if( response.success ){
let type = Auth.getProfile();
Context.setProfile( type );
Context.setMe( response.result );
Context.setToken( response.token );
Auth.setToken( response.token, type );
} else {
this.submitError( response );
}
}
submitError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
$( this.node ).find( '[name="email"]' ).addClass( 'border-red-700' );
break;
case 'password-missing':
$( this.node ).find( '[name="password"]' ).addClass( 'border-red-700' );
break;
case 'user-invalid':
this.navigateToOTP();
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
navigateToOTP(){
let email = $( this.node ).find( '[name="email"]' ).val();
if( email ){
let parameters = Object.assign( this.parameters, {"route":"/otp/validate", "send":"/otp/send", "email":email} );
Viewport.navigate( '/otp', parameters );
}
}
// Navigation Management
handleForgotPasswordNavigation( inst ){
return (event) => {
let parameters = Object.assign( this.parameters, {"route":"/lost-password"} );
Viewport.navigate( '/lost-password', parameters );
};
}
handleRegisterNavigation( inst ){
return (event) => {
let parameters = Object.assign( this.parameters, {"route":"/register"} );
Viewport.navigate( '/register', parameters );
};
}
// UI Management
handleTogglePasswordVisibility( inst ){
return ( event ) => {
inst.togglePasswordVisibility();
};
}
togglePasswordVisibility(){
let isVisible = this.isPasswordVisible();
if( isVisible ){
this.unsetPasswordVisible();
} else {
this.setPasswordVisible();
}
}
isPasswordVisible(){
return $( this.node ).find( '[name="password"]' ).attr( 'type' ) == 'text';
}
setPasswordVisible(){
$( this.node ).find( '[name="password"]' ).attr( 'type', 'text' );
$( this.node ).find('.input-toggle-visibility .fa').removeClass( 'fa-eye-slash text-gray-500' ).addClass( 'fa-eye text-gray-600' );
}
unsetPasswordVisible(){
$( this.node ).find( '[name="password"]' ).attr( 'type', 'password' );
$( this.node ).find('.input-toggle-visibility .fa').removeClass( 'fa-eye text-gray-600' ).addClass( 'fa-eye-slash text-gray-500' );
}
}class LostPasswordFormComponent extends FormComponent{
tpl = `
`+Lang.t('Back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
beforeRender(){
this.parameters.model = Auth.getModel();
}
setEvents(){
super.setEvents();
$( this.node ).find( '.link-login' ).click( this.handleLoginNavigation(this) );
}
submit(){
$( this.node ).find( '.error-message' ).html();
let email = $( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' ).val();
if( email ){
let parameters = Object.assign( this.parameters, {"route":"/renew-password", "send":"/otp/send", "email":email} );
Viewport.navigate( '/change-password', parameters );
}
}
// Navigation Management
handleLoginNavigation( inst ){
return (event) => {
let parameters = Object.assign( this.parameters, {"route":"/login"} );
Viewport.navigate( '/login', parameters );
};
}
// UI Management
} class OTPFormComponent extends FormComponent{
parameters = {
'type': 'user',
'route': '/otp/validate',
'send': '/otp/send',
'email': false
};
tpl = `
`+Lang.t('Back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
afterRender(){
super.afterRender();
let email = this.getParameter( 'email' );
if( email){
$( this.node ).find( '[name="email"]' ).val( email );
}
this.sendOTP();
}
setRoutes(){
let type = Auth.getProfile();
let route = this.getParameter( 'route' );
let contextRoute = '/'+type+route;
$( this.node ).find( 'form' ).attr( 'action', contextRoute );
}
setEvents(){
super.setEvents();
$( this.node ).find('form')
.data( 'onSuccess', this.handleOTPSuccess( this ) )
.data( 'onError', this.handleOTPError( this ) );
$( this.node ).find( '.link-login' ).click( this.handleLoginNavigation(this) );
$( this.node ).find( '.link-resend' ).click( this.handleResendOTP(this) );
}
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="otp"]' ).removeClass( 'border-red-700' );
super.submit();
}
// Logic Management
handleOTPSuccess( inst ){
return (response) => {
inst.otpSuccess( response );
};
}
otpSuccess( response ){
if( response.success ){
Toaster.render( 'check', Lang.t('Your account is now validated'), 'success' );
Context.setProfile( Auth.getProfile() );
Context.setToken( response.token );
Context.setMe( response.result );
Auth.setToken( response.token, Context.getProfile() );
} else {
this.otpError( response );
}
}
handleOTPError( inst ){
return (response) => {
inst.otpError( response );
};
}
otpError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
let parameters = Object.assign( this.parameters, {"route":"/login"} );
Viewport.navigate( '/login', parameters );
break;
case 'otp-code-invalid':
$( this.node ).find( '[name="otp"]' ).val('').focus();
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
handleResendOTP( inst ){
return (event) => {
inst.sendOTP();
};
}
sendOTP(){
let email = $( this.node ).find( '[name="email"]' ).val();
if( email ){
let send_route = this.getParameter( 'send' );
if( send_route ){
let type = Auth.getProfile();
send_route = '/'+type+send_route;
WebService.call( send_route, {'email':email}, 'POST', false, this.handleSendOTPSuccess( this ), this.handleSendOTPError( this ) );
}
} else {
this.otpError( {'error':'security-error'} );
}
}
handleSendOTPSuccess( inst ){
return (response) => {
if( response.success ){
Toaster.render( 'check', Lang.t('Security code sent'), 'success' );
} else {
inst.sendOTPError( response );
}
}
}
handleSendOTPError( inst ){
return (response) => {
inst.sendOTPError( response );
}
}
sendOTPError( response ){
this.otpError( {'error':'security-error'} );
}
// Navigation Management
handleLoginNavigation( inst ){
return (event) => {
let parameters = Object.assign( this.parameters, {"route":"/login"} );
Viewport.navigate( '/login', parameters );
};
}
// UI Management
}class RegisterFormComponent extends FormComponent{
tpl = `
`+Lang.t('Already have an account?')+`
`+Lang.t('sign in.')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
beforeRender(){
this.parameters.model = Auth.getModel();
}
setEvents(){
super.setEvents();
$( this.node ).find( '.input-toggle-visibility' ).click( this.handleTogglePasswordVisibility(this) );
$( this.node ).find( '.link-login' ).click( this.handleLoginNavigation(this) );
}
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' );
$( this.node ).find( '[name="password"], [name="password-confirm"]' ).removeClass( 'border-red-700' );
let password = $( this.node ).find( '[name="password"]' ).val();
let confirm = $( this.node ).find( '[name="password-confirm"]' ).val();
if( password && password!='' ){
if( password.length>5 ){
if( password == confirm ){
super.submit();
} else {
this.submitError( {'error':'password-mismatch'} );
}
} else {
this.submitError( {'error':'password-invalid-format'} );
}
} else {
this.submitError( {'error':'password-missing'} );
}
}
submitData( formData, onSuccess, onError ){
let model = this.getParameter('model');
if( model ){
model.register( formData, onSuccess, onError );
}
}
// Logic Management
submitSuccess( response ){
if( response.success ){
let email = $( this.node ).find( '[name="email"]' ).val();
if( email ){
let parameters = Object.assign( this.parameters, {"route":"/otp/validate", "send":"/otp/send", "email":email} );
Viewport.navigate( '/otp', parameters );
}
} else {
this.registerError( response );
}
}
submitError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
$( this.node ).find( '[name="email"]' ).addClass( 'border-red-700' );
break;
case 'password-invalid-format':
$( this.node ).find( '[name="password"]' ).addClass( 'border-red-700' );
break;
case 'password-mismatch':
$( this.node ).find( '[name="password"], [name="password-confirm"]' ).addClass( 'border-red-700' );
break;
case 'password-missing':
$( this.node ).find( '[name="password"]' ).addClass( 'border-red-700' );
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
// Navigation Management
handleLoginNavigation( inst ){
return (event) => {
let parameters = Object.assign( this.parameters, {"route":"/login"} );
Viewport.navigate( '/login', parameters );
};
}
// UI Management
handleTogglePasswordVisibility( inst ){
return ( event ) => {
inst.togglePasswordVisibility();
};
}
togglePasswordVisibility(){
let isVisible = this.isPasswordVisible();
if( isVisible ){
this.unsetPasswordVisible();
} else {
this.setPasswordVisible();
}
}
isPasswordVisible(){
return $( this.node ).find( '[name="password"], [name="password-confirm"]' ).attr( 'type' ) == 'text';
}
setPasswordVisible(){
$( this.node ).find( '[name="password"], [name="password-confirm"]' ).attr( 'type', 'text' );
$( this.node ).find('.input-toggle-visibility .fa').removeClass( 'fa-eye-slash text-gray-500' ).addClass( 'fa-eye text-gray-600' );
}
unsetPasswordVisible(){
$( this.node ).find( '[name="password"], [name="password-confirm"]' ).attr( 'type', 'password' );
$( this.node ).find('.input-toggle-visibility .fa').removeClass( 'fa-eye text-gray-600' ).addClass( 'fa-eye-slash text-gray-500' );
}
}class ChannelModel extends ObjectModel{
static model = ObjectModel.models[ this.name ] = this;
static definition = {
'name': {'label':Lang.t('Name'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':true },
'endpoint': {'label':Lang.t('Endpoint url'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':true },
'key': {'label':Lang.t('Key'), 'type':'string', 'minlength':8, 'maxlength':75, 'required':true },
'active': {'label':Lang.t('Active'), 'type':'bool', 'required':true },
'date_add': {'label':Lang.t('Created at'), 'type':'datetime' },
'date_upd': {'label':Lang.t('Updated at'), 'type':'datetime' },
};
static routes = {
'add': {'route':'/channel', 'endpoint':'/channel'},
'update': {'route':'/channel', 'endpoint':'/channel/{id}'},
'list': {'route':'/channels', 'endpoint':'/channels'},
'delete': {'route':'/channel', 'endpoint':'/channel/{id}'}
};
}class ProductModel extends ObjectModel{
static model = ObjectModel.models[ this.name ] = this;
static definition = {
'reference': {'label':Lang.t('Reference'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':true },
'name': {'label':Lang.t('Name'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':false },
'id_file_cover': {'label':Lang.t('Cover image'), 'type':'int'},
'active': {'label':Lang.t('Active'), 'type':'bool', 'required':true },
'date_add': {'label':Lang.t('Created at'), 'type':'datetime' },
'date_upd': {'label':Lang.t('Updated at'), 'type':'datetime' },
};
static routes = {
'add': {'route':'/product', 'endpoint':'/product'},
'update': {'route':'/product', 'endpoint':'/product/{id}'},
'list': {'route':'/products', 'endpoint':'/products'},
'delete': {'route':'/product', 'endpoint':'/product/{id}'}
};
}class StockModel extends ObjectModel{
static model = ObjectModel.models[ this.name ] = this;
static definition = {
'reference': {'label':Lang.t('Reference'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':true },
'quantity': {'label':Lang.t('Quantity'), 'type':'int', 'required':true },
'type': {'label':Lang.t('Type'), 'type':'string', 'required':true },
'date_available': {'label':Lang.t('Type'), 'type':'string', 'required':true },
'date_add': {'label':Lang.t('Created at'), 'type':'datetime' },
};
static routes = {
'add': {'route':'/stock', 'endpoint':'/stock'},
'update': {'route':'/stock', 'endpoint':'/stock/{id}'},
'list': {'route':'/stocks', 'endpoint':'/stocks'},
'delete': {'route':'/stock', 'endpoint':'/stock/{id}'}
};
}class WarehouseModel extends ObjectModel{
static model = ObjectModel.models[ this.name ] = this;
static definition = {
'name': {'label':Lang.t('Name'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':true },
'active': {'label':Lang.t('Active'), 'type':'bool', 'required':true },
'date_add': {'label':Lang.t('Created at'), 'type':'datetime' },
'date_upd': {'label':Lang.t('Updated at'), 'type':'datetime' },
};
static routes = {
'add': {'route':'/warehouse', 'endpoint':'/warehouse'},
'update': {'route':'/warehouse', 'endpoint':'/warehouse/{id}'},
'list': {'route':'/warehouses', 'endpoint':'/warehouses'},
'delete': {'route':'/warehouse', 'endpoint':'/warehouse/{id}'}
};
}class AdminAdminFormComponent extends FormComponent{
parameters = {
'model': AdminModel
};
tpl = `
`+Lang.t('Go back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' );
super.submit();
}
// Logic Management
submitSuccess( response ){
if( response.success ){
Context.setMe( response.result );
Toaster.render( 'check', Lang.t('Informations saved'), 'success' );
} else {
this.saveError( response );
}
}
submitError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
$( this.node ).find( '[name="email"]' ).addClass( 'border-red-700' );
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
}class AdminChannelFormComponent extends FormComponent{
parameters = {
'model': ChannelModel
};
tpl = `
`+Lang.t('Go back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
}class AdminMyAccountFormComponent extends FormComponent{
parameters = {
'model': AdminModel
};
tpl = `
`;
styles = `
.error-message:empty{ display:none; }
`;
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' );
super.submit();
}
// Logic Management
submitSuccess( response ){
if( response.success ){
Context.setMe( response.result );
Toaster.render( 'check', Lang.t('Informations saved'), 'success' );
} else {
this.saveError( response );
}
}
submitError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
$( this.node ).find( '[name="email"]' ).addClass( 'border-red-700' );
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
}class AdminProductFormComponent extends FormComponent{
parameters = {
'model': ProductModel
};
tpl = `
`+Lang.t('Go back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
}class AdminStockFormComponent extends FormComponent{
parameters = {
'model': StockModel
};
tpl = `
`+Lang.t('Go back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
}class AdminUserFormComponent extends FormComponent{
parameters = {
'model': UserModel
};
tpl = `
`+Lang.t('Go back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' );
super.submit();
}
// Logic Management
submitSuccess( response ){
if( response.success ){
Context.setMe( response.result );
Toaster.render( 'check', Lang.t('Informations saved'), 'success' );
} else {
this.saveError( response );
}
}
submitError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
$( this.node ).find( '[name="email"]' ).addClass( 'border-red-700' );
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
}class AdminWarehouseFormComponent extends FormComponent{
parameters = {
'model': WarehouseModel
};
tpl = `
`+Lang.t('Go back')+`
`;
styles = `
.error-message:empty{ display:none; }
`;
}class UserMyAccountFormComponent extends FormComponent{
parameters = {
'model': UserModel
};
tpl = `
`;
styles = `
.error-message:empty{ display:none; }
`;
submit(){
$( this.node ).find( '.error-message' ).html();
$( this.node ).find( '[name="email"]' ).removeClass( 'border-red-700' );
super.submit();
}
// Logic Management
submitSuccess( response ){
if( response.success ){
Context.setMe( response.result );
Toaster.render( 'check', Lang.t('Informations saved'), 'success' );
} else {
this.submitError( response );
}
}
submitError( response ){
let errorMessage = Lang.t( response.error );
switch( response.error ){
case 'email-missing':
$( this.node ).find( '[name="email"]' ).addClass( 'border-red-700' );
break;
}
if( errorMessage && errorMessage!='' ){
$( this.node ).find( '.error-message' ).html( '
' + errorMessage );
}
}
}class ListHelper extends Component{
data = false;
tpl = `
`;
static render( target, parameters ){
let inst = super.render( target, parameters );
let viewInstance = inst.getParameter( 'instance' );
viewInstance.parameters.model = inst.getParameter( 'model' );
let title = inst.getParameter( 'title' );
$( inst.node ).find( '.list-title' ).html( title );
if( $.isArray(parameters.columns) ){
let row = $('
|
');
$( parameters.columns ).each(function(i,column){
let col = $('
| ',{'class':'px-3 py-1.5 text-medium'}).html( column.label );
$( row ).append( col );
});
$( inst.node ).find( 'thead' ).append( row );
}
return inst;
}
setEvents(){
let viewInstance = this.getParameter( 'instance' );
if( viewInstance ){
$('#actions-new').click( this.handleNewAction( viewInstance ) );
}
}
handleNewAction( inst ){
return (event) => {
inst.newAction();
};
}
loadData( params ){
let filters = this.getParameter('filters');
if( filters && Tools.isObject(filters) ){
if( params && Tools.isObject(params) ){
params = Object.assign( params, filters );
} else {
params = filters;
}
}
let onSuccess = this.handleSuccess( this );
let onError = this.handleError( this );
let model = this.getParameter('model');
if( model ){
model.list( params, onSuccess, onError );
}
}
handleSuccess( inst ){
return( response ) => {
if( response && response.success ){
inst.renderResponse( response );
} else {
inst.renderError( Lang.t('An error occurs') );
}
}
}
handleError( inst ){
return ( error ) => {
inst.renderError( error.message );
}
}
renderResponse( response ){
this.renderSearch( response.pagination );
this.renderList( response.result );
this.renderPagination( response.pagination );
}
renderList( channels ){
let parameters = this.parameters;
if( $.isArray(channels) ){
$( this.node ).find( 'tbody' ).html('');
for( let channel of channels ){
if( $.isArray(parameters.columns) ){
let row = $('
|
',{'class':'odd:bg-gray-100 even:bg-slate-100 border-b border-slate-200'});
for( let column of parameters.columns ){
let value = channel[ column.property ];
value = this.adaptValue( value, column, channel, parameters );
let col = $('
| ',{'class':'px-3 py-1.5'}).html( value );
if( column.type ){
$( col ).addClass( column.type );
if( column.type=='action' ){
$( col ).addClass( 'w-3' );
}
}
if( column.class && column.class ){
$( col ).addClass( column.class );
}
$( row ).append( col );
}
$( this.node ).find( 'tbody' ).append( row );
}
}
}
}
renderPagination( pagination ){
if( pagination ){
let target = $(this.node).find('.container-pagination');
$( target ).html('');
PaginationHelper.render( target, { 'list':this, 'pagination':pagination } );
}
}
renderSearch( pagination ){
if( pagination ){
let target = $(this.node).find('.container-search');
$( target ).html('');
let viewInstance = this.getParameter( 'instance' );
let model = viewInstance.getParameter( 'model' );
let routeName = viewInstance.getParameter( 'route' );
SearchHelper.render( target, { 'list':this, 'pagination':pagination, 'route':routeName, 'model':model } );
}
}
renderError( message ){
Toaster.render( 'times', message, 'error' );
}
adaptValue( value, column, object, parameters ){
let type = column.type ? column.type : 'text';
switch( type ){
case 'active':
let activeIcon = parseInt(value) ? 'check text-emerald-700' : 'times text-red-700';
value = $('
',{'class':'fa fa-'+activeIcon});
break;
case 'signedNumber':
let signedColor = parseInt(value)>0 ? 'text-emerald-700' : 'text-red-700';
value = $('
',{'class':signedColor}).html( value );
break;
case 'signedNumberUndefined':
let signedNumberUndefinedColor = value===false ? 'text-slate-700' : (parseInt(value)>0 ? 'text-emerald-700' : 'text-red-700');
value = value===false ? '-' : value;
value = $('
',{'class':signedNumberUndefinedColor}).html( value );
break;
case 'availability':
let availabilityColor = value===false ? 'text-red-700' : (value===true ? 'text-emerald-700' : 'text-slate-700');
value = value===false ? Lang.t('No') : (value===true ? Lang.t('Yes') : value);
value = $('
',{'class':availabilityColor}).html( value );
break;
case 'image':
if( parseInt(value)>0 ){
let relatedObjectProp = column.property.replace('id_file_', '');
if( Tools.exists(object.files) && Tools.exists(object.files[ relatedObjectProp ]) && Tools.exists(object.files[ relatedObjectProp ].url) ){
value = $('
![]()
',{'src':object.files[ relatedObjectProp ].url, 'class':'thumbnail w-[60px] rounded-xs border border-slate-200'});
} else {
value = '';
}
} else {
value = '';
}
break;
case 'action':
value = this.adaptActions( value, column, object, parameters );
break;
}
return value;
}
actions = {
'editAction': {'label':Lang.t('Edit'), 'icon':'edit'},
'deleteAction': {'label':Lang.t('Delete'), 'icon':'trash'}
}
adaptActions( value, column, object, parameters ){
let button = false;
if( this.actions[ column.method ] ){
let buttonIcon = typeof(this.actions[ column.method ].icon)!='undefined' ? this.actions[ column.method ].icon : false;
if( buttonIcon ){
button = $('
',{'class':'cursor-pointer'})
.html( $('
',{'class':'fa fa-'+buttonIcon}) );
let func = column.onClick;
if( typeof(func)=='function' ){
$( button ).click( func );
} else {
let inst = parameters.instance ? parameters.instance : false;
if( inst && typeof(inst.handleAction)=='function' ){
func = inst.handleAction( inst, column.method, object );
$( button ).click( func );
}
}
value = button;
}
}
return button;
}
}class PaginationHelper extends Component{
data = false;
tpl = `
`;
static render( target, parameters ){
let inst = super.render( target, parameters );
let pagination = parameters.pagination;
let listHelper = parameters.list;
if( listHelper && pagination && pagination.links ){
if( pagination.pages.nb_pages>0 ){
$( inst.node ).find('.current-page').html( pagination.pages.page );
$( inst.node ).find('.nb-pages').html( pagination.pages.nb_pages );
if( pagination.pages.page>1 ){
if( pagination.links.first ){
$( inst.node )
.find('.first')
.click( inst.handleNavigate( listHelper, pagination.links.first ) )
.removeAttr('disabled');
}
if( pagination.links.prev ){
$( inst.node )
.find('.prev')
.click( inst.handleNavigate( listHelper, pagination.links.prev ) )
.removeAttr('disabled');
}
}
if( pagination.pages.page
{
listHelper.loadData( url );
};
}
}class SearchHelper extends FormComponent{
parameters = {
'route': '/channels'
};
tpl = `
`;
setRoutes(){
let route = this.getParameter( 'route' );
let pagination = this.getParameter( 'pagination' );
if( pagination && pagination.query && pagination.query.term ){
$('#search [name="q"]').val( pagination.query.term );
$('#search-clear')
.click( this.handleReset(this) )
.removeClass('hidden');
}
}
submitData( formData, onSuccess, onError ){
let listHelper = this.getParameter('list');
let filters = listHelper.getParameter('filters');
if( filters && Tools.isObject(filters) ){
if( !formData ){
formData = new FormData();
}
for( let key in filters ){
formData.delete( filters[key] );
formData.set( key, filters[key] );
}
}
let model = this.getParameter('model');
if( model ){
model.list( formData, onSuccess, onError );
}
}
// Logic Management
handleReset( inst ){
return ( event ) => {
inst.reset();
}
}
reset(){
let listHelper = this.getParameter('list');
if( listHelper ){
let pagination = this.getParameter('pagination');
listHelper.loadData( pagination.links.base );
}
}
submitSuccess( response ){
if( response.success ){
let listHelper = this.getParameter('list');
if( listHelper ){
listHelper.renderResponse( response );
}
} else {
this.error( response );
}
}
handleError( inst ){
return (response) => {
inst.error( response );
};
}
error( response ){
let listHelper = this.getParameter('list');
if( listHelper ){
listHelper.renderResponse( {'list':[]} );
}
}
}class AuthObjectModel extends ObjectModel{
static profiles = {};
static login( params, onSuccess, onError ){
let endpoint = this.getEndpoint( 'login' );
if( params && endpoint ){
WebService.call( endpoint, params, 'POST', false, onSuccess, onError );
}
}
static renewPassword( params, onSuccess, onError ){
let endpoint = this.getEndpoint( 'renew-password' );
if( params && endpoint ){
WebService.call( endpoint, params, 'POST', false, onSuccess, onError );
}
}
static register( params, onSuccess, onError ){
let endpoint = this.getEndpoint( 'register' );
if( params && endpoint ){
WebService.call( endpoint, params, 'POST', false, onSuccess, onError );
}
}
}class FormView extends View{
menu = true;
sidebar = true;
tpl = `
`;
static getFormComponent(){
return false;
}
afterRender(){
super.afterRender();
let container = $( this.node ).find('.container-form');
let component = this.constructor.getFormComponent();
if( component ){
component.render( container, this.parameters );
}
}
}class ListView extends View{
menu = true;
sidebar = true;
tpl = `
`;
afterRender(){
super.afterRender();
let target = $(this.node).find('.container-list');
let parameters = this.constructor.listParameters;
parameters.instance = this;
parameters.model = this.constructor.getModel();
parameters = this.adaptParameters( parameters );
let list = ListHelper.render( target, parameters );
for( let column of parameters.columns ){
if( column.type=='action' && $.inArray(column.method, ['editAction', 'newAction', 'viewAction', 'deleteAction'])==-1 ){
let funcName = column.method;
if( Tools.isFunction( this[column.method] ) ){
list.actions[ column.method ] = { 'label':column.title, 'icon':column.icon };
}
}
}
list = this.adaptList( list );
list.loadData();
}
static getModel(){
return false;
}
adaptParameters( parameters ){
return parameters;
}
adaptList( list ){
return list;
}
createLink(){
let link = false;
let parameters = this.constructor.linkParameters;
if( parameters.label ){
let icon = parameters.icon ? parameters.icon : false;
link = this.mkLink( parameters.icon, parameters.label );
}
return link;
}
handleAction( inst, method, object ){
return (event) => {
let func = method;
if( typeof(inst[func])=='function' ){
inst[func]( object );
}
};
}
newAction(){
let routeName = false;
let model = this.getParameter('model');
if( model ){
let route = model.getRoute('add');
if( route ){
routeName = route;
}
}
if( !routeName ){
let className = this.constructor.name;
let formClassName = className.replace( 'ListView', 'FormView' );
let instance = eval( 'new '+formClassName+'()' );
if( instance && typeof(instance.route)!='undefined' ){
routeName = instance.route;
}
}
this.navigate( routeName );
}
editAction( object ){
let routeName = false;
let model = this.getParameter('model');
if( model ){
let route = model.getRoute('update');
if( route ){
routeName = route;
}
}
if( !routeName ){
let className = this.constructor.name;
let formClassName = className.replace( 'ListView', 'FormView' );
let instance = eval( 'new '+formClassName+'()' );
if( instance && typeof(instance.route)!='undefined' ){
routeName = instance.route;
}
}
this.navigate( routeName, object );
}
deleteAction( object ){
let label = Lang.t('Are you sure you want to delete this value?');
let options = {
'icon': 'trash',
'title': Lang.t('Delete'),
'confirm':{
'func': this.handleConfirmDeleteAction( this, object )
}
};
Confirm.render( label, options );
}
handleConfirmDeleteAction( inst, object ){
return ( event ) => {
inst.delete( object );
}
}
delete( object ){
if( object && object.id ){
let model = this.getParameter('model');
if( model ){
let onSuccess = this.handleDeleteSuccess( this );
let onError = this.handleDeleteError( this );
model.delete( object.id, onSuccess, onError );
}
}
}
handleDeleteSuccess( inst ){
return (response) => {
inst.deleteSuccess();
Toaster.render( 'check', Lang.t('Delete success'), 'success' );
};
}
deleteSuccess(){
let routeName = false;
let model = this.getParameter('model');
if( model ){
let route = model.getRoute('list');
if( route ){
routeName = route;
}
}
if( !routeName ){
let className = this.constructor.name;
let instance = eval( 'new '+className+'()' );
if( instance && typeof(instance.route)!='undefined' ){
routeName = instance.route;
}
}
this.navigate( routeName );
}
handleDeleteError( inst ){
return (error) => {
inst.deleteError();
Toaster.render( 'times', Lang.t('An error occurs'), 'error' );
};
}
deleteError(){
let routeName = false;
let routes = this.getParameter('routes');
if( routes && routes.list && routes.list.route ){
routeName = routes.list.route;
}
this.navigate( routeName );
}
}class AdminModel extends AuthObjectModel{
static model = ObjectModel.models[ this.name ] = this;
static profile = AuthObjectModel.profiles['admin'] = this;
static definition = {
'email': {'label':Lang.t('Email'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':true },
'password': {'label':Lang.t('Password'), 'type':'password', 'minlength':3, 'maxlength':75, 'required':true },
'firstname': {'label':Lang.t('First name'), 'type':'string', 'minlength':3, 'maxlength':75 },
'lastname': {'label':Lang.t('Last name'), 'type':'string', 'minlength':3, 'maxlength':75 },
'phone': {'label':Lang.t('Phone number'), 'type':'string', 'minlength':10, 'maxlength':15 },
'active': {'label':Lang.t('Active'), 'type':'bool' },
'date_add': {'label':Lang.t('Created at'), 'type':'datetime' },
'date_upd': {'label':Lang.t('Updated at'), 'type':'datetime' },
};
static routes = {
'login': {'route':'/admin/login', 'endpoint':'/admin/login'},
'renew-password': {'route':'/admin/renew-password', 'endpoint':'/admin/renew-password'},
'register': {'route':'/admin/register', 'endpoint':'/admin/register'},
'add': {'route':'/admin', 'endpoint':'/admin'},
'update': {'route':'/admin', 'endpoint':'/admin/{id}'},
'list': {'route':'/admins', 'endpoint':'/admins'},
'delete': {'route':'/admin', 'endpoint':'/admin/{id}'}
};
}class UserModel extends AuthObjectModel{
static model = ObjectModel.models[ this.name ] = this;
static profile = AuthObjectModel.profiles['user'] = this;
static definition = {
'email': {'label':Lang.t('Email'), 'type':'string', 'minlength':3, 'maxlength':75, 'required':true },
'password': {'label':Lang.t('Password'), 'type':'password', 'minlength':3, 'maxlength':75, 'required':true },
'firstname': {'label':Lang.t('First name'), 'type':'string', 'minlength':3, 'maxlength':75 },
'lastname': {'label':Lang.t('Last name'), 'type':'string', 'minlength':3, 'maxlength':75 },
'phone': {'label':Lang.t('Phone number'), 'type':'string', 'minlength':10, 'maxlength':15 },
'address': {'label':Lang.t('Address'), 'type':'string', 'minlength':3, 'maxlength':75 },
'postcode': {'label':Lang.t('Post code'), 'type':'string', 'minlength':3, 'maxlength':10 },
'city': {'label':Lang.t('City'), 'type':'string', 'minlength':3, 'maxlength':75 },
'country': {'label':Lang.t('Country'), 'type':'string', 'minlength':3, 'maxlength':75 },
'active': {'label':Lang.t('Active'), 'type':'bool' },
'date_add': {'label':Lang.t('Created at'), 'type':'datetime' },
'date_upd': {'label':Lang.t('Updated at'), 'type':'datetime' },
};
static routes = {
'login': {'route':'/user/login', 'endpoint':'/user/login'},
'renew-password': {'route':'/user/renew-password', 'endpoint':'/user/renew-password'},
'register': {'route':'/user/register', 'endpoint':'/user/register'},
'add': {'route':'/user', 'endpoint':'/user'},
'update': {'route':'/user', 'endpoint':'/user/{id}'},
'list': {'route':'/users', 'endpoint':'/users'},
'delete': {'route':'/user', 'endpoint':'/user/{id}'}
};
}class AdminAdminListView extends ListView{
static route = '/admin/admins';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin', 'sidebar':{'position':5, 'group':'users'} };
static getModel(){
return AdminModel;
}
static linkParameters = {
'icon': 'user-crown',
'label': Lang.t('Administrators')
};
static listParameters = {
'title': Lang.t('Administrators'),
'columns': [
{'label': Lang.t('First name'), 'property': 'firstname'},
{'label': Lang.t('Last name'), 'property': 'lastname'},
{'label': Lang.t('Email'), 'property': 'email'},
{'label': Lang.t('Phone'), 'property': 'phone'},
{'label': Lang.t('Active'), 'property': 'active', 'type': 'active'},
{'label': '', 'type': 'action', 'method': 'editAction'},
{'label': '', 'type': 'action', 'method': 'deleteAction'}
]
};
}class AdminUserListView extends ListView{
static route = '/admin/users';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin', 'sidebar':{'position':1, 'group':'users'} };
static getModel(){
return UserModel;
}
static linkParameters = {
'icon': 'user',
'label': Lang.t('Users')
};
static listParameters = {
'title': Lang.t('Users'),
'columns': [
{'label': Lang.t('First name'), 'property': 'firstname'},
{'label': Lang.t('Last name'), 'property': 'lastname'},
{'label': Lang.t('Email'), 'property': 'email'},
{'label': Lang.t('Phone'), 'property': 'phone'},
{'label': Lang.t('Active'), 'property': 'active', 'type': 'active'},
{'label': '', 'type': 'action', 'method': 'editAction'},
{'label': '', 'type': 'action', 'method': 'deleteAction'}
]
};
}class AdminAdminFormView extends FormView{
static route = '/admin/admin';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin' };
static getFormComponent(){
return AdminAdminFormComponent;
}
}class AdminMyAccountView extends FormView{
static route = '/admin/myaccount';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin' };
static getFormComponent(){
return AdminMyAccountFormComponent;
}
}class AdminUserFormView extends FormView{
static route = '/admin/user';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin' };
static getFormComponent(){
return AdminUserFormComponent;
}
}class UserMyAccountView extends FormView{
static route = '/user/myaccount';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'user' };
static getFormComponent(){
return UserMyAccountFormComponent;
}
}class AdminChannelListView extends ListView{
static route = '/admin/channels';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin', 'sidebar':{'position':1, 'group':'parameters'} };
static getModel(){
return ChannelModel;
}
static linkParameters = {
'icon': 'server',
'label': Lang.t('Channels')
};
static listParameters = {
'title': Lang.t('Channels'),
'columns': [
{'label': Lang.t('#'), 'property': 'id_channel'},
{'label': Lang.t('Name'), 'property': 'name', 'class': 'font-bold'},
{'label': Lang.t('Endpoint'), 'property': 'endpoint'},
{'label': Lang.t('Key'), 'property': 'key'},
{'label': Lang.t('Active'), 'property': 'active', 'type': 'active'},
{'label': '', 'type': 'action', 'method': 'editAction'},
{'label': '', 'type': 'action', 'method': 'deleteAction'}
]
};
}class AdminProductListView extends ListView{
static route = '/admin/products';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin', 'sidebar':{'position':1, 'group':'catalog'} };
static getModel(){
return ProductModel;
}
static linkParameters = {
'icon': 'boxes-stacked',
'label': Lang.t('Products')
};
static listParameters = {
'title': Lang.t('Products'),
'columns': [
{'label': '', 'property': 'id_file_cover', 'type': 'image', 'class': 'font-bold w-[60px]'},
{'label': Lang.t('Reference'), 'property': 'reference', 'class': 'font-bold'},
{'label': Lang.t('Name'), 'property': 'name'},
{'label': Lang.t('Stock'), 'property': 'quantity', 'type': 'signedNumberUndefined'},
{'label': Lang.t('Active'), 'property': 'active', 'type': 'active'},
{'label': '', 'type': 'action', 'method': 'viewStockListAction', 'title':Lang.t('View stocks'), 'icon':'list'},
{'label': '', 'type': 'action', 'method': 'editAction'},
{'label': '', 'type': 'action', 'method': 'deleteAction'}
]
};
viewStockListAction( object ){
let routeName = AdminStockListView.route;
this.navigate( routeName, object );
}
}class AdminStockListView extends ListView{
static route = '/admin/stocks';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin', 'sidebar':{'position':2, 'group':'catalog'} };
static getModel(){
return StockModel;
}
static linkParameters = {
'icon': 'list',
'label': Lang.t('Stocks')
};
static listParameters = {
'title': Lang.t('Stocks'),
'columns': [
{'label': Lang.t('Reference'), 'property': 'reference'},
{'label': Lang.t('Quantity'), 'property': 'quantity'},
{'label': Lang.t('Warehouse'), 'property': 'warehouse'},
{'label': Lang.t('Type'), 'property': 'type'},
{'label': Lang.t('Availability'), 'property': 'availability', 'type': 'availability'},
{'label': '', 'type': 'action', 'method': 'editAction'},
{'label': '', 'type': 'action', 'method': 'deleteAction'}
]
};
adaptParameters( parameters ){
let relatedObject = this.getParameter('object');
if( Tools.isObject(relatedObject) && relatedObject.reference ){
parameters.filters = { 'reference': relatedObject.reference };
parameters.title += ' : ' + relatedObject.reference;
}
return parameters;
}
}class AdminWarehouseListView extends ListView{
static route = '/admin/warehouses';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin', 'sidebar':{'position':2, 'group':'parameters'} };
static getModel(){
return WarehouseModel;
}
static linkParameters = {
'icon': 'warehouse',
'label': Lang.t('Warehouses')
};
static listParameters = {
'title': Lang.t('Warehouses'),
'columns': [
{'label': Lang.t('#'), 'property': 'id_warehouse'},
{'label': Lang.t('Name'), 'property': 'name', 'class': 'font-bold'},
{'label': Lang.t('Active'), 'property': 'active', 'type': 'active'},
{'label': '', 'type': 'action', 'method': 'editAction'},
{'label': '', 'type': 'action', 'method': 'deleteAction'}
]
};
}class AdminChannelFormView extends FormView{
static route = '/admin/channel';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin' };
static getFormComponent(){
return AdminChannelFormComponent;
}
}class AdminProductFormView extends FormView{
static route = '/admin/product';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin' };
static getFormComponent(){
return AdminProductFormComponent;
}
}class AdminStockFormView extends FormView{
static route = '/admin/stock';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin' };
static getFormComponent(){
return AdminStockFormComponent;
}
}class AdminWarehouseFormView extends FormView{
static route = '/admin/warehouse';
static routeConfig = Viewport.routes[this.route] = { 'class':this.name, 'acl':'admin' };
static getFormComponent(){
return AdminWarehouseFormComponent;
}
}class App{
static inst = false;
static parameters = false;
constructor(){
App.inst = this;
let element = document.querySelector('[data-profile]');
let profile = element.getAttribute('data-profile');
element = document.querySelector('[data-route]');
Auth.setProfile( profile );
EventDispatcher.on( 'auth_success', this.onAuthSuccess );
EventDispatcher.on( 'auth_error', this.onAuthError );
EventDispatcher.on( 'auth_logout', this.onAuthError );
}
init(){
WebService.call( '/app', false, 'GET', false, this.onInitSuccess, this.onInitError );
}
onInitSuccess( params ){
if( params ){
App.parameters = params.app;
EventDispatcher.trigger( 'ready', {'instance':App.inst} );
DynamicLoader.loadStyle( '/assets/css/fontawesome.min.css', console.log, console.error );
DynamicLoader.loadStyle( '/assets/css/select2.min.css', console.log, console.error );
DynamicLoader.loadStyle( '/assets/css/app.css', console.log, console.error );
DynamicLoader.loadScript( '/assets/js/jquery.min.js', App.inst.onDependenciesReady, console.error );
DynamicLoader.loadScript( '/assets/js/tailwindcss.js', console.log, console.error );
} else {
App.inst.onInitError( 'An error occurs while loading application config.' );
}
}
onInitError( params ){
console.error( params );
}
onAuthSuccess( params ){
if( Auth.checkACL() ){
App.inst.displayDashboard();
} else {
App.inst.displayLogin();
}
Viewport.components.sidebar.refresh();
}
onAuthError( params ){
App.inst.displayLogin();
}
onLogout( params ){
App.inst.displayLogin();
}
onDependenciesReady(){
DynamicLoader.loadScript( '/assets/js/select2.min.js', console.log, console.error );
Lang.setDictionary( 'en' );
Viewport.init();
Auth.loadProfiles();
}
displayDashboard(){
Viewport.navigate( '/dashboard' );
}
displayLogin(){
Viewport.navigate( '/login', {'route':'/login', 'otp':'email'}, true );
}
static getName(){
let name = '';
if( App.parameters && App.parameters.name ){
name = App.parameters.name;
}
return name;
}
static getBaseUri(){
let base_uri = '';
if( App.parameters && App.parameters.base_uri ){
base_uri = App.parameters.base_uri;
}
return base_uri;
}
static getHost(){
let host = '';
if( App.parameters && App.parameters.host ){
host = App.parameters.host;
}
return host;
}
}
const application = new App();
application.init();