From fd90bb4570d234e1936801e8261d07fa4a5990c8 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 4 Sep 2018 09:23:07 +0300 Subject: [PATCH] markdown for editing blog posts --- .../Pages/Blog/Posts/Edit.cshtml | 55 +++++++++++++---- .../Pages/Blog/Posts/Edit.cshtml.cs | 1 + .../Pages/Blog/Posts/Index.cshtml | 2 +- .../Pages/Blog/Posts/edit.js | 61 +++++++++++++++++++ .../Volo.Blogging.Web/Pages/Blog/Posts/new.js | 3 +- 5 files changed, 107 insertions(+), 15 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml index 5019e48bfd..a021f9101d 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml @@ -1,26 +1,57 @@ @page +@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Lodash +@using Volo.Abp.AspNetCore.Mvc.UI.Packages.TuiEditor @using Volo.Blogging.Pages.Blog.Posts @model EditModel @inherits Volo.Blogging.Pages.Blog.BloggingPage +@section styles { + + + + +} @section scripts { + + } -
- - - +
+ + + + + + + + +
+
+
+
+
+ +
+
+ +
+ @L["MarkdownSupported"] +
+ +
@L["FileUploadInfo"].Value
-
- - -
+
+
+ - - + @L["Cancel"] +
+
- - \ No newline at end of file + +
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs index 7a0072ca23..e2f0aab317 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs @@ -67,6 +67,7 @@ namespace Volo.Blogging.Pages.Blog.Posts [StringLength(PostConsts.MaxUrlLength)] public string Url { get; set; } + [HiddenInput] [StringLength(PostConsts.MaxContentLength)] public string Content { get; set; } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml index cdc04643bf..a8c01af63b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml @@ -22,7 +22,7 @@ } - + Create New Post
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js index 60fb760de1..e912f65528 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js @@ -1,4 +1,65 @@ (function ($) { + + var $container = $("#edit-post-container"); + var $editorContainer = $container.find(".edit-post-editor"); + var $submitButton = $container.find("button[type=submit]"); + var $form = $container.find("form#edit-post-form"); + var editorDataKey = "tuiEditor"; + + var uploadImage = function (file, callbackFn) { + var formData = new FormData(); + formData.append('file', file); + + $.ajax({ + type: "POST", + url: "", + data: formData, + contentType: false, + processData: false, + success: function (response) { + callbackFn(response.fileUrl); + } + }); + }; + + console.log($form.find("input[name='Post.Content']").val() + "asda"); + var newPostEditor = $editorContainer.tuiEditor({ + usageStatistics: false, + initialEditType: 'markdown', + previewStyle: 'tab', + height: "auto", + initialValue: $form.find("input[name='Post.Content']").val(), + hooks: { + addImageBlobHook: function (blob, callback, source) { + var imageAltText = blob.name; + + uploadImage(blob, + function (fileUrl) { + callback(fileUrl, imageAltText); + }); + } + }, + events: { + load: function () { + $editorContainer.find(".loading-cover").remove(); + $submitButton.prop("disabled", false); + } + } + }).data(editorDataKey); + + + + $container.find("form#edit-post-form").submit(function (e) { + var $postTextInput = $form.find("input[name='Post.Content']"); + + var postText = newPostEditor.getMarkdown(); + $postTextInput.val(postText); + console.log(postText); + + $submitButton.buttonBusy(); + $(this).off('submit').submit(); + }); + $('#Post_Title').on("change paste keyup", function() { var title = $('#Post_Title').val(); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js index 072e1eb0bb..5fd102ff28 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js @@ -4,6 +4,7 @@ var $container = $("#qa-new-post-container"); var $editorContainer = $container.find(".new-post-editor"); var $submitButton = $container.find("button[type=submit]"); + var $form = $container.find("form#new-post-form"); var editorDataKey = "tuiEditor"; var uploadImage = function (file, callbackFn) { @@ -48,12 +49,10 @@ $container.find("form#new-post-form").submit(function (e) { - var $form = $container.find("form#new-post-form"); var $postTextInput = $form.find("input[name='Post.Content']"); var postText = newPostEditor.getMarkdown(); $postTextInput.val(postText); - console.log(postText); $submitButton.buttonBusy(); $(this).off('submit').submit();