|
|
|
@ -8,15 +8,15 @@ |
|
|
|
var $titleClone = $('#title-clone'); |
|
|
|
var $slug = $('#ViewModel_Slug'); |
|
|
|
var $buttonSubmit = $('#button-blog-post-update'); |
|
|
|
var $contentValueInput = $('#ViewModel_Value'); |
|
|
|
var $blogPostIdInput = $('#Id'); |
|
|
|
var $contentIdInput = $('#ViewModel_Id'); |
|
|
|
var $tagsInput = $('.tag-editor-form input[name=tags]'); |
|
|
|
var $fileInput = $('#BlogPostCoverImage'); |
|
|
|
|
|
|
|
var UPPY_UPLOAD_ENDPOINT = "/api/cms-kit-admin/blogs/blog-posts/{0}/cover-image"; |
|
|
|
var UPPY_FILE_ID = "uppy-upload-file"; |
|
|
|
|
|
|
|
var isTagsEnabled = true; |
|
|
|
|
|
|
|
$formUpdate.data('validator').settings.ignore = ":hidden, [contenteditable='true']:not([name]), .tui-popup-wrapper"; |
|
|
|
|
|
|
|
function initSelectBlog() { |
|
|
|
@ -40,7 +40,12 @@ |
|
|
|
|
|
|
|
$formUpdate.ajaxSubmit({ |
|
|
|
success: function (result) { |
|
|
|
submitEntityContent(); |
|
|
|
if (isTagsEnabled) { |
|
|
|
submitEntityTags($blogPostIdInput.val()); |
|
|
|
} |
|
|
|
else { |
|
|
|
submitCoverImage($blogPostIdInput.val()); |
|
|
|
} |
|
|
|
}, |
|
|
|
error: function (result) { |
|
|
|
abp.ui.clearBusy(); abp.notify.error(result.responseJSON.error.message); |
|
|
|
@ -53,49 +58,16 @@ |
|
|
|
e.preventDefault(); |
|
|
|
$formUpdate.submit(); |
|
|
|
}); |
|
|
|
|
|
|
|
function submitEntityTags(blogPostId) { |
|
|
|
|
|
|
|
function submitEntityContent() { |
|
|
|
|
|
|
|
var contentId = $contentIdInput.val(); |
|
|
|
var blogPostId = $blogPostIdInput.val(); |
|
|
|
var contentValue = $contentValueInput.val(); |
|
|
|
|
|
|
|
if (contentId) { |
|
|
|
volo.cmsKit.admin.contents.contentAdmin |
|
|
|
.update(contentId, |
|
|
|
{ |
|
|
|
value: contentValue |
|
|
|
}) |
|
|
|
.then(function (result) { |
|
|
|
entityContentCallback(blogPostId); |
|
|
|
}); |
|
|
|
} |
|
|
|
else { |
|
|
|
volo.cmsKit.admin.contents.contentAdmin |
|
|
|
.create({ |
|
|
|
entityType: 'BlogPost', |
|
|
|
entityId: blogPostId, |
|
|
|
value: contentValue |
|
|
|
}) |
|
|
|
.then(function (result) { |
|
|
|
entityContentCallback(blogPostId); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
var tags = $tagsInput.val().split(',').map(x => x.trim()).filter(x => x); |
|
|
|
|
|
|
|
function entityContentCallback(blogPostId) { |
|
|
|
if ($tagsInput.val()) { |
|
|
|
submitEntityTags(blogPostId); |
|
|
|
} |
|
|
|
else { |
|
|
|
if(tags.length === 0){ |
|
|
|
submitCoverImage(blogPostId); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function submitEntityTags(blogPostId) { |
|
|
|
|
|
|
|
var tags = $tagsInput.val().split(","); |
|
|
|
|
|
|
|
|
|
|
|
volo.cmsKit.admin.tags.entityTagAdmin |
|
|
|
.setEntityTags({ |
|
|
|
entityType: 'BlogPost', |
|
|
|
@ -154,7 +126,7 @@ |
|
|
|
function finishSaving(result) { |
|
|
|
abp.notify.success(l('SuccessfullySaved')); |
|
|
|
abp.ui.clearBusy(); |
|
|
|
location.href = "../BlogPosts/"; |
|
|
|
location.href = "/CmsKit/BlogPosts/"; |
|
|
|
} |
|
|
|
|
|
|
|
$titleClone.on('change paste keyup', function () { |
|
|
|
@ -177,4 +149,78 @@ |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
var fileUploadUri = "/api/cms-kit-admin/media/blogpost"; |
|
|
|
var fileUriPrefix = "/api/cms-kit/media/"; |
|
|
|
|
|
|
|
var editorDataKey = "tuiEditor"; |
|
|
|
|
|
|
|
initAllEditors(); |
|
|
|
|
|
|
|
function initAllEditors() { |
|
|
|
$('.content-editor').each(function (i, item) { |
|
|
|
initEditor(item); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function initEditor(element) { |
|
|
|
var $editorContainer = $(element); |
|
|
|
var inputName = $editorContainer.data('input-id'); |
|
|
|
var $editorInput = $('#' + inputName); |
|
|
|
var initialValue = $editorInput.val(); |
|
|
|
|
|
|
|
var editor = $editorContainer.tuiEditor({ |
|
|
|
usageStatistics: false, |
|
|
|
useCommandShortcut: true, |
|
|
|
initialValue: initialValue, |
|
|
|
previewStyle: 'tab', |
|
|
|
height: "25em", |
|
|
|
minHeight: "25em", |
|
|
|
initialEditType: initialValue ? 'wysiwyg' : 'markdown', |
|
|
|
language: $editorContainer.data("language"), |
|
|
|
hooks: { |
|
|
|
addImageBlobHook: uploadFile, |
|
|
|
}, |
|
|
|
events: { |
|
|
|
change: function (_val) { |
|
|
|
$editorInput.val(editor.getHtml()); |
|
|
|
$editorInput.trigger("change"); |
|
|
|
} |
|
|
|
} |
|
|
|
}).data(editorDataKey); |
|
|
|
} |
|
|
|
|
|
|
|
function uploadFile(blob, callback, source) { |
|
|
|
var UPPY_OPTIONS = { |
|
|
|
endpoint: fileUploadUri, |
|
|
|
formData: true, |
|
|
|
fieldName: "file", |
|
|
|
method: "post", |
|
|
|
headers: getUppyHeaders() |
|
|
|
}; |
|
|
|
|
|
|
|
var UPPY = Uppy.Core().use(Uppy.XHRUpload, UPPY_OPTIONS); |
|
|
|
|
|
|
|
UPPY.reset(); |
|
|
|
|
|
|
|
UPPY.addFile({ |
|
|
|
id: "content-file", |
|
|
|
name: blob.name, |
|
|
|
type: blob.type, |
|
|
|
data: blob, |
|
|
|
}); |
|
|
|
|
|
|
|
UPPY.upload().then((result) => { |
|
|
|
if (result.failed.length > 0) { |
|
|
|
abp.message.error("File upload failed"); |
|
|
|
} else { |
|
|
|
var mediaDto = result.successful[0].response.body; |
|
|
|
var fileUrl = (fileUriPrefix + mediaDto.id); |
|
|
|
|
|
|
|
callback(fileUrl, mediaDto.name); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |