Created
June 21, 2016 08:23
-
-
Save gregwiechec/e82d4457f33a311dbde6ddb524300188 to your computer and use it in GitHub Desktop.
Deleting single file from trash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using EPiServer.Cms.Shell.UI.Rest; | |
using EPiServer.Cms.Shell.UI.Rest.Models; | |
using EPiServer.Framework; | |
using EPiServer.Framework.Initialization; | |
using EPiServer.ServiceLocation; | |
using EPiServer.Shell.Rest; | |
namespace ContentAreaWithPreview.Business | |
{ | |
public class CustomUriContextResolver : IUriContextResolver, IUrlContextResolver | |
{ | |
private readonly CmsContentContextResolver _cmsContentContextResolver; | |
public string Name => this._cmsContentContextResolver.Name; | |
public int SortOrder => this._cmsContentContextResolver.SortOrder; | |
public CustomUriContextResolver(CmsContentContextResolver cmsContentContextResolver) | |
{ | |
_cmsContentContextResolver = cmsContentContextResolver; | |
} | |
public bool TryResolveUri(Uri uri, out ClientContextBase instance) | |
{ | |
var result = this._cmsContentContextResolver.TryResolveUri(uri, out instance); | |
AssignCustomTrashComponent(instance); | |
return result; | |
} | |
public bool TryResolveUrl(Uri url, out ClientContextBase instance) | |
{ | |
var result = this._cmsContentContextResolver.TryResolveUrl(url, out instance); | |
AssignCustomTrashComponent(instance); | |
return result; | |
} | |
private static void AssignCustomTrashComponent(ClientContextBase instance) | |
{ | |
if (instance != null) | |
{ | |
var contentDataContext = (ContentDataContext)instance; | |
if (contentDataContext.CustomViewType == "epi-cms/component/Trash") | |
{ | |
contentDataContext.CustomViewType = "customTrash/Trash"; | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web; | |
using EPiServer; | |
using EPiServer.Core; | |
using EPiServer.Framework; | |
using EPiServer.Shell.Services.Rest; | |
using EPiServer.Cms.Shell.UI.Rest.Models; | |
using EPiServer.Security; | |
namespace ContentAreaWithPreview.Business | |
{ | |
[RestStore("extendedWastebasket")] | |
public class ExtendedWasteBasketStore : RestControllerBase | |
{ | |
private readonly IContentLoader _contentLoader; | |
private readonly IContentRepository _contentRepository; | |
private readonly IContentProviderManager _contentProviderManager; | |
public ExtendedWasteBasketStore(IContentProviderManager contentProviderManager, IContentLoader contentLoader, | |
IContentRepository contentRepository) | |
{ | |
_contentProviderManager = contentProviderManager; | |
_contentLoader = contentLoader; | |
_contentRepository = contentRepository; | |
} | |
public RestResult PermanentDelete(ContentReference id) | |
{ | |
Validator.ThrowIfNull("id", id); | |
var content = this._contentLoader.Get<IContent>(id); | |
if (!this._contentProviderManager.IsWastebasket(content.ParentLink)) | |
{ | |
throw new HttpException(400, "Not a valid wastebasket."); | |
} | |
if (!content.QueryDistinctAccess(AccessLevel.Delete)) | |
{ | |
throw new HttpException(403, "You do not have access rights to empty this waste basket."); | |
} | |
var actionResponse = new ActionResponse<ContentReference> {ExtraInformation = content.ParentLink }; | |
this._contentRepository.Delete(id, true, AccessLevel.NoAccess); | |
return this.Rest(actionResponse); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<module> | |
<clientResources> | |
<add dependency="epi-cms.widgets.base" path="scripts/storeInitializer.js" resourceType="Script" /> | |
</clientResources> | |
<clientModule initializer="customTrash.storeInitializer"> | |
<moduleDependencies> | |
<add dependency="CMS" type="RunAfter" /> | |
</moduleDependencies> | |
</clientModule> | |
<dojo> | |
<paths> | |
<add name="customTrash" path="scripts" /> | |
</paths> | |
</dojo> | |
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
"dojo", | |
"dojo/_base/declare", | |
"epi/_Module", | |
"epi/dependency", | |
"epi/routes", | |
"epi/shell/store/JsonRest" | |
], function ( | |
dojo, | |
declare, | |
_Module, | |
dependency, | |
routes, | |
JsonRest | |
) { | |
return declare([_Module], { | |
initialize: function () { | |
this.inherited(arguments); | |
var registry = this.resolveDependency("epi.storeregistry"); | |
//Register store | |
registry.add("alloy.extendedWastebasket", | |
new JsonRest({ | |
target: this._getRestPath("extendedWastebasket"), | |
idProperty: "contentLink" | |
}) | |
); | |
}, | |
_getRestPath: function (name) { | |
return routes.getRestPath({ moduleArea: "App", storeName: name }); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.Sleek .epi-trash .epi-gridDeleteAction { | |
display: none; | |
float: right; | |
padding-right: 10px | |
} | |
.Sleek .epi-trash .dgrid-selected .epi-gridDeleteAction, | |
.Sleek .epi-trash .epi-dgrid-mouseover .epi-gridDeleteAction { | |
display: block; | |
cursor: pointer; | |
text-decoration: underline | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
"dojo/_base/declare", | |
"customTrash/TrashWidget", | |
"epi-cms/component/Trash" | |
], | |
function( | |
declare, | |
TrashWidget, | |
Trash | |
) { | |
return declare([Trash], { | |
templateString: "<div class=\"epi-trashComponent\"><div data-dojo-type='customTrash/TrashWidget' data-dojo-attach-point='trash'></div></div>" | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
"dojo/_base/declare", | |
"dojo/_base/lang", | |
"dojo/_base/array", | |
"dojo/_base/Deferred", | |
"dojo/topic", | |
"dijit/registry", | |
"epi", | |
"epi/dependency", | |
"epi-cms/widget/Trash", | |
"epi/shell/widget/dialog/Confirmation", | |
// Resources | |
"epi/i18n!epi/cms/nls/episerver.cms.components.trash", | |
"xstyle/css!./styles.css" | |
], | |
function( | |
declare, | |
lang, | |
array, | |
Deferred, | |
topic, | |
registry, | |
epi, | |
dependency, | |
Trash, | |
Confirmation, | |
resources | |
) { | |
return declare([Trash], { | |
_setQueryOptionsAttr: function() { | |
this.inherited(arguments); | |
var selectedTab = this.tabContainer.selectedChildWidget; | |
if (!selectedTab || !selectedTab.itemListId) { | |
return; | |
} | |
var trashItemListWidget = registry.byId(selectedTab.itemListId); | |
if (trashItemListWidget._isDeleteActionModified) { | |
return; | |
} | |
this._modifyActionColumn(trashItemListWidget); | |
var storeRegistry = dependency.resolve("epi.storeregistry"); | |
this._extendedWastebasketStore = storeRegistry.get("alloy.extendedWastebasket"); | |
this._initDeleteOnClick(trashItemListWidget); | |
trashItemListWidget._isDeleteActionModified = true; | |
}, | |
_craeteConfirmationDialog: function (row) { | |
return new Confirmation({ | |
title: "Delete", | |
description: lang.replace("Are you sure you want to permanently delete '{name}'", row.data), | |
onShow: lang.hitch(this, function() { | |
var trashItemList = this.tabContainer.selectedChildWidget.getChildren()[0]; | |
trashItemList.clearSelection(); | |
}) | |
}); | |
}, | |
_modifyActionColumn: function(trashItemListWidget) { | |
var actionFormatterFunc = trashItemListWidget._grid.columns.action.formatter; | |
function renderActionMenu(value) { | |
return actionFormatterFunc() + "<a class=\"epi-gridDeleteAction epi-visibleLink\">Delete permanently</a>"; | |
} | |
trashItemListWidget._grid.columns.action.formatter = renderActionMenu; | |
}, | |
_initDeleteOnClick: function (trashItemListWidget) { | |
trashItemListWidget._grid.on(".epi-gridDeleteAction:click", lang.hitch(this, function (evt) { | |
var row = trashItemListWidget._grid.row(evt); | |
var currentTrash = this.model.get("currentTrash"); | |
if (!row.data || !currentTrash) { | |
return; | |
} | |
var dialog = this._craeteConfirmationDialog(row); | |
dialog.connect(dialog, "onAction", lang.hitch(this, function (confirm) { | |
if (!confirm) { | |
return; | |
} | |
var contentId = row.data.contentLink; | |
Deferred.when(this._extendedWastebasketStore.executeMethod("PermanentDelete", contentId), lang.hitch(this, function (response) { | |
var trashes = this.model.get("trashes"); | |
// loop through all affected trashes, turn the isRequireLoad flag to true | |
array.forEach(trashes, lang.hitch(this, function (trash) { | |
if (response.extraInformation === trash.wasteBasketLink) { | |
//_this.model.updateTrash(trash); | |
trash.deletedByUsers = []; | |
trash.isRequireLoad = true; | |
trash.deletedByUsers = []; | |
this.model.set("currentTrash", trash); | |
} | |
})); | |
//this.model.isEmptyTrash = true; | |
//topic.publish("/epi/cms/trash/empty", response.extraInformation); | |
}), lang.hitch(this, function (response) { | |
if (response.status === 403) { | |
this.model.set("actionResponse", resources.emptytrash.accessdenied); | |
} | |
} | |
)); | |
})); | |
dialog.show(); | |
} | |
)); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using EPiServer.Cms.Shell.UI.Rest; | |
using EPiServer.Cms.Shell.UI.Rest.Models; | |
using EPiServer.Framework; | |
using EPiServer.Framework.Initialization; | |
using EPiServer.ServiceLocation; | |
using EPiServer.Shell.Rest; | |
namespace ContentAreaWithPreview.Business | |
{ | |
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))] | |
public class UriContextResolverInitializer : IConfigurableModule | |
{ | |
public void ConfigureContainer(ServiceConfigurationContext context) | |
{ | |
context.Services | |
.Intercept<IUriContextResolver>( | |
(locator, uriContextResolver) => | |
uriContextResolver is CmsContentContextResolver | |
? new CustomUriContextResolver((CmsContentContextResolver) uriContextResolver) | |
: uriContextResolver) | |
.Intercept<IUrlContextResolver>( | |
(locator, urlContextResolver) => | |
urlContextResolver is CmsContentContextResolver | |
? new CustomUriContextResolver((CmsContentContextResolver) urlContextResolver) | |
: urlContextResolver); | |
} | |
public void Initialize(InitializationEngine context) { } | |
public void Uninitialize(InitializationEngine context) { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment