Commit 0c0085af authored by Jonathon Duerig's avatar Jonathon Duerig

Better organization of Apt JS client-side code. Checkpoint.

parent e9050ff9
......@@ -32,5 +32,6 @@ RequiredPageArguments();
SPITHEADER();
echo "The URL you gave: <b>" . htmlentities( $_SERVER["REQUEST_URI"] ) . "</b>
is not available or is broken.";
echo "<script src='js/lib/require.js' data-main='js/main'></script>";
SPITFOOTER();
window.APT_OPTIONS = window.APT_OPTIONS || {};
window.APT_OPTIONS.config = function ()
{
require.config({
baseUrl: '.',
paths: {
'jquery': 'js/lib/jquery-2.0.3.min',
'bootstrap': 'bootstrap/js/bootstrap',
'formhelpers': 'formhelpers/js/bootstrap-formhelpers',
'dateformat': 'js/lib/date.format',
'd3': 'js/lib/d3.v3',
},
shim: {
'bootstrap': { deps: ['jquery'] },
'formhelpers': { deps: ['bootstrap']},
'dateformat': { exports: 'dateFormat' },
'd3': { exports: 'd3' }
},
});
}
window.APT_OPTIONS.initialize = function (sup)
{
if (window.APT_OPTIONS.isNewUser)
{
sup.ShowModal('#verify_modal');
}
$('#quickvm_login_modal_button').click(function (event) {
event.preventDefault();
sup.LoginByModal();
});
$('#logoutbutton').click(function (event) {
event.preventDefault();
sup.Logout();
});
$('body').show();
}
require.config({
baseUrl: '.',
paths: {
'jquery': 'js/lib/jquery-2.0.3.min',
'bootstrap': 'bootstrap/js/bootstrap',
'formhelpers': 'formhelpers/js/bootstrap-formhelpers',
'dateformat': 'js/lib/date.format',
'd3': 'js/lib/d3.v3',
},
shim: {
'bootstrap': { deps: ['jquery'] },
'formhelpers': { deps: ['bootstrap']},
'dateformat': { exports: 'dateFormat' },
'd3': { exports: 'd3' }
},
});
window.APT_OPTIONS.config();
require(['jquery', 'js/quickvm_sup',
// jQuery modules
......@@ -24,130 +9,7 @@ function ($, sup)
function initialize()
{
var pageType = 'donotsetthistoindex';
if (window.APT_OPTIONS)
{
console.log('APT_OPTIONS: ' + JSON.stringify(window.APT_OPTIONS));
if (window.APT_OPTIONS.isNewUser)
{
sup.ShowModal('#verify_modal');
}
if (window.APT_OPTIONS.pageType)
{
pageType = window.APT_OPTIONS.pageType;
}
initLoginButton();
}
else
{
console.log('APT_OPTIONS is undefined');
}
if (pageType === 'index')
{
initIndex();
}
else if (pageType === 'sshterm')
{
sup.StartSSH('sshpanel', window.APT_OPTIONS.authObject);
}
else if (pageType === 'status')
{
sup.InitQuickVM(window.APT_OPTIONS.uuid,
window.APT_OPTIONS.sliceExpires);
initStatusButtons();
}
else if (pageType == 'signup') {
$('button#reset-form').click(function (event) {
event.preventDefault();
sup.resetForm($('#quickvm_signup_form'));
});
if (window.APT_OPTIONS.ShowVerifyModal)
{
sup.ShowModal('#verify_modal');
}
}
else if (pageType == 'manage_profile') {
if (1) {
try {
$('#rspecfile').change(function() {
var reader = new FileReader();
reader.onload = function(event) {
var content = event.target.result;
sup.ShowUploadedRspec(content);
};
reader.readAsText(this.files[0]);
});
}
catch (e) {
alert(e);
}
}
}
$('body').show();
}
function initIndex()
{
sup.UpdateProfileSelection($('#profile_name li[value = ' + window.PROFILE + ']'));
$('#quickvm_topomodal').on('hidden.bs.modal', function() {
sup.ShowProfileList($('.current'))
});
initIndexButtons();
}
function initIndexButtons()
{
$('button#reset-form').click(function (event) {
event.preventDefault();
sup.resetForm($('#quickvm_form'));
});
$('button#profile').click(function (event) {
event.preventDefault();
sup.ShowModal('#quickvm_topomodal');
});
$('li.profile-item').click(function (event) {
event.preventDefault();
sup.ShowProfileList(event.target);
});
$('button#showtopo_select').click(function (event) {
event.preventDefault();
sup.UpdateProfileSelection($('.selected'));
});
}
function initStatusButtons()
{
$('button#register-account').click(function (event) {
event.preventDefault();
sup.RegisterAccount(window.APT_OPTIONS.creatorUid,
window.APT_OPTIONS.creatorEmail);
});
$('button#request-extension').click(function (event) {
event.preventDefault();
sup.RequestExtension(window.APT_OPTIONS.uuid);
});
$('button#extend').click(function (event) {
event.preventDefault();
sup.Extend(window.APT_OPTIONS.uuid);
});
$('button#terminate').click(function (event) {
event.preventDefault();
sup.Terminate(window.APT_OPTIONS.uuid, 'quickvm.php');
});
}
function initLoginButton()
{
$('#quickvm_login_modal_button').click(function (event) {
event.preventDefault();
sup.LoginByModal();
});
$('#logoutbutton').click(function (event) {
event.preventDefault();
sup.Logout();
});
window.APT_OPTIONS.initialize(sup);
}
$(document).ready(initialize);
......
window.APT_OPTIONS.config();
require(['jquery', 'js/quickvm_sup',
// jQuery modules
'bootstrap', 'formhelpers'],
function ($, sup)
{
'use strict';
function initialize()
{
window.APT_OPTIONS.initialize(sup);
try {
$('#rspecfile').change(function() {
var reader = new FileReader();
reader.onload = function(event) {
var content = event.target.result;
sup.ShowUploadedRspec(content);
};
reader.readAsText(this.files[0]);
});
}
catch (e) {
alert(e);
}
}
$(document).ready(initialize);
});
window.APT_OPTIONS.config();
require(['jquery', 'js/quickvm_sup',
// jQuery modules
'bootstrap', 'formhelpers'],
function ($, sup)
{
'use strict';
function initialize()
{
window.APT_OPTIONS.initialize(sup);
sup.UpdateProfileSelection($('#profile_name li[value = ' + window.PROFILE + ']'));
$('#quickvm_topomodal').on('hidden.bs.modal', function() {
sup.ShowProfileList($('.current'))
});
$('button#reset-form').click(function (event) {
event.preventDefault();
sup.resetForm($('#quickvm_form'));
});
$('button#profile').click(function (event) {
event.preventDefault();
sup.ShowModal('#quickvm_topomodal');
});
$('li.profile-item').click(function (event) {
event.preventDefault();
sup.ShowProfileList(event.target);
});
$('button#showtopo_select').click(function (event) {
event.preventDefault();
sup.UpdateProfileSelection($('.selected'));
});
}
$(document).ready(initialize);
});
window.APT_OPTIONS.config();
require(['jquery', 'js/quickvm_sup',
// jQuery modules
'bootstrap', 'formhelpers'],
function ($, sup)
{
'use strict';
function initialize()
{
window.APT_OPTIONS.initialize(sup);
sup.InitQuickVM(window.APT_OPTIONS.uuid,
window.APT_OPTIONS.sliceExpires);
$('button#register-account').click(function (event) {
event.preventDefault();
sup.RegisterAccount(window.APT_OPTIONS.creatorUid,
window.APT_OPTIONS.creatorEmail);
});
$('button#request-extension').click(function (event) {
event.preventDefault();
sup.RequestExtension(window.APT_OPTIONS.uuid);
});
$('button#extend').click(function (event) {
event.preventDefault();
sup.Extend(window.APT_OPTIONS.uuid);
});
$('button#terminate').click(function (event) {
event.preventDefault();
sup.Terminate(window.APT_OPTIONS.uuid, 'quickvm.php');
});
}
$(document).ready(initialize);
});
window.APT_OPTIONS.config();
require(['jquery', 'js/quickvm_sup',
// jQuery modules
'bootstrap', 'formhelpers'],
function ($, sup)
{
'use strict';
function initialize()
{
window.APT_OPTIONS.initialize(sup);
$('button#reset-form').click(function (event) {
event.preventDefault();
sup.resetForm($('#quickvm_signup_form'));
});
if (window.APT_OPTIONS.ShowVerifyModal)
{
sup.ShowModal('#verify_modal');
}
}
$(document).ready(initialize);
});
window.APT_OPTIONS.config();
require(['jquery', 'js/quickvm_sup',
// jQuery modules
'bootstrap', 'formhelpers'],
function ($, sup)
{
'use strict';
function initialize()
{
window.APT_OPTIONS.initialize(sup);
sup.StartSSH('sshpanel', window.APT_OPTIONS.authObject);
}
$(document).ready(initialize);
});
......@@ -58,6 +58,7 @@ if (NOLOGINS()) {
SPITHEADER();
SPITUSERERROR("Sorry, logins are temporarily disabled, ".
"please try again later.");
echo "<script src='js/lib/require.js' data-main='js/main'></script>";
SPITFOOTER();
return;
}
......@@ -130,6 +131,7 @@ function SPITFORM($uid, $referrer, $error)
</div>
</div>\n";
echo "<script src='js/lib/require.js' data-main='js/main'></script>";
SPITFOOTER();
return;
}
......@@ -165,6 +167,7 @@ else {
restored. <br> <br>
Please do not attempt to login again; it will not work!
</h3>\n";
echo "<script src='js/lib/require.js' data-main='js/main'></script>";
SPITFOOTER();
return;
}
......
......@@ -44,6 +44,7 @@ if ($this_user) {
else {
SPITHEADER();
echo "<center><font color=red>Logout failed!</font></failed>\n";
echo "<script src='js/lib/require.js' data-main='js/main'></script>";
SPITFOOTER();
}
}
......
......@@ -200,12 +200,7 @@ function SPITFORM($formfields, $errors)
</div>
</div>\n";
echo "<script type='text/javascript'>\n";
echo "window.APT_OPTIONS = {\n";
echo " pageType: 'manage_profile',\n";
echo "};\n";
echo "</script>\n";
echo "<script src='js/lib/require.js' data-main='js/manage_profile'></script>"
SPITFOOTER();
}
......
......@@ -284,16 +284,11 @@ function SPITFORM($username, $email, $sshkey, $profile, $newuser, $errors)
else {
echo "window.PROFILE = '$profile_default';\n";
}
echo "</script>\n";
echo "<script type='text/javascript'>\n";
echo "window.APT_OPTIONS = {\n";
echo " pageType: 'index',\n";
if ($newuser) {
echo " isNewUser: true\n";
echo "window.APT_OPTIONS.isNewUser = true;\n";
}
echo "};\n";
echo "</script>\n";
echo "<script src='js/lib/require.js' data-main='js/quickvm'></script>"
}
if (!isset($create)) {
......
......@@ -280,14 +280,12 @@ echo "</div>\n"; # cols
echo "</div>\n"; # row
echo "<script type='text/javascript'>\n";
echo "window.APT_OPTIONS = {\n";
echo " pageType: 'status',\n";
echo " uuid: '" . $uuid . "',\n";
echo " sliceExpires: '" . $slice_expires . "',\n";
echo " creatorUid: '" . $creator_uid . "',\n";
echo " creatorEmail: '" . $creator_email . "'\n";
echo "};\n";
echo " window.APT_OPTIONS.uuid = '" . $uuid . "';\n";
echo " window.APT_OPTIONS.sliceExpires = '" . $slice_expires . "';\n";
echo " window.APT_OPTIONS.creatorUid = '" . $creator_uid . "';\n";
echo " window.APT_OPTIONS.creatorEmail = '" . $creator_email . "';\n";
echo "</script>\n";
echo "<script src='js/lib/require.js' data-main='js/quickvm_status'></script>";
#
# A modal to tell people how to register
......
......@@ -65,7 +65,7 @@ function SPITHEADER($thinheader = 0)
<title>AptLab</title>
<link rel='stylesheet' href='bootstrap/css/bootstrap.css'>
<link rel='stylesheet' href='quickvm.css'>
<script src='js/lib/require.js' data-main='js/main'></script>
<script src='js/common.js'></script>
<script src='https://www.emulab.net/emulab_sup.js'></script>
</head>
<body style='display: none'>\n";
......
......@@ -274,13 +274,11 @@ function SPITFORM($formfields, $showverify, $errors)
\n";
echo "<script type='text/javascript'>\n";
echo "window.APT_OPTIONS = {\n";
echo " pageType: 'signup',\n";
if ($showverify) {
echo " ShowVerifyModal: true\n";
echo "window.APT_OPTIONS.ShowVerifyModal = true;\n";
}
echo "};\n";
echo "</script>\n";
echo "<script src='js/lib/require.js' data-main='js/signup'></script>"
SPITFOOTER();
}
#
......
......@@ -52,11 +52,9 @@ echo "</div>\n";
echo "</div>\n";
echo "<script type='text/javascript'>\n";
echo "window.APT_OPTIONS = {\n";
echo " pageType: 'sshterm',\n";
echo " authObject: '" . $auth_object . "'\n";
echo "};\n";
echo "window.APT_OPTIONS.authObject = '" . $auth_object . "';\n";
echo "</script>\n";
echo "<script src='js/lib/require.js' data-main='js/sshterm'></script>";
SPITFOOTER();
?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment