This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge changes from the release branch before release beta2.
- Loading branch information
Showing
12 changed files
with
333 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using SenseNet.Portal.UI.PortletFramework; | ||
using System.Web.UI.WebControls.WebParts; | ||
|
||
namespace SenseNet.Portal.Portlets | ||
{ | ||
public class DialogFileUploadPortlet : ContextBoundPortlet | ||
{ | ||
private const string DialogFileUploadPortletClass = "DialogFileUploadPortlet"; | ||
private const string VIEWPATH = "/Root/System/SystemPlugins/Controls/DialogFileUpload.ascx"; | ||
|
||
[WebBrowsable(true), Personalizable(true)] | ||
[LocalizedWebDisplayName(DialogFileUploadPortletClass, "Prop_AllowedContentTypes_DisplayName")] | ||
[LocalizedWebDescription(DialogFileUploadPortletClass, "Prop_AllowedContentTypes_Description")] | ||
[WebCategory("Dialog File Upload", 100)] | ||
[WebOrder(100)] | ||
public string AllowedContentTypes { get; set; } | ||
|
||
public DialogFileUploadPortlet() | ||
{ | ||
this.Name = "$DialogFileUploadPortlet:PortletDisplayName"; | ||
this.Description = "$DialogFileUploadPortlet:PortletDescription"; | ||
this.Category = new PortletCategory(PortletCategoryType.Application); | ||
} | ||
|
||
protected override void OnInit(EventArgs e) | ||
{ | ||
var control = this.Page.LoadControl(VIEWPATH) as UI.Controls.DialogFileUpload; | ||
if (control != null) | ||
{ | ||
control.AllowedContentTypes = this.AllowedContentTypes; | ||
this.Controls.Add(control); | ||
} | ||
|
||
base.OnInit(e); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web.UI; | ||
using System.Web.UI.WebControls; | ||
using SenseNet.ContentRepository.Storage; | ||
using SenseNet.ContentRepository; | ||
using SenseNet.Portal.Virtualization; | ||
using SenseNet.Portal.Handlers; | ||
using System.Web; | ||
using SenseNet.ContentRepository.Storage.Security; | ||
using SenseNet.ContentRepository.Schema; | ||
|
||
namespace SenseNet.Portal.UI.Controls | ||
{ | ||
[Serializable] | ||
internal class FileListElement | ||
{ | ||
public string Path { get; set; } | ||
public string FileName { get; set; } | ||
} | ||
|
||
public class DialogFileUpload : UserControl | ||
{ | ||
// ==================================================================================== Properties | ||
public string AllowedContentTypes { get; set; } | ||
|
||
|
||
// ==================================================================================== Members | ||
private List<FileListElement> _fileListElements; | ||
|
||
private List<ContentType> AllowedContentTypesList => string.IsNullOrEmpty(AllowedContentTypes) | ||
? null | ||
: AllowedContentTypes | ||
.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries) | ||
.Select(ContentType.GetByName).ToList(); | ||
|
||
|
||
// ==================================================================================== Controls | ||
private FileUpload Upload | ||
{ | ||
get | ||
{ | ||
return this.FindControlRecursive("Upload") as FileUpload; | ||
} | ||
} | ||
private Repeater UploadedFiles | ||
{ | ||
get | ||
{ | ||
return this.FindControlRecursive("UploadedFiles") as Repeater; | ||
} | ||
} | ||
private PlaceHolder ErrorPlaceHolder | ||
{ | ||
get | ||
{ | ||
return this.FindControlRecursive("ErrorPlaceHolder") as PlaceHolder; | ||
} | ||
} | ||
private Label ErrorLabel | ||
{ | ||
get | ||
{ | ||
return this.FindControlRecursive("ErrorLabel") as Label; | ||
} | ||
} | ||
|
||
|
||
// ==================================================================================== Methods | ||
protected override void LoadControlState(object savedState) | ||
{ | ||
var state = (object[])savedState; | ||
_fileListElements = state[0] as List<FileListElement>; | ||
base.LoadControlState(state[1]); | ||
} | ||
protected override object SaveControlState() | ||
{ | ||
return new[] { | ||
_fileListElements, | ||
base.SaveControlState() | ||
}; | ||
} | ||
protected override void OnInit(EventArgs e) | ||
{ | ||
base.OnInit(e); | ||
this.Page.RegisterRequiresControlState(this); | ||
} | ||
protected override void CreateChildControls() | ||
{ | ||
ErrorPlaceHolder.Visible = false; | ||
|
||
if (Upload.HasFile) | ||
{ | ||
try | ||
{ | ||
this.SaveFile(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
ErrorLabel.Text = ex.Message; | ||
ErrorPlaceHolder.Visible = true; | ||
} | ||
} | ||
|
||
UploadedFiles.DataSource = _fileListElements; | ||
UploadedFiles.ItemDataBound += new RepeaterItemEventHandler(UploadedFiles_ItemDataBound); | ||
UploadedFiles.DataBind(); | ||
} | ||
private void SaveFile() | ||
{ | ||
// get target container | ||
var container = PortalContext.Current.ContextNode as GenericContent; | ||
var targetFolderName = HttpContext.Current.Request["TargetFolder"]; | ||
if (!string.IsNullOrEmpty(targetFolderName)) | ||
{ | ||
var containerPath = RepositoryPath.Combine(container?.Path, targetFolderName); | ||
container = Node.LoadNode(containerPath) as GenericContent; | ||
|
||
// create target container if does not exist | ||
if (container == null) | ||
{ | ||
using (new SystemAccount()) | ||
{ | ||
container = new Folder(PortalContext.Current.ContextNode) | ||
{ | ||
Name = targetFolderName, | ||
AllowedChildTypes = AllowedContentTypesList | ||
}; | ||
container.Save(); | ||
} | ||
} | ||
} | ||
|
||
var contentTypeName = UploadHelper.GetContentType(Upload.PostedFile.FileName, container?.Path) ?? typeof(File).Name; | ||
if (container != null && container.GetAllowedChildTypeNames().Any(ctn => ctn == contentTypeName)) | ||
{ | ||
var binaryData = UploadHelper.CreateBinaryData(Upload.PostedFile); | ||
var fileName = binaryData.FileName.ToString(); | ||
|
||
var content = ContentRepository.Content.CreateNew(contentTypeName, container, fileName); | ||
|
||
// Uploaded files of different users go to the same folder. | ||
// Avoid collision, do not overwrite each others' files. | ||
content.ContentHandler.AllowIncrementalNaming = true; | ||
|
||
content["Name"] = fileName; | ||
content.Fields["Binary"].SetData(binaryData); | ||
content.Save(); | ||
|
||
// display uploaded file in repeater | ||
if (_fileListElements == null) | ||
_fileListElements = new List<FileListElement>(); | ||
|
||
_fileListElements.Add(new FileListElement { FileName = content.Name, Path = content.Path }); | ||
} | ||
else | ||
{ | ||
ErrorLabel.Text = "This type cannot be uploaded!"; | ||
ErrorPlaceHolder.Visible = true; | ||
} | ||
} | ||
|
||
private void UploadedFiles_ItemDataBound(object sender, RepeaterItemEventArgs e) | ||
{ | ||
var button = e.Item.FindControlRecursive("DeleteFile") as Button; | ||
if (button != null) | ||
button.Click += DeleteFileButton_Click; | ||
} | ||
|
||
private void DeleteFileButton_Click(object sender, EventArgs e) | ||
{ | ||
var button = sender as Button; | ||
var path = button?.CommandName ?? string.Empty; | ||
|
||
var node = Node.LoadNode(path); | ||
if (node == null) | ||
{ | ||
ErrorLabel.Text = "Cannot find content!"; | ||
ErrorPlaceHolder.Visible = true; | ||
return; | ||
} | ||
|
||
// check: was this file uploaded by me? if yes, delete. Otherwise don't allow delete. | ||
if (node.CreatedById == User.Current.Id) | ||
{ | ||
Node.ForceDelete(path); | ||
|
||
_fileListElements = _fileListElements.Where(a => a.Path != path).ToList(); | ||
if (_fileListElements.Count == 0) | ||
_fileListElements = null; | ||
|
||
UploadedFiles.DataSource = _fileListElements; | ||
UploadedFiles.DataBind(); | ||
} | ||
else | ||
{ | ||
ErrorLabel.Text = "This content cannot be deleted since it was created by another user!"; | ||
ErrorPlaceHolder.Visible = true; | ||
} | ||
} | ||
} | ||
} |
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
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
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
16 changes: 16 additions & 0 deletions
16
src/nuget/snadmin/install-webpages/import/(apps)/Folder/IFrameUpload.Content
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ContentMetaData> | ||
<ContentType>Page</ContentType> | ||
<ContentName>IFrameUpload</ContentName> | ||
<Fields> | ||
<PageTemplateNode> | ||
<Path>/Root/Global/pagetemplates/sn-iframedialogupload.html</Path> | ||
</PageTemplateNode> | ||
<PersonalizationSettings attachment="IFrameUpload.PersonalizationSettings" /> | ||
<DisplayName><![CDATA[$Action,IFrameUpload]]></DisplayName> | ||
<Icon><![CDATA[application]]></Icon> | ||
</Fields> | ||
<Permissions> | ||
<Clear /> | ||
</Permissions> | ||
</ContentMetaData> |
Empty file.
28 changes: 28 additions & 0 deletions
28
src/nuget/snadmin/install-webpages/import/Global/pagetemplates/sn-iframedialogupload.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<% string snLang = SenseNet.Portal.Virtualization.PortalContext.Current?.Site?.Language ?? "en-us"; %> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" lang="<%=snLang%>" xml:lang="<%=snLang%>"> | ||
<head> | ||
<title><% = (SenseNet.Portal.Virtualization.PortalContext.Current.Workspace != null) ? SenseNet.ContentRepository.Content.Create(SenseNet.Portal.Virtualization.PortalContext.Current.Workspace).DisplayName : "Sense/Net" %></title> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<meta http-equiv="imagetoolbar" content="no" /> | ||
<sn:BaseTag ID="BaseTagControl1" runat="server" /> | ||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> | ||
</head> | ||
|
||
<body class="sn-body" style="min-width:0; background:0;"> | ||
<% string snLang = SenseNet.Portal.Virtualization.PortalContext.Current?.Site?.Language ?? "en-us"; %> | ||
|
||
<sn:CssRequest CSSPath="$skin/styles/jqueryui/jquery-ui.css" ID="pageTemplateUIStyleReq" runat="server" /> | ||
<sn:CssRequest CSSPath="$skin/styles/jqueryui/jquery-ui-sntheme.css" ID="pageTemplateUIStyleReq2" runat="server" /> | ||
<sn:CssRequest CSSPath="$skin/styles/sn-layout.css" ID="snLayoutCss" runat="server" /> | ||
<sn:CssRequest CSSPath="$skin/styles/skin.css" ID="pageTemplateCssRequest1" runat="server" /> | ||
|
||
<div class="sn-layout-full ui-helper-clearfix" style="margin-top:20px;"> | ||
<snpe:DialogFileUploadPortlet ID="portlet" runat="server" AllowedContentTypes="Image" /> | ||
</div> | ||
|
||
<!-- prc --> | ||
<sn:ScriptRequest runat="server" Path="$skin/scripts/init.js" /> | ||
</body> | ||
</html> |
12 changes: 12 additions & 0 deletions
12
...t/snadmin/install-webpages/import/Global/pagetemplates/sn-iframedialogupload.html.Content
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ContentMetaData> | ||
<ContentType>PageTemplate</ContentType> | ||
<ContentName>sn-iframedialogupload.html</ContentName> | ||
<Fields> | ||
<Binary attachment="sn-iframedialogupload.html" /> | ||
<DisplayName>sn-iframedialogupload.html</DisplayName> | ||
</Fields> | ||
<Permissions> | ||
<Clear /> | ||
</Permissions> | ||
</ContentMetaData> |
Oops, something went wrong.