JSLint.

Doesn't fix all style, but already much better now.
parent c7b9c569
$(document).ready( function() { $(document).ready(function() {
var editor; var editor;
setupFileTree(); setupFileTree();
$($("#slappart li")[0]).find("input:radio").attr('checked', true); $($('#slappart li')[0]).find('input:radio').attr('checked', true);
$(".menu-box-right>div").css('min-height', $("#slappart li").length*26 + 20 + "px"); $('.menu-box-right>div').css('min-height', $('#slappart li').length * 26 + 20 + 'px');
configRadio(); configRadio();
var send = false; var send = false;
var lastli = null; var lastli = null;
var partitionAmount = $("input#partitionAmount").val(); var partitionAmount = $('input#partitionAmount').val();
$("#slappart li").each(function(){ $('#slappart li').each(function() {
lastli = $(this); lastli = $(this);
$(this).find("input:radio").change(function(){ $(this).find('input:radio').change(function() {
configRadio(); configRadio();
}); });
}); });
if(lastli){lastli.css("border-bottom", "none");} if (lastli) {lastli.css('border-bottom', 'none');}
$("#parameterkw").slideBox("show"); $('#parameterkw').slideBox('show');
setupSlappart(); setupSlappart();
$("#softwareType").slideBox(); $('#softwareType').slideBox();
$("#reloadfiles").click(function(){ $('#reloadfiles').click(function() {
setupFileTree(); setupFileTree();
}); });
$("#refresh").click(function(){ $('#refresh').click(function() {
if (send) return; if (send) return;
$("#imgwaitting").fadeIn(); $('#imgwaitting').fadeIn();
$.ajax({ $.ajax({
type: "GET", type: 'GET',
url: $SCRIPT_ROOT + '/supervisordStatus', url: $SCRIPT_ROOT + '/supervisordStatus',
data: "", data: '',
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
$("#supervisordcontent").empty(); $('#supervisordcontent').empty();
$("#supervisordcontent").append(data.result); $('#supervisordcontent').append(data.result);
} }
$("#imgwaitting").fadeOut(); $('#imgwaitting').fadeOut();
} }
}); });
return false; return false;
}); });
$("#add_attribute").click(function(){ $('#add_attribute').click(function() {
var size = Number($("#partitionParameter > tbody > tr").last().attr('id').split('_')[1]) + 1; var size = Number($('#partitionParameter > tbody > tr').last().attr('id').split('_')[1]) + 1;
var row="<tr id='row_"+size+"'><td class='first'><input type='text' name='txt_"+size+"' id='txt_"+size+"'></td>"+ var row = "<tr id='row_" + size + "'><td class='first'><input type='text' name='txt_" + size + "' id='txt_" + size + "'></td>" +
"<td style='padding:6px'><textarea class='slap' id='value_"+size+"'></textarea>"+ "<td style='padding:6px'><textarea class='slap' id='value_" + size + "'></textarea>" +
"</td><td valign='middle'><span style='margin-left: 10px;' id='btn_"+size+"' class='close'></span></td></tr>"; "</td><td valign='middle'><span style='margin-left: 10px;' id='btn_" + size + "' class='close'></span></td></tr>";
$("#partitionParameter").append(row); $('#partitionParameter').append(row);
setInput($("input#txt_"+size)); setInput($('input#txt_' + size));
setupTextarea($("textarea#value_"+size)); setupTextarea($('textarea#value_' + size));
$("#btn_"+size).click(function(){ $('#btn_' + size).click(function() {
var index = $(this).attr('id').split('_')[1]; var index = $(this).attr('id').split('_')[1];
$("tr#row_"+index).remove(); $('tr#row_' + index).remove();
}); });
return false; return false;
}); });
$("#updateParameters").click(function(){ $('#updateParameters').click(function() {
updateParameter(); updateParameter();
return false; return false;
}); });
$("#xmlview").click(function(){ $('#xmlview').click(function() {
var content = '<h2 style="color: #4c6172; font: 18px \'Helvetica Neue\', Helvetica, Arial, sans-serif;">' + var content = '<h2 style="color: #4c6172; font: 18px \'Helvetica Neue\', Helvetica, Arial, sans-serif;">' +
'INSTANCE PARAMETERS: Load XML file</h2><p id="xmllog" class="message"><br/></p>'; 'INSTANCE PARAMETERS: Load XML file</h2><p id="xmllog" class="message"><br/></p>';
content += '<div class="main_content" style="height:230px"><pre id="editor"></pre></div>'+ content += '<div class="main_content" style="height:230px"><pre id="editor"></pre></div>' +
'<input type=submit value="Load" id="loadxml" class="button">'; '<input type=submit value="Load" id="loadxml" class="button">';
$.ajax({ $.ajax({
type: "GET", type: 'GET',
url: $SCRIPT_ROOT + '/getParameterXml/xml', url: $SCRIPT_ROOT + '/getParameterXml/xml',
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
$("#inline_content").html(content); $('#inline_content').html(content);
setupEditor(true); setupEditor(true);
$(".inline").colorbox({inline:true, width: "600px", height: "410px", onComplete:function(){ $('.inline').colorbox({inline: true, width: '600px', height: '410px', onComplete: function() {
editor.getSession().setValue(data.result); editor.getSession().setValue(data.result);
}}); }});
$(".inline").click(); $('.inline').click();
$("#loadxml").click(function(){ $('#loadxml').click(function() {
//Parse XML file //Parse XML file
try{ try {
var xmlDoc = $.parseXML(editor.getSession().getValue()), $xml = $( xmlDoc ); var xmlDoc = $.parseXML(editor.getSession().getValue()), $xml = $(xmlDoc);
if($xml.find("parsererror").length !== 0){$("p#xmllog").html("Error: Invalid XML document!<br/>");return false;} if ($xml.find('parsererror').length !== 0) {$('p#xmllog').html('Error: Invalid XML document!<br/>');return false;}
} catch(err) { } catch (err) {
$("p#xmllog").html("Error: Invalid XML document!<br/>");return false; $('p#xmllog').html('Error: Invalid XML document!<br/>');return false;
} }
$.ajax({ $.ajax({
type: "POST", type: 'POST',
url: $SCRIPT_ROOT + '/saveParameterXml', url: $SCRIPT_ROOT + '/saveParameterXml',
data: {software_type:"", parameter:editor.getSession().getValue()}, data: {software_type: '', parameter: editor.getSession().getValue()},
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
location.href = $SCRIPT_ROOT + '/inspectInstance#tab3'; location.href = $SCRIPT_ROOT + '/inspectInstance#tab3';
location.reload(); location.reload();
} }
else{$("p#xmllog").html(data.result);} else {$('p#xmllog').html(data.result);}
} }
}); });
return false; return false;
}); });
} }
else{ else {
$("#error").Popup(data.result, {type:'error', duration:5000}); $('#error').Popup(data.result, {type: 'error', duration: 5000});
} }
} }
}); });
}); });
//Load previous instance parameters //Load previous instance parameters
loadParameter(); loadParameter();
$("a#parameterTab").click(function(){ $('a#parameterTab').click(function() {
var size = $("#partitionParameter > tbody > tr").length; var size = $('#partitionParameter > tbody > tr').length;
for(var i=2; i<=size; i++){ for (var i = 2; i <= size; i++) {
$("textarea#value_"+i).keyup(); $('textarea#value_' + i).keyup();
} }
}); });
function setupFileTree(path){ function setupFileTree(path) {
var root = $("input#root").val(); var root = $('input#root').val();
if (root == "") return; if (root == '') return;
if (path){ if (path) {
root += "/" + path; root += '/' + path;
$("#tab4>h2").html("File content for <strong>" + path + "</strong>"); $('#tab4>h2').html('File content for <strong>' + path + '</strong>');
} }
else{$("#tab4>h2").html("File content for all your partitions");} else {$('#tab4>h2').html('File content for all your partitions');}
$('#fileTree').empty(); $('#fileTree').empty();
$('#fileTree').fileTree({ root: root, script: $SCRIPT_ROOT + "/readFolder", folderEvent: 'click', expandSpeed: 750, $('#fileTree').fileTree({ root: root, script: $SCRIPT_ROOT + '/readFolder', folderEvent: 'click', expandSpeed: 750,
collapseSpeed: 750, multiFolder: false, selectFolder: false }, function(file) { collapseSpeed: 750, multiFolder: false, selectFolder: false }, function(file) {
}, function(file){ }, function(file) {
//User have double click on file in to the fileTree //User have double click on file in to the fileTree
viewFile(file); viewFile(file);
}); });
} }
function viewFile(file){ function viewFile(file) {
//User have double click on file in to the fileTree //User have double click on file in to the fileTree
loadFileContent(file); loadFileContent(file);
} }
$("#parameter").load($SCRIPT_ROOT + '/getParameterXml'); $('#parameter').load($SCRIPT_ROOT + '/getParameterXml');
$("#update").click(function(){ $('#update').click(function() {
if($("#parameter").val() == ""){ if ($('#parameter').val() == '') {
$("#error").Popup("Can not save empty value!", {type:'alert', duration:3000}); $('#error').Popup('Can not save empty value!', {type: 'alert', duration: 3000});
} }
$.ajax({ $.ajax({
type: "POST", type: 'POST',
url: $SCRIPT_ROOT + '/saveParameterXml', url: $SCRIPT_ROOT + '/saveParameterXml',
data: {parameter: $("#parameter").val().trim()}, data: {parameter: $('#parameter').val().trim()},
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
$("#error").Popup("Instance parameters updated!", {type:'info', duration:3000}); $('#error').Popup('Instance parameters updated!', {type: 'info', duration: 3000});
} }
else{ else {
$("#error").Popup(data.result, {type:'error', duration:5000}); $('#error').Popup(data.result, {type: 'error', duration: 5000});
} }
} }
}); });
}); });
function loadFileContent(file){ function loadFileContent(file) {
$.ajax({ $.ajax({
type: "POST", type: 'POST',
url: $SCRIPT_ROOT + '/checkFileType', url: $SCRIPT_ROOT + '/checkFileType',
data: "path=" + file, data: 'path=' + file,
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
if (data.result=="text"){ if (data.result == 'text') {
$.ajax({ $.ajax({
type: "POST", type: 'POST',
url: $SCRIPT_ROOT + '/getFileContent', url: $SCRIPT_ROOT + '/getFileContent',
data: {file:file, truncate:1500}, data: {file: file, truncate: 1500},
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
$("#inline_content").empty(); $('#inline_content').empty();
$("#inline_content").append('<h2 style="color: #4c6172; font: 18px \'Helvetica Neue\', Helvetica, Arial, sans-serif;">Inspect Instance Content: ' + $('#inline_content').append('<h2 style="color: #4c6172; font: 18px \'Helvetica Neue\', Helvetica, Arial, sans-serif;">Inspect Instance Content: ' +
file +'</h2>'); file + '</h2>');
$("#inline_content").append('<br/><div class="main_content"><pre id="editor"></pre></div>'); $('#inline_content').append('<br/><div class="main_content"><pre id="editor"></pre></div>');
setupEditor(); setupEditor();
$(".inline").colorbox({inline:true, width: "847px", onComplete:function(){ $('.inline').colorbox({inline: true, width: '847px', onComplete: function() {
editor.getSession().setValue(data.result); editor.getSession().setValue(data.result);
}}); }});
$(".inline").click(); $('.inline').click();
} }
else{ else {
$("#error").Popup("Can not load your file, please make sure that you have selected a Software Release", {type:'alert', duration:5000}); $('#error').Popup('Can not load your file, please make sure that you have selected a Software Release', {type: 'alert', duration: 5000});
} }
} }
}); });
} }
else{ else {
//Can not displays binary file //Can not displays binary file
$("#error").Popup(data.result, {type:'alert', duration:5000}); $('#error').Popup(data.result, {type: 'alert', duration: 5000});
} }
} }
else{ else {
$("#error").Popup(data.result, {type:'alert', duration:5000}); $('#error').Popup(data.result, {type: 'alert', duration: 5000});
} }
} }
}); });
} }
function updateParameter() { function updateParameter() {
var xml = '<?xml version="1.0" encoding="utf-8"?>\n', var xml = '<?xml version="1.0" encoding="utf-8"?>\n',
software_type="", software_type = '',
software_type_input_value = $("input#software_type").val(); software_type_input_value = $('input#software_type').val();
if (software_type_input_value !== "" && software_type_input_value !== "Software Type here...") { if (software_type_input_value !== '' && software_type_input_value !== 'Software Type here...') {
software_type = +software_type_input_value; software_type = +software_type_input_value;
} }
xml +='<instance>\n'; xml += '<instance>\n';
var size = $("#partitionParameter > tbody > tr").length; var size = $('#partitionParameter > tbody > tr').length;
if(size > 1){ if (size > 1) {
for(var i=2; i<=size; i++){ for (var i = 2; i <= size; i++) {
if($("input#txt_"+i).val() != ""){ if ($('input#txt_' + i).val() != '') {
xml +='<parameter id="'+$("input#txt_"+i).val()+'">'+$("textarea#value_"+i).val()+'</parameter>\n'; xml += '<parameter id="' + $('input#txt_' + i).val() + '">' + $('textarea#value_' + i).val() + '</parameter>\n';
} }
} }
} }
xml +='</instance>\n'; xml += '</instance>\n';
$.ajax({ $.ajax({
type: "POST", type: 'POST',
url: $SCRIPT_ROOT + '/saveParameterXml', url: $SCRIPT_ROOT + '/saveParameterXml',
data: {software_type:software_type, parameter:xml}, data: {software_type: software_type, parameter: xml},
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
$("#error").Popup("Instance parameters has been updated, please run your instance now!", {type:'confirm', duration:5000}); $('#error').Popup('Instance parameters has been updated, please run your instance now!', {type: 'confirm', duration: 5000});
} }
else{ else {
$("#error").Popup(data.result, {type:'error', duration:5000}); $('#error').Popup(data.result, {type: 'error', duration: 5000});
} }
} }
}); });
} }
function setupTextarea($txt){ function setupTextarea($txt) {
var size = Number($txt.attr('id').split('_')[1]); var size = Number($txt.attr('id').split('_')[1]);
var hiddenDiv = $(document.createElement('div')), var hiddenDiv = $(document.createElement('div')),
content = null; content = null;
hiddenDiv.attr('id', 'div_'+size); hiddenDiv.attr('id', 'div_' + size);
hiddenDiv.addClass('hiddendiv'); hiddenDiv.addClass('hiddendiv');
$('div#parameterkw').append(hiddenDiv); $('div#parameterkw').append(hiddenDiv);
$txt.keyup(function() { $txt.keyup(function() {
content = $txt.val().replace(/\n/g, '<br>'); content = $txt.val().replace(/\n/g, '<br>');
hiddenDiv.html(content); hiddenDiv.html(content);
if(hiddenDiv.height() > $txt.height() && hiddenDiv.height() > 120){return} if (hiddenDiv.height() > $txt.height() && hiddenDiv.height() > 120) {return}
$txt.css('height', hiddenDiv.height()+"px"); $txt.css('height', hiddenDiv.height() + 'px');
}); });
} }
function loadParameter(){ function loadParameter() {
$.ajax({ $.ajax({
type: "GET", type: 'GET',
url: $SCRIPT_ROOT + '/getParameterXml/dict', url: $SCRIPT_ROOT + '/getParameterXml/dict',
success: function(data){ success: function(data) {
if(data.code == 1){ if (data.code == 1) {
var dict=data.result['instance']; var dict = data.result['instance'];
for (propertie in dict){ for (propertie in dict) {
$("#add_attribute").click(); $('#add_attribute').click();
var size = Number($("#partitionParameter > tbody > tr").last().attr('id').split('_')[1]); var size = Number($('#partitionParameter > tbody > tr').last().attr('id').split('_')[1]);
$("input#txt_"+size).val(propertie); $('input#txt_' + size).val(propertie);
$("textarea#value_"+size).val(dict[propertie]); $('textarea#value_' + size).val(dict[propertie]);
$("textarea#value_"+size).keyup(); $('textarea#value_' + size).keyup();
} }
} }
else{ else {
$("#error").Popup(data.result, {type:'error', duration:5000}); $('#error').Popup(data.result, {type: 'error', duration: 5000});
} }
} }
}); });
} }
function configRadio(){ function configRadio() {
$("#slappart li").each(function() { $('#slappart li').each(function() {
var $radio = $(this).find("input:radio"); var $radio = $(this).find('input:radio');
var boxselector = "#box" + $radio.attr('id'); var boxselector = '#box' + $radio.attr('id');
if($(this).hasClass('checked')){ if ($(this).hasClass('checked')) {
$(this).removeClass('checked'); $(this).removeClass('checked');
$(boxselector).slideUp("normal"); $(boxselector).slideUp('normal');
} }
if($radio.is(':checked')){ if ($radio.is(':checked')) {
$(this).addClass('checked'); $(this).addClass('checked');
//change content here //change content here
$(boxselector).slideDown("normal"); $(boxselector).slideDown('normal');
} }
}); });
} }
function setupBox(){ function setupBox() {
var state = $("#softwareType").css("display"); var state = $('#softwareType').css('display');
if (state == "none"){ if (state == 'none') {
$("#softwareType").slideDown("normal"); $('#softwareType').slideDown('normal');
$("#softwareTypeHead").removeClass("hide"); $('#softwareTypeHead').removeClass('hide');
$("#softwareTypeHead").addClass("show"); $('#softwareTypeHead').addClass('show');
} }
else{ else {
$("#softwareType").slideUp("normal"); $('#softwareType').slideUp('normal');
$("#softwareTypeHead").removeClass("show"); $('#softwareTypeHead').removeClass('show');
$("#softwareTypeHead").addClass("hide"); $('#softwareTypeHead').addClass('hide');
} }
} }
function setupEditor(editable){ function setupEditor(editable) {
editor = ace.edit("editor"); editor = ace.edit('editor');
editor.setTheme("ace/theme/crimson_editor"); editor.setTheme('ace/theme/crimson_editor');
var CurentMode = require("ace/mode/text").Mode; var CurentMode = require('ace/mode/text').Mode;
editor.getSession().setMode(new CurentMode()); editor.getSession().setMode(new CurentMode());
editor.getSession().setTabSize(2); editor.getSession().setTabSize(2);
editor.getSession().setUseSoftTabs(true); editor.getSession().setUseSoftTabs(true);
editor.renderer.setHScrollBarAlwaysVisible(false); editor.renderer.setHScrollBarAlwaysVisible(false);
if(!editable){editor.setReadOnly(true);} if (!editable) {editor.setReadOnly(true);}
} }
function setupSlappart(){ function setupSlappart() {
for(var i=0; i<partitionAmount; i++){ for (var i = 0; i < partitionAmount; i++) {
var elt = $("#slappart"+i+"Parameter"); var elt = $('#slappart' + i + 'Parameter');
var fileId = $("#slappart"+i+"Files"); var fileId = $('#slappart' + i + 'Files');
if(elt && elt != undefined) elt.click(function(){ if (elt && elt != undefined) elt.click(function() {
alert($(this).html()); alert($(this).html());
}); });
if(fileId && fileId != undefined) fileId.click(function(){ if (fileId && fileId != undefined) fileId.click(function() {
$("#instancetabfiles").click(); $('#instancetabfiles').click();
setupFileTree($(this).attr("rel")); setupFileTree($(this).attr('rel'));
}); });
} }
} }
}); });
\ No newline at end of file
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