diff --git a/ui/jsp/resource.jsp b/ui/jsp/resource.jsp
index f6b0a527137..67e1f28e82b 100644
--- a/ui/jsp/resource.jsp
+++ b/ui/jsp/resource.jsp
@@ -96,7 +96,7 @@
-
+
diff --git a/ui/scripts/cloud.core.js b/ui/scripts/cloud.core.js
index 59c8449f73c..0691a9de6d5 100644
--- a/ui/scripts/cloud.core.js
+++ b/ui/scripts/cloud.core.js
@@ -1527,7 +1527,7 @@ function validateNumber(label, field, errMsgField, min, max, isOptional) {
return isValid;
}
-function validateString(label, field, errMsgField, isOptional) {
+function validateString(label, field, errMsgField, isOptional, maxLength) {
var isValid = true;
var errMsg = "";
var value = field.val();
@@ -1535,8 +1535,8 @@ function validateString(label, field, errMsgField, isOptional) {
errMsg = label + " is a required value. ";
isValid = false;
}
- else if (value!=null && value.length >= 255) {
- errMsg = label + " must be less than 255 characters";
+ else if (value!=null && value.length >= maxLength) {
+ errMsg = label + " must be less than " + maxLength + " characters";
isValid = false;
}
else if(value!=null && value.indexOf('"')!=-1) {
diff --git a/ui/scripts/cloud.core.resource.js b/ui/scripts/cloud.core.resource.js
index 4417dec17a5..f37f21dd533 100644
--- a/ui/scripts/cloud.core.resource.js
+++ b/ui/scripts/cloud.core.resource.js
@@ -295,7 +295,7 @@ function afterLoadResourceJSP($midmenuItem1) {
initAddZoneButton($("#midmenu_add_link"));
initUpdateConsoleCertButton($("#midmenu_add2_link"));
initDialog("dialog_add_zone");
- initDialog("dialog_update_cert", 550);
+ initDialog("dialog_update_cert", 450);
}
function initUpdateConsoleCertButton($midMenuAddLink2) {
@@ -308,15 +308,62 @@ function initUpdateConsoleCertButton($midMenuAddLink2) {
.dialog('option', 'buttons', {
"Add": function() {
var $thisDialog = $(this);
+ var isValid = true;
+ isValid &= validateString("SSL Certificate", $thisDialog.find("#update_cert"), $thisDialog.find("#update_cert_errormsg"), false, 4096);
+ if (!isValid) return;
+
+ $spinningWheel = $thisDialog.find("#spinning_wheel").show();
- $thisDialog.dialog("close");
+ var cert = trim($thisDialog.find("#update_cert").val());
+
+ $.ajax({
+ data: createURL("command=uploadCustomCertificate&certificate="+encodeURIComponent(cert)),
+ dataType: "json",
+ success: function(json) {
+ var jobId = json.uploadcustomcertificateresponse.jobid;
+ var timerKey = "asyncJob_" + jobId;
+ $("body").everyTime(
+ 5000,
+ timerKey,
+ function() {
+ $.ajax({
+ data: createURL("command=queryAsyncJobResult&jobId="+jobId),
+ dataType: "json",
+ success: function(json) {
+ var result = json.queryasyncjobresultresponse;
+ if (result.jobstatus == 0) {
+ return; //Job has not completed
+ } else {
+ $("body").stopTime(timerKey);
+ $spinningWheel.hide();
+
+ if (result.jobstatus == 1) { // Succeeded
+ $thisDialog.dialog("close");
+ // TODO: Add a confirmation message
+ } else if (result.jobstatus == 2) { // Failed
+ var errorMsg = result.jobresult.uploadcustomcertificateresponse.errortext;
+ $thisDialog.find("#info_container").text(errorMsg).show();
+ }
+ }
+ },
+ error: function(XMLHttpResponse) {
+ $("body").stopTime(timerKey);
+ handleErrorInDialog(XMLHttpResponse, $thisDialog);
+ }
+ });
+ },
+ 0
+ );
+ },
+ error: function(XMLHttpResponse) {
+ handleErrorInDialog(XMLHttpResponse, $thisDialog);
+ }
+ });
},
"Cancel": function() {
var $thisDialog = $(this);
-
$thisDialog.dialog("close");
}
-
}).dialog("open");
return false;
});
@@ -348,7 +395,7 @@ function initAddZoneButton($midmenuAddLink1) {
if (!isValid)
return;
- $thisDialog.find("#spinning_wheel").show()
+ $thisDialog.find("#spinning_wheel").show();
var moreCriteria = [];