csharp: added the ability to Create New from templates for user "John Smith"

This commit is contained in:
metoou
2021-06-08 12:56:47 +03:00
committed by Sergey Linnik
parent b9e70b913a
commit c3fa000cea
3 changed files with 63 additions and 21 deletions

View File

@ -64,10 +64,10 @@ namespace OnlineEditorsExample
protected string History { get; private set; }
protected string HistoryData { get; private set; }
protected string InsertImageConfig { get; private set; }
protected string compareFileData { get; private set; }
protected string dataMailMergeRecipients { get; private set; }
protected string usersForMentions { get; private set; }
protected string documentType { get { return _Default.DocumentType(FileName); } }
protected string CompareFileData { get; private set; }
protected string DataMailMergeRecipients { get; private set; }
protected string UsersForMentions { get; private set; }
protected string DocumentType { get { return _Default.DocumentType(FileName); } }
// get callback url
public static string CallbackUrl
@ -161,11 +161,29 @@ namespace OnlineEditorsExample
var actionLink = Request.GetOrDefault("actionLink", null); // get the action link (comment or bookmark) if it exists
var actionData = string.IsNullOrEmpty(actionLink) ? null : jss.DeserializeObject(actionLink); // get action data for the action link
var createUrl = getCreateUrl(DocumentType, editorsType);
var templatesImageUrl = GetTemplateImageUrl(ext); // image url for templates
var templates = new List<Dictionary<string, string>>
{
new Dictionary<string, string>()
{
{ "image", templatesImageUrl },
{ "title", "Blank" },
{ "url", createUrl }
},
new Dictionary<string, string>()
{
{ "image", templatesImageUrl },
{ "title", "With sample content" },
{ "url", createUrl + "&sample=true" }
}
};
// specify the document config
var config = new Dictionary<string, object>
{
{ "type", editorsType },
{ "documentType", documentType },
{ "documentType", DocumentType },
{
"document", new Dictionary<string, object>
{
@ -206,7 +224,8 @@ namespace OnlineEditorsExample
{ "mode", mode },
{ "lang", Request.Cookies.GetOrDefault("ulang", "en") },
{ "callbackUrl", CallbackUrl }, // absolute URL to the document storage service
{ "createUrl", getCreateUrl(documentType, editorsType)},
{ "createUrl", !user.id.Equals("uid-0") ? createUrl : null },
{ "templates", user.templates ? templates : null },
{
// the user currently viewing or editing the document
"user", new Dictionary<string, object>
@ -264,15 +283,15 @@ namespace OnlineEditorsExample
// a document which will be compared with the current document
Dictionary<string, object> compareFile = GetCompareFile();
compareFileData = jss.Serialize(compareFile);
CompareFileData = jss.Serialize(compareFile);
// recipient data for mail merging
Dictionary<string, object> mailMergeConfig = GetMailMergeConfig();
dataMailMergeRecipients = jss.Serialize(mailMergeConfig);
DataMailMergeRecipients = jss.Serialize(mailMergeConfig);
// get users for mentions
List<Dictionary<string, object>> usersData = Users.getUsersForMentions(user.id);
usersForMentions = !user.id.Equals("uid-0") ? jss.Serialize(usersData) : null;
UsersForMentions = !user.id.Equals("uid-0") ? jss.Serialize(usersData) : null;
Dictionary<string, object> hist;
Dictionary<string, object> histData;
@ -451,6 +470,28 @@ namespace OnlineEditorsExample
return mailMergeConfig;
}
// get image url for templates
private string GetTemplateImageUrl (string ext)
{
var path = new UriBuilder(_Default.GetServerUrl(true)) // templates image url in the "From Template" section
{
Path = HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "App_Themes\\images\\"
};
switch (ext)
{
case ".docx":
return path + "file_docx.svg"; // for word document type
case ".xlsx":
return path + "file_xlsx.svg"; // .xlsx for cell document type
case ".pptx":
return path + "file_pptx.svg"; // .pptx for slide document type
default:
return path + "file_docx.svg"; // the default value
}
}
// create the public url
private string MakePublicUrl(string fullPath)
{