Commit 9316dea7 authored by Leigh B Stoller's avatar Leigh B Stoller

A bunch of changes for handling errors, especially in parameterized

profiles. Problems still perist, I am sure.

Ultimately, this needs a lot of rewriting to make the control flow
more obvious and less fragile.
parent 13f9fef1
......@@ -132,16 +132,13 @@ body {
height: 300px;
}
#edit_nopicker {
height: 500px;
}
.edit_buttons {
float: right;
margin-top: 10px;
}
#edit_nopicker {
height: 500px;
width: 100%;
}
......
......@@ -236,6 +236,7 @@ function SPITFORM($formfields, $newuser, $errors)
global $TBBASE, $APTMAIL, $ISCLOUD;
global $profile_array, $this_user, $profilename, $profile, $am_array;
global $projlist;
$skipsteps = "false";
$amlist = array();
$showabout = ($ISCLOUD || !$this_user ? 1 : 0);
$registered = (isset($this_user) ? "true" : "false");
......@@ -259,6 +260,7 @@ function SPITFORM($formfields, $newuser, $errors)
}
# XSS prevention.
if ($errors) {
$skipsteps = "true";
while (list ($key, $val) = each ($errors)) {
# Skip internal error, we want the html in those errors
# and we know it is safe.
......@@ -284,7 +286,7 @@ function SPITFORM($formfields, $newuser, $errors)
};
SPITHEADER(1);
echo "<div id='waitwait_div'></div>\n";
echo "<div id='ppviewmodal_div'></div>\n";
# Placeholder for the "about" panel, which is now a template file.
echo "<div id='about_div' class='col-lg-8 col-lg-offset-2
......@@ -604,7 +606,9 @@ function SPITFORM($formfields, $newuser, $errors)
echo "<textarea name='formfields[pp_rspec]'
id='pp_rspec_textarea'
class='form-control hidden'
type='textarea'></textarea>\n";
type='textarea'>".
(isset($formfields['pp_rspec']) ? $formfields['pp_rspec'] : "") .
"</textarea>\n";
echo "</form>\n
</div>\n";
if (!isset($this_user)) {
......@@ -658,7 +662,6 @@ function SPITFORM($formfields, $newuser, $errors)
}
SpitTopologyViewModal("quickvm_topomodal", $profile_array);
echo "<div id='waitwait_div'></div>\n";
echo "<div id='ppmodal_div'></div>\n";
echo "<div id='instantiate_div'></div>\n";
echo "<div id='editmodal_div'></div>\n";
......@@ -678,6 +681,7 @@ function SPITFORM($formfields, $newuser, $errors)
echo " window.REGISTERED = $registered;\n";
echo " window.WEBONLY = $webonly;\n";
echo " window.PORTAL = '$portal';\n";
echo " window.SKIPSTEPS = $skipsteps;\n";
if ($newuser) {
echo "window.APT_OPTIONS.isNewUser = true;\n";
}
......@@ -793,8 +797,8 @@ elseif (! array_key_exists($formfields["profile"], $profile_array)) {
$errors["profile"] = "Invalid Profile: " . $formfields["profile"];
}
else {
$profile = Profile::Lookup($formfields["profile"]);
if (!$profile) {
$temp = Profile::Lookup($formfields["profile"]);
if (!$temp) {
$errors["profile"] = "No such profile in the database";
}
}
......
......@@ -37,13 +37,13 @@ function (_, Constraints, sup, ppstart, JacksEditor, aboutaptString, aboutcloudS
$('#instantiate_submit').prop('disabled', true);
$.get(contextUrl).then(contextReady, contextFail);
window.APT_OPTIONS.initialize(sup);
window.APT_OPTIONS.initialize(ppstart);
registered = window.REGISTERED;
window.APT_OPTIONS.initialize(sup);
window.APT_OPTIONS.initialize(ppstart);
registered = window.REGISTERED;
webonly = window.WEBONLY;
isadmin = window.ISADMIN;
portal = window.PORTAL;
ajaxurl = window.AJAXURL;
ajaxurl = window.AJAXURL;
$('#stepsContainer').steps({
headerTag: "h3",
......@@ -52,26 +52,56 @@ function (_, Constraints, sup, ppstart, JacksEditor, aboutaptString, aboutcloudS
autoFocus: true,
onStepChanging: function(event, currentIndex, newIndex) {
if (currentIndex == 0 && newIndex == 1) {
if (ispprofile) {
if (selected_uuid != loaded_uuid) {
$('#stepsContainer-p-1 > div').attr('style','display:block');
ppstart.StartPP({uuid : selected_uuid,
registered : registered,
isadmin : isadmin,
amlist : amlist,
amdefault : amdefault,
callback : ConfigureDone,
button_label : "Accept"});
loaded_uuid = selected_uuid;
ppchanged = true;
}
}
else {
$('#stepsContainer-p-1 > div').attr('style','display:none');
loaded_uuid = selected_uuid;
if (ispprofile) {
if (selected_uuid != loaded_uuid) {
$('#stepsContainer-p-1 > div')
.attr('style','display:block');
ppstart.StartPP(
{uuid : selected_uuid,
registered : registered,
isadmin : isadmin,
amlist : amlist,
amdefault : amdefault,
callback : ConfigureDone,
button_label : "Accept",
rspec :
(!window.SKIPSTEPS ? null :
$('#pp_rspec_textarea').val()),
});
loaded_uuid = selected_uuid;
ppchanged =
(window.SKIPSTEPS ? false : true);
}
}
else {
$('#stepsContainer-p-1 > div')
.attr('style','display:none');
loaded_uuid = selected_uuid;
}
}
else if (currentIndex == 1 && newIndex == 2) {
if (ispprofile && ppchanged &&
!window.SKIPSTEPS) {
ppstart.HandleSubmit(function(success) {
if (success) {
ppchanged = false;
$('#stepsContainer-t-1')
.parent().removeClass('error');
$('#stepsContainer').steps('next');
}
else {
$('#stepsContainer-t-1')
.parent().addClass('error');
}
});
// We do not proceed until the form is
// submitted properly. This has a bad
// side effect; the steps code assumes
// this means failure and adds the error
// class.
return false;
}
// Set up the Finalize tab
$('#stepsContainer-p-2 #finalize_options').html('');
// Each .experiment_option in the form is copied to the last page.
......@@ -134,10 +164,6 @@ function (_, Constraints, sup, ppstart, JacksEditor, aboutaptString, aboutcloudS
else if (currentIndex == 2 && priorIndex == 1) {
// Keep the two panes the same height
$('#inline_container').css('height', $('#finalize_container').outerHeight());
if (ispprofile && ppchanged) {
ppstart.HandleSubmit();
ppchanged = false;
}
}
if (currentIndex < priorIndex) {
......@@ -410,6 +436,13 @@ function (_, Constraints, sup, ppstart, JacksEditor, aboutaptString, aboutcloudS
.filter('[value="'+ amdefault + '"]')
.prop('selected', true);
}
if (window.SKIPSTEPS) {
$('#stepsContainer').steps("next");
if (ispprofile) {
$('#stepsContainer').steps("next");
}
window.SKIPSTEPS = 0;
}
updateWhere();
};
GetProfile($(selectedElement).attr('value'), continuation);
......
......@@ -109,7 +109,7 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
return root;
}
function HandleSubmit()
function HandleSubmit(callback)
{
/*
* If not a registered user, then continue takes them back.
......@@ -124,7 +124,7 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
// Submit with check only at first, since this will return
// very fast, so no need to throw up a waitwait.
SubmitForm(1);
SubmitForm(1, callback);
}
// Instantiate the new rspec on the chosen aggregate.
......@@ -187,12 +187,12 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
// Submit the form. If no errors, we get back the rspec. Throw that
// up in a Jack editor window.
//
function SubmitForm(checkonly)
function SubmitForm(checkonly, steps_callback)
{
// Current form contents as formfields array.
var formfields = {};
var callback = function(json) {
var callback = function(json) {
if (!checkonly) {
sup.HideModal("#waitwait-modal");
}
......@@ -200,30 +200,23 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
if (checkonly && json.code == 2) {
// Regenerate page with errors.
GenerateModalBody(formfields, json.value);
return;
}
sup.HideModal('#ppmodal');
$('#stepsContainer').steps('previous');
$('#stepsContainer-t-1').parent().addClass('error');
//sup.SpitOops("oops", json.value);
else {
sup.SpitOops("oops", json.value);
}
steps_callback(false);
return;
}
if (checkonly) {
// Form checked out okay, submit again to generate rspec.
sup.HideModal('#ppmodal');
sup.ShowModal("#waitwait-modal");
SubmitForm(0);
SubmitForm(0, steps_callback);
}
else {
steps_callback(true);
if (_.has(json.value, "amdefault")) {
amdefault = json.value.amdefault;
}
// Got the rspec, show the editor.
RSPEC = json.value.rspec;
editor.show(json.value.rspec,
EditorDone, EditorCancel, button_label);
EditorDone(editor.fetchXml());
ShowEditor(json.value.rspec);
}
}
// Convert form data into formfields array, like all our
......@@ -235,16 +228,21 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
// This clears any errors before new submit. Needs more thought.
GenerateModalBody(formfields, null);
var xmlthing = sup.CallServerMethod(null, "manage_profile",
"BindParameters",
{"formfields" : formfields,
"uuid" : uuid,
"checkonly" : checkonly});
// Not in checkform mode, this will take time.
if (!checkonly) {
sup.ShowModal("#waitwait-modal");
}
var xmlthing =
sup.CallServerMethod(null, "manage_profile",
"BindParameters",
{"formfields" : formfields,
"uuid" : uuid,
"checkonly" : checkonly});
xmlthing.done(callback);
}
function StartPP(args) {
uuid = args.uuid;
uuid = args.uuid;
registered = args.registered;
amlist = args.amlist;
amdefault = args.amdefault;
......@@ -272,7 +270,6 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
* the initial values.
*/
var callback = function(json) {
console.info(json);
if (json.code) {
sup.SpitOops("oops", json.value);
}
......@@ -293,6 +290,9 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
bodyTemplate = _.template(html);
GenerateModalBody(defaults, null);
//sup.ShowModal('#ppmodal');
if (args.rspec) {
ShowEditor(args.rspec);
}
}
var xmlthing = sup.CallServerMethod(null, "instantiate",
"GetParameters",
......@@ -302,8 +302,12 @@ function(_, sup, JacksEditor, ppmodalString, ppbodyString, chooserString)
function ChangeJacksRoot(root, selectionPane) {
editor = new JacksEditor(root, true, true, selectionPane, true);
editor.show(RSPEC,
EditorDone, EditorCancel, button_label);
editor.show(RSPEC, EditorDone, EditorCancel, button_label);
}
function ShowEditor(rspec) {
RSPEC = rspec;
editor.show(RSPEC, EditorDone, EditorCancel, button_label);
EditorDone(RSPEC);
}
return {
......
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