protected function loadJs()
    {
        \Nails\Common\Controller\Base::setNailsJs();

        $oAsset = Factory::service('Asset');

        //  Module assets
        $oAsset->load('admin.min.js', 'nails/module-admin');
        $oAsset->load('nails.default.min.js', 'NAILS');
        $oAsset->load('nails.admin.js', 'NAILS');
        $oAsset->load('nails.forms.min.js', 'NAILS');
        $oAsset->load('nails.api.min.js', 'NAILS');

        //  Component assets
        foreach (Components::available() as $oComponent) {

            if (!empty($oComponent->data->{'nails/module-admin'}->autoload)) {

                $oAutoLoad = $oComponent->data->{'nails/module-admin'}->autoload;
                if (!empty($oAutoLoad->assets->js)) {
                    foreach ($oAutoLoad->assets->js as $mAsset) {

                        if (is_string($mAsset)) {
                            $sAsset    = $mAsset;
                            $sLocation = $oComponent->slug;
                        } else {
                            $sAsset    = !empty($mAsset[0]) ? $mAsset[0] : null;
                            $sLocation = !empty($mAsset[1]) ? $mAsset[1] : null;
                        }

                        $oAsset->load($sAsset, $sLocation, 'JS');
                    }
                }

                //  JS Inline
                if (!empty($oAutoLoad->assets->jsInline)) {
                    foreach ($oAutoLoad->assets->jsInline as $sAsset) {
                        $oAsset->inline($sAsset, 'JS');
                    }
                }
            }
        }

        //  Global JS
        $sAdminJsPath = defined('APP_ADMIN_JS_PATH') ? APP_ADMIN_JS_PATH : NAILS_APP_PATH . 'assets/build/js/admin.min.js';
        $sAdminJsUrl  = defined('APP_ADMIN_JS_URL') ? APP_ADMIN_JS_URL : 'admin.min.js';
        if (file_exists($sAdminJsPath)) {
            $oAsset->load($sAdminJsUrl);
        }

        //  Inline assets
        $sJs = 'var _nails,_nails_admin,_nails_api, _nails_forms;';

        $sJs .= 'if (typeof(NAILS_JS) === \'function\'){';
        $sJs .= '_nails = new NAILS_JS();';
        $sJs .= '}';

        $sJs .= 'if (typeof(NAILS_API) === \'function\'){';
        $sJs .= '_nails_api = new NAILS_API();';
        $sJs .= '}';

        $sJs .= 'if (typeof(NAILS_Admin) === \'function\'){';
        $sJs .= '_nails_admin = new NAILS_Admin();';
        $sJs .= '}';

        $sJs .= 'if (typeof(NAILS_Forms) === \'function\'){';
        $sJs .= '_nails_forms = new NAILS_Forms();';
        $sJs .= '}';

        $oAsset->inline($sJs, 'JS');
    }