new UI - template page - implement add template

This commit is contained in:
Jessica Wang 2010-09-16 20:13:07 -07:00
parent 221c8fb059
commit 135f131270
4 changed files with 67 additions and 29 deletions

View File

@ -59,19 +59,8 @@ $(document).ready(function() {
for(var i=0; i<items.length;i++) {
var $midmenuItem1 = $midmenuItem.clone();
$midmenuItem1.data("toRightPanelFn", toRightPanel);
toMidmenu(items[i], $midmenuItem1);
$midmenuItem1.bind("click", function(event){
var thisMidmenuItem = $(this);
if(selected_midmenu_id != null && selected_midmenu_id.length > 0)
$("#"+selected_midmenu_id).find("#content").removeClass("selected");
selected_midmenu_id = ("midmenuItem_"+thisMidmenuItem.data("jsonObj").id);
thisMidmenuItem.find("#content").addClass("selected");
clearRightPanel();
toRightPanel(thisMidmenuItem);
return false;
});
toMidmenu(items[i], $midmenuItem1);
bindClickToMidMenu($midmenuItem1, toRightPanel);
$("#midmenu_container").append($midmenuItem1.show());
}
}

View File

@ -1218,8 +1218,7 @@ function clickInstanceGroupHeader($arrowIcon) {
} else if (result.jobstatus == 2) {
// Failed
afterAddingMidMenuItem($midmenuItem1, false);
$("#dialog_error").html("<p><b>Adding Instance failed</b></p><br/><p>"+fromdb(result.jobresult)+"</p>").dialog("open");
afterAddingMidMenuItem($midmenuItem1, false, fromdb(result.jobresult));
}
}
},

View File

@ -563,7 +563,7 @@ function beforeAddingMidMenuItem() {
$("#midmenu_container").append($midmenuItem1.show());
return $midmenuItem1;
}
function afterAddingMidMenuItem($midmenuItem1, isSuccessful) {
function afterAddingMidMenuItem($midmenuItem1, isSuccessful, extraMessage) {
$midmenuItem1.find("#content").removeClass("inaction");
$midmenuItem1.find("#spinning_wheel").hide();
@ -574,9 +574,40 @@ function afterAddingMidMenuItem($midmenuItem1, isSuccessful) {
else {
$midmenuItem1.find("#info_icon").addClass("error").show();
$midmenuItem1.find("#first_row").text("Adding failed");
if(extraMessage != null)
$midmenuItem1.find("#second_row").text(extraMessage);
}
}
function bindClickToMidMenu($midmenuItem1, toRightPanel) {
$midmenuItem1.bind("click", function(event){
var thisMidmenuItem = $(this);
if(selected_midmenu_id != null && selected_midmenu_id.length > 0)
$("#"+selected_midmenu_id).find("#content").removeClass("selected");
selected_midmenu_id = ("midmenuItem_"+thisMidmenuItem.data("jsonObj").id);
thisMidmenuItem.find("#content").addClass("selected");
clearRightPanel();
toRightPanel(thisMidmenuItem);
return false;
});
}

View File

@ -4,16 +4,27 @@ var g_zoneNames = [];
function afterLoadTemplateJSP() {
var $detailsTab = $("#right_panel_content #tab_content_details");
//add button ***
//add button ***
var formatSelect = $("#dialog_add_template #add_template_format").empty();
if (getHypervisorType() == "kvm")
formatSelect.append("<option value='QCOW2'>QCOW2</option>");
else if (getHypervisorType() == "xenserver")
formatSelect.append("<option value='VHD'>VHD</option>");
if(isAdmin())
$("#dialog_add_template #add_template_featured_container, #dialog_edit_template #edit_template_featured_container").show();
else
$("#dialog_add_template #add_template_featured_container, #dialog_edit_template #edit_template_featured_container").hide();
$("#midmenu_add_link").show();
$("#midmenu_add_link").bind("click", function(event) {
$("#dialog_add_template")
.dialog('option', 'buttons', {
"Create": function() {
var thisDialog = $(this);
thisDialog.dialog("close");
debugger;
// validate values
var isValid = true;
isValid &= validateString("Name", thisDialog.find("#add_template_name"), thisDialog.find("#add_template_name_errormsg"));
@ -36,20 +47,28 @@ function afterLoadTemplateJSP() {
moreCriteria.push("&isfeatured="+isFeatured);
}
//middle menu spinning wheel....
var $midmenuItem1 = beforeAddingMidMenuItem() ;
$.ajax({
data: createURL("command=registerTemplate&name="+encodeURIComponent(name)+"&displayText="+encodeURIComponent(desc)+"&url="+encodeURIComponent(url)+"&zoneid="+zoneId+"&ispublic="+isPublic+moreCriteria.join("")+"&format="+format+"&passwordEnabled="+password+"&osTypeId="+osType+"&response=json"),
dataType: "json",
success: function(json) {
var result = json.registertemplateresponse;
debugger;
//spinning wheel disappear
},
error: function(XMLHttpResponse) {
debugger;
}
success: function(json) {
var result = json.registertemplateresponse;
templateToMidmenu(result.template[0], $midmenuItem1);
bindClickToMidMenu($midmenuItem1, templateToRigntPanel);
/*
if(result.template.length > 1) {
for(var i=1; i<result.template.length; i++) {
var template2 = $("#vm_template_template").clone(true);
templateJSONToTemplate(result.template[i], template2);
submenuContent.find("#grid_content").prepend(template2.fadeIn("slow"));
changeGridRowsTotal(submenuContent.find("#grid_rows_total"), 1);
}
}
*/
afterAddingMidMenuItem($midmenuItem1, true);
}
});
},
"Cancel": function() {