Commit 06effa0f authored by Leigh B Stoller's avatar Leigh B Stoller

Add a download button on the show-profile/manage_profile pages, at the

bottom of the show source modal. And on just the manage_profile page,
add an Upload button.
parent 333c8aee
......@@ -146,7 +146,7 @@ function (_, sup, filesize, JacksEditor, ShowImagingModal, moment, aptforms,
// runs at page load, and so the filestyle'd button in the
// form is not as it should be.
//
$('#sourcefile').each(function() {
$('#sourcefile, #rspec_modal_upload_button').each(function() {
$(this).filestyle({input : false,
buttonText : $(this).attr('data-buttonText'),
classButton: $(this).attr('data-classButton')});
......@@ -170,19 +170,34 @@ function (_, sup, filesize, JacksEditor, ShowImagingModal, moment, aptforms,
//
// File upload handler.
//
$('#sourcefile').change(function() {
var reader = new FileReader();
reader.onload = function(event) {
var newrspec = event.target.result;
/*
* Clear the file so that the change handler will
* run if the same file is selected again (say, after
* fixing a script error).
*/
$("#sourcefile").filestyle('clear');
$('#sourcefile, #rspec_modal_upload_button').change(function() {
var reader = new FileReader();
var button = $(this);
reader.onload = function(event) {
var newrspec = event.target.result;
/*
* Clear the file so that the change handler will
* run if the same file is selected again (say, after
* fixing a script error).
*/
$("#sourcefile, #rspec_modal_upload_button").filestyle('clear');
/*
* If the modal upload button is used, we want to change the
* contents of the modal only. User has to accept the change.
*/
if ($(button).attr("id") == "rspec_modal_upload_button") {
$('#modal_profile_rspec_textarea').val(newrspec);
// The modal shown event updates the code in the modal.
$('#rspec_modal').trigger('shown.bs.modal');
}
else {
changeRspec(newrspec);
};
reader.readAsText(this.files[0]);
}
};
reader.readAsText(this.files[0]);
});
// Handler for all paths to rspec change (file upload, jacks, edit).
......@@ -212,9 +227,18 @@ function (_, sup, filesize, JacksEditor, ShowImagingModal, moment, aptforms,
// is no script.
//
var source = $.trim($('#profile_script_textarea').val());
var href = "show-profile.php?uuid=" + profile_uuid;
if (!source.length) {
source = $.trim($('#profile_rspec_textarea').val());
$('#rspec_modal_download_button')
.attr("href", href + "&rspec=true");
}
else {
$('#rspec_modal_download_button')
.attr("href", href + "&source=true");
}
$('#rspec_modal_upload_span').removeClass("hidden");
$('#rspec_modal_editbuttons').removeClass("hidden");
$('#rspec_modal_viewbuttons').addClass("hidden");
$('#modal_profile_rspec_textarea').prop("readonly", false);
......@@ -230,6 +254,11 @@ function (_, sup, filesize, JacksEditor, ShowImagingModal, moment, aptforms,
// XML, but it is not intended to be edited.
//
var source = $.trim($('#profile_rspec_textarea').val());
var href = "show-profile.php?uuid=" + profile_uuid +
"&rspec=true";
$('#rspec_modal_download_button')
.attr("href", href + "&rspec=true");
$('#rspec_modal_upload_span').addClass("hidden");
$('#rspec_modal_editbuttons').addClass("hidden");
$('#rspec_modal_viewbuttons').removeClass("hidden");
$('#modal_profile_rspec_textarea').val(source);
......@@ -249,6 +278,10 @@ function (_, sup, filesize, JacksEditor, ShowImagingModal, moment, aptforms,
if (myRe.test(source)) {
mode = "text/x-python";
}
// In case we got here via the modal upload button, need to
// kill the current contents.
$('.CodeMirror').remove();
myCodeMirror = CodeMirror(function(elt) {
$('#modal_profile_rspec_div').prepend(elt);
}, {
......
......@@ -99,12 +99,17 @@ function (_, sup, moment,
$('#show_source_modal_button, #show_xml_modal_button')
.click(function (event) {
var source = null;
var href = "show-profile.php?uuid=" + profile_uuid;
if ($(this).attr("id") == "show_source_modal_button") {
source = $.trim($('#profile_script_textarea').val());
$('#rspec_modal_download_button')
.attr("href", href + "&source=true");
}
if (!source || !source.length) {
source = $.trim($('#profile_rspec_textarea').val());
$('#rspec_modal_download_button')
.attr("href", href + "&rspec=true");
}
$('#rspec_modal_editbuttons').addClass("hidden");
$('#rspec_modal_viewbuttons').removeClass("hidden");
......
<?php
#
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -41,11 +41,10 @@ $isadmin = (ISADMIN() ? 1 : 0);
#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("uuid", PAGEARG_STRING);
$reqargs = RequiredPageArguments("uuid", PAGEARG_STRING);
$optargs = OptionalPageArguments("source", PAGEARG_BOOLEAN,
"rspec", PAGEARG_BOOLEAN);
SPITHEADER(1);
echo "<div id='ppviewmodal_div'></div>\n";
if (!isset($uuid)) {
SPITUSERERROR("Must provide uuid!");
}
......@@ -56,6 +55,23 @@ if (!$profile) {
if (!$profile->CanView($this_user) && !(ISADMIN() || ISFOREIGN_ADMIN())) {
SPITUSERERROR("Not enough permission!");
}
# For the download source button.
if ($source || $rspec) {
$filename = $profile->name() . ".xml";
$stuff = $profile->rspec();
if ($source && $profile->script() && $profile->script() != "") {
$stuff = $profile->script();
$filename = $profile->name() . ".py";
}
header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename='${filename}'");
echo $stuff;
return;
}
SPITHEADER(1);
echo "<div id='ppviewmodal_div'></div>\n";
$profile_uuid = $profile->profile_uuid();
$version_uuid = $profile->uuid();
$ispp = ($profile->isParameterized() ? 1 : 0);
......
......@@ -25,6 +25,19 @@
<div class='panel panel-default'>
<div id='modal_profile_rspec_div' style='height:300px'></div>
</div>
<div>
<center>
<a type='button' id="rspec_modal_download_button"
class='btn btn-info btn-xs'>Download</a>
<span id="rspec_modal_upload_span" class="hidden">
<input class='filestyle hidden' type='file'
id="rspec_modal_upload_button"
data-classButton='btn btn-primary btn-xs'
data-input='false'
style='margin-left: 10px;'
data-buttonText='Upload'></span>
</center>
</div>
<textarea name=\"formfields[profile_rspec_modal]\"
id='modal_profile_rspec_textarea'
rows=20
......
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