#18100 : Various MediaPicker alert screens showing garbage (3 different failures)

--HG--
branch : 1.x
extra : transplant_source : k%A3%B7q%D0%3B%C4%F6%DCr%F02%8D%C2p%20K%C6J%AC
This commit is contained in:
blelem
2011-09-04 22:14:19 +03:00
parent 8ff576b67c
commit 6225a96138
4 changed files with 40 additions and 10 deletions

View File

@@ -37,15 +37,15 @@ namespace Orchard.MediaPicker.Controllers {
[HttpPost]
public JsonResult CreateFolder(string path, string folderName) {
if (!Services.Authorizer.Authorize(Permissions.ManageMedia)) {
return Json(T("Couldn't create media folder").ToString());
return Json(new { Success = false, Message = T("Couldn't create media folder").ToString() });
}
try {
_mediaService.CreateFolder(HttpUtility.UrlDecode(path), folderName);
return Json(true);
return Json(new { Success = true, Message = "" });
}
catch (Exception exception) {
return Json(T("Creating Folder failed: {0}", exception.Message).ToString());
return Json(new { Success = false, Message = T("Creating Folder failed: {0}", exception.Message).ToString()} );
}
}
}

View File

@@ -45,17 +45,26 @@
});
$("#createFolder").live("click", function () {
if ($(this).hasClass("disabled")) return;
$.post("MediaPicker/CreateFolder", { path: query("mediaPath") || "", folderName: $("#folderName").val(), __RequestVerificationToken: $("#__requesttoken").val() },
function (response) {
if (typeof response === "string") {
alert(response);
}
else {
if (response.Success == true) {
location.reload(true);
} else if (response.Success == false) {
alert(response.Message);
} else {
// Most likely a redirection due to expired authorisation
alert($("#AccessDeniedMsg").val());
var loginWindow = window.open($("#LoginUrl").val(), "AccessDenied", 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
});
});
$("#folderName").live("propertychange keyup input paste", function () {
var empty = ($("#folderName").val() == "");
$("#createFolder").attr("disabled", empty).toggleClass("disabled", empty);
});
$(function () {
$("#tabs").tabs({
selected: parseInt(query("tab", location.hash)) || 0,
@@ -101,8 +110,15 @@
});
}
var data = window.opener.jQuery[query("callback")].data,
try {
var data = window.opener.jQuery[query("callback")].data,
img = data ? data.img : null;
}
catch (ex) {
alert($("#LostCallbackMsg").val());
window.close();
}
if (img) {
for (var name in img) {
$("#img-" + name).val(img[name]);
@@ -140,7 +156,12 @@
height: $(prefix + "height").val()
};
img.html = getImageHtml(img);
window.opener.jQuery[query("callback")]({ img: img });
try {
window.opener.jQuery[query("callback")]({ img: img });
}
catch (ex) {
alert($("#LostCallbackMsg").val());
}
window.close();
}
@@ -274,6 +295,10 @@
else if (result && result.error) {
alert(result.error);
}
else if (frame.location.pathname.match("AccessDenied")) {
alert($("#AccessDeniedMsg").val());
window.open($("#LoginUrl").val(), "AccessDenied", 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
else {
var somethingPotentiallyHorrible = "";
try {

View File

@@ -29,6 +29,11 @@
</head>
<body id="orchardmediapicker">
<form id="ErrorHandlingValues">
<input type="hidden" id="LostCallbackMsg" value="@T("Cannot perform requested operation")" />
<input type="hidden" id="AccessDeniedMsg" value="@T("Authentification timed-out: please log-on again")" />
<input type="hidden" id="LoginUrl" value="@Url.Action("LogIn", new { Controller = "Account", Area = "Orchard.Users" })" />
</form>
<div id="tabs" class="group">
<ul>
<li><a href="#tab-url" data-edittext="@T("Update/Upload Image")" data-edittext-content="true">@T("Insert/Upload Image")</a></li>

View File

@@ -28,7 +28,7 @@
<fieldset>
<input id="__requesttoken" type="hidden" value="@Html.AntiForgeryTokenValueOrchard()" />
<input class="text-box" id="folderName" type="text" />
<input class="button" type="button" id="createFolder" value="@T("Create Folder")" />
<input class="button disabled" type="button" id="createFolder" value="@T("Create Folder")" />
</fieldset>
</div>
<fieldset>