Commit e277960d authored by Leigh Stoller's avatar Leigh Stoller

Checkpoint change to join/start tabs.

parent 2b34d4d0
......@@ -32,6 +32,70 @@ function (_, sup,
window.APT_OPTIONS.joinproject,
window.APT_OPTIONS.ShowVerifyModal,
window.APT_OPTIONS.this_user);
// Carry this forward.
if (window.APT_OPTIONS.ShowVerifyModal) {
var $jval = (window.APT_OPTIONS.joinproject ? "1" : "0");
$('#quickvm_signup_form').append("<input type='hidden' " +
" id='joinproject' " +
" name='joinproject' " +
" value='jval' />");
}
// But if bound, make sure we have proper tab active.
if (typeof window.APT_OPTIONS.joinproject === 'undefined' ||
!window.APT_OPTIONS.joinproject) {
$("#project_tabs a:last").tab('show');
}
else {
$("#project_tabs a:first").tab('show');
}
/*
* Intercept the submit so we can check to see if the user
* is joining or starting a project. We do this by looking
* to see which of the tabs is active.
*
* XXX Both tabs need the same formfields[pid] entry, but
* it does not work to have two input fields with the same
* name, so yank the input field out of the inactive tab.
*
* Also add the joinproject boolean so the server side knows
* what the user is doing (join or start).
*/
$('button#submit_button').click(function (event) {
if ($('#join_tab').hasClass('active')) {
$('#joinproject').remove();
$('#quickvm_signup_form').append("<input type='hidden' " +
" id='joinproject' " +
" name='joinproject' " +
" value='1' />");
$('#form_start_pid').remove();
}
else {
$('#joinproject').remove();
$('#quickvm_signup_form').append("<input type='hidden' " +
" id='joinproject' " +
" name='joinproject' " +
" value='0' />");
$('#form_join_pid').remove();
}
});
/*
* When the user toggles from one tab to the other, change
* the label in the button.
*/
if (window.APT_OPTIONS.this_user) {
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
if ($('#join_tab').hasClass('active')) {
$('#submit_button').text("Join Project");
}
else {
$('#submit_button').text("Start Project");
}
});
}
}
function renderForm(formfields, errors, joinproject, showVerify, thisUser)
......@@ -45,7 +109,7 @@ function (_, sup,
var personal = formatter(personalTemplate({
formfields: formfields
}), errors);
var project = formatter(projectTemplate({
var project = Newformatter(projectTemplate({
joinproject: joinproject,
formfields: formfields
}), errors);
......@@ -120,5 +184,32 @@ function (_, sup,
return result;
}
// Better version.
function Newformatter(fieldString, errors)
{
var root = $(fieldString);
var list = root.find('.format-me');
list.each(function (index, item) {
if (item.dataset) {
var key = item.dataset['key'];
var wrapper = $('<div></div>');
wrapper.addClass('sidebyside-form');
wrapper.addClass('form-group');
wrapper.html($(item).clone());
if (_.has(errors, key))
{
wrapper.addClass('has-error');
wrapper.append('<label class="control-label" ' +
'for="inputError">' + _.escape(errors[key]) +
'</label>');
}
$(item).after(wrapper);
$(item).remove();
}
});
return root;
}
$(document).ready(initialize);
});
......@@ -25,6 +25,8 @@ chdir("..");
include("defs.php3");
chdir("apt");
include("quickvm_sup.php");
# Do not create anything, just do the checks.
$debug = 1;
#
# Get current user.
......@@ -82,8 +84,9 @@ function SPITFORM($formfields, $showverify, $errors)
# }
# echo "};\n";
if ($joinproject) {
echo "window.APT_OPTIONS.joinproject = true;\n";
if (isset($joinproject)) {
$joinproject = ($joinproject ? "true" : "false");
echo "window.APT_OPTIONS.joinproject = $joinproject;\n";
}
if ($showverify) {
echo "window.APT_OPTIONS.ShowVerifyModal = true;\n";
......@@ -315,8 +318,9 @@ if (!$this_user) {
}
}
if (0) {
TBERROR("New APT User" . print_r($formfields, TRUE), 0);
if ($debug) {
TBERROR("New APT User ($joinproject)" .
print_r($formfields, TRUE), 0);
SPITFORM($formfields, 0, $errors);
return;
}
......@@ -390,6 +394,15 @@ if (!$this_user) {
return;
}
}
elseif ($joinproject) {
$group = $project->LoadDefaultGroup();
if ($project->AddNewMember($this_user) < 0) {
TBERROR("Could not add new user to project group $pid", 1);
}
$group->NewMemberNotify($this_user);
header("Location: instantiate.php");
return;
}
#
# Now for the new Project
......
<input name="formfields[pid]" value="<%- formfields.pid %>"
class="form-control" data-key="pid"
placeholder="Project Name" type="text">
<% if (! joinproject) { %>
<!-- Creating a new project. -->
<input name="formfields[proj_title]" value="<%- formfields.proj_title %>"
class="form-control" data-key="proj_title"
placeholder="Project Title (short sentence)" type="text">
<input name="formfields[proj_url]" value="<%- formfields.proj_url %>"
class="form-control" data-key="proj_url"
placeholder="Project Page URL" type="text">
<textarea name="formfields[proj_why]" rows="8"
class="form-control" data-key="proj_why"
placeholder="projectDescription (details)" type="textarea">
<%- formfields.proj_why %>
</textarea>
<% } %>
<div>
<ul class='nav nav-tabs' id='project_tabs'>
<li class='active'>
<a href='#join_tab' data-toggle='tab'>Join Project</a>
</li>
<li>
<a href='#start_tab' data-toggle='tab'>Start Project</a>
</li>
</ul>
<div class='tab-content'>
<div class='tab-pane active' id='join_tab'>
<input name="formfields[pid]" value="<%- formfields.pid %>"
id="form_join_pid"
class="form-control format-me" data-key="pid"
placeholder="Project Name" type="text">
</div>
<div class='tab-pane' id='start_tab'>
<input name="formfields[pid]" value="<%- formfields.pid %>"
id="form_start_pid"
class="form-control format-me" data-key="pid"
placeholder="Project Name" type="text">
<input name="formfields[proj_title]" value="<%- formfields.proj_title %>"
class="form-control format-me" data-key="proj_title"
placeholder="Project Title (short sentence)" type="text">
<input name="formfields[proj_url]" value="<%- formfields.proj_url %>"
class="form-control format-me" data-key="proj_url"
placeholder="Project Page URL" type="text">
<textarea name="formfields[proj_why]" rows="8"
class="form-control format-me" data-key="proj_why"
placeholder="Project Description (details)"
type="textarea"><%- formfields.proj_why %></textarea>
</div>
</div>
</div>
......@@ -20,9 +20,6 @@
method='post' action='signup.php'>
<div class='row'>
<div class='<% if (this_user) { %>col-sm-12<% } else { %>col-sm-6<% } %>'>
<% if (joinproject) { %>
<input type='hidden' name='joinproject' value=1>
<% } %>
<%= verify_modal %>
<input type='hidden' name='formfields[pubkey]'
value='<%- pubkey %>'>
......@@ -36,11 +33,7 @@
<% } %>
<fieldset>
<legend>
<% if (joinproject) { %>
Project Name
<% } else { %>
Project Information
<% } %>
Project Information
</legend>
<%= project_fields %>
</fieldset>
......@@ -52,6 +45,7 @@
Reset Form
</button>
<button class='btn btn-primary btm-sm pull-right'
id='submit_button'
type='submit' name='create'><%- button_label %></button>
</div>
</form>
......
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