Adding Publish/Unpublish buttons to Media Actions view.

The Publish/Unpublish buttons appear only when the content type of the media item is set to Draftable.
This commit is contained in:
Sipke Schoorstra
2013-12-28 16:11:49 +01:00
parent 4ce3ee3226
commit b7dca6f998

View File

@@ -1,20 +1,34 @@
@using Orchard.ContentManagement
@using Orchard.Core.Contents;
@using Orchard.Core.Contents.Settings
@{
ContentItem contentItem = Model.ContentItem;
var draftable = contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable;
}
@if (Authorizer.Authorize(Permissions.EditContent, contentItem)) {
@Html.Link(T("Edit").Text, Url.ItemEditUrl(contentItem), new {@class = "button", id="edit-media-link"})
}
<div id="media-actions">
@if (Authorizer.Authorize(Permissions.EditContent, contentItem)) {
@Html.Link(T("Edit").Text, Url.ItemEditUrl(contentItem), new { @class = "button", id = "edit-media-link" })
}
@if (Authorizer.Authorize(Permissions.PublishContent, contentItem) && draftable) {
if (contentItem.HasPublished()) {
@Html.AntiForgeryTokenValueOrchardLink(T("Unpublish").Text, Url.Action("Unpublish", "Admin", new { Area = "Contents", contentItem.Id }), new { @class = "button", itemprop = "UnsafeUrl" })
}
else {
@Html.AntiForgeryTokenValueOrchardLink(T("Publish").Text, Url.Action("Publish", "Admin", new { Area = "Contents", contentItem.Id }), new { @class = "button", itemprop = "UnsafeUrl" })
}
}
</div>
<script type="text/javascript">
//<![CDATA[
// update the returnUrl from javascript to get the main window's location
$('#edit-media-link').each(function() {
$('#media-actions .button').each(function () {
var self = $(this);
var returnUrl = self.attr('href') + '?returnUrl=' + encodeURIComponent(window.location);
var href = self.attr('href');
var containsQueryString = href.indexOf("?") >= 0;
var returnUrl = href + (containsQueryString ? "&" : "?") + "returnUrl=" + encodeURIComponent(window.location);
self.attr('href', returnUrl);
});
//]]>
//]]>
</script>