Commit 59fb0036 authored by Jonathon Duerig's avatar Jonathon Duerig

Fix show-profile -> genilib-editor link logic.

Fix project selection in genilib-editor.
Embed html snippets inside of genilib-editor main page.
parent 86b6299f
......@@ -122,6 +122,8 @@ echo "<script src='https://cdn.jsdelivr.net/ace/1.2.3/noconflict/ace.js'></scrip
echo "<script src='https://cdn.jsdelivr.net/ace/1.2.3/noconflict/keybinding-vim.js'></script>\n";
echo "<script src='https://cdn.jsdelivr.net/ace/1.2.3/noconflict/keybinding-emacs.js'></script>\n";
echo "<script src='js/lib/require.js' data-main='js/genilib-editor'></script>";
EchoTemplateList(array("genilib-editor", "oops-modal", "waitwait-modal", "manage-profile"));
SPITFOOTER();
?>
......@@ -161,3 +161,13 @@ window.APT_OPTIONS.nagPI = function (pid) {
});
return false;
};
window.APT_OPTIONS.fetchTemplate = function (name) {
var result = '';
var element = document.getElementById(name);
if (element)
{
result = atob(element.innerHTML);
}
return result;
};
require(window.APT_OPTIONS.configObject,
['underscore', 'js/quickvm_sup', 'js/aptforms',
'js/lib/text!template/genilib-editor.html',
'js/lib/text!template/oops-modal.html',
'js/lib/text!template/waitwait-modal.html',
'js/lib/text!template/manage-profile.html',
// 'js/lib/text!template/genilib-editor.html',
// 'js/lib/text!template/oops-modal.html',
// 'js/lib/text!template/waitwait-modal.html',
// 'js/lib/text!template/manage-profile.html',
'jacks'],
function (_, sup, aptforms,
pageString, oopsString, waitwaitString, manageString)
function (_, sup, aptforms)//,
// pageString, oopsString, waitwaitString, manageString)
{
'use strict';
var pageString = APT_OPTIONS.fetchTemplate('genilib-editor');
var oopsString = APT_OPTIONS.fetchTemplate('oops-modal');
var waitwaitString = APT_OPTIONS.fetchTemplate('waitwait-modal');
var manageString = APT_OPTIONS.fetchTemplate('manage-profile');
var editor;
var isWaiting = false;
var isSplit = false;
......@@ -376,10 +382,20 @@ function (_, sup, aptforms,
function updateCreateBody()
{
var projlist = JSON.parse(_.unescape($('#projects-json')[0].textContent));
var project = undefined;
if (projlist.length == 1)
{
project = projlist[0];
}
else if (window.PROFILE_PROJECT && _.contains(projlist, window.PROFILE_PROJECT))
{
project = window.PROFILE_PROJECT;
}
var fields = {
profile_script: editor.getValue(),
profile_rspec: rspec,
profile_who: 'private'
profile_who: 'private',
profile_pid: project
};
var manage_html = manageTemplate({
formfields: fields,
......
......@@ -114,23 +114,29 @@ function (_, sup, moment,
// The Show Source button.
$('#show_source_modal_button, #show_xml_modal_button')
.click(function (event) {
var source = null;
var source = null;
var isScript = true;
var href = "show-profile.php?uuid=" + profile_uuid;
if ($(this).attr("id") == "show_source_modal_button") {
/*
source = $.trim($('#profile_script_textarea').val());
source = $.trim($('#profile_script_textarea').val());
$('#rspec_modal_download_button')
.attr("href", href + "&source=true");
if (! source || ! source.length) {
isScript = false;
}
if (isScript == false ||
$(this).attr("id") != "show_source_modal_button") {
source = $.trim($('#profile_rspec_textarea').val());
$('#rspec_modal_download_button')
.attr("href", href + "&source=true");
*/
.attr("href", href + "&rspec=true");
}
if ($(this).attr("id") == "show_source_modal_button" && isScript) {
openEditor();
}
else
{
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");
......
......@@ -877,4 +877,23 @@ function CheckLoginOrRedirect($modifier = 0)
return $this_user;
}
#
# Echos a plaintext <script> tag with a base64-encoded template inside.
# The <script> tag has an id of $baseName. The template is loaded from
# the path 'template/$baseName.html'
#
function EchoTemplate($baseName)
{
echo "\n<script type='text/plain' id='" . $baseName . "'>\n";
echo base64_encode(file_get_contents("template/" . $baseName . ".html")) . "\n";
echo "</script>\n";
}
function EchoTemplateList($nameList)
{
foreach ($nameList as $index => $name) {
EchoTemplate($name);
}
}
?>
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