|
|
|
@ -1,22 +1,25 @@ |
|
|
|
$(function () { |
|
|
|
var l = abp.localization.getResource("CmsKit"); |
|
|
|
|
|
|
|
var $formCreate = $('#form-page-create'); |
|
|
|
var $createForm = $('#form-page-create'); |
|
|
|
var $title = $('#ViewModel_Title'); |
|
|
|
var $slug = $('#ViewModel_Slug'); |
|
|
|
var $buttonSubmit = $('#button-page-create'); |
|
|
|
var $pageContentInput = $('#ViewModel_Value'); |
|
|
|
|
|
|
|
$formCreate.on('submit', function (e) { |
|
|
|
$createForm.data('validator').settings.ignore = ":hidden, [contenteditable='true']:not([name]), .tui-popup-wrapper"; |
|
|
|
|
|
|
|
$createForm.on('submit', function (e) { |
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
if ($formCreate.valid()) { |
|
|
|
if ($createForm.valid()) { |
|
|
|
|
|
|
|
abp.ui.setBusy(); |
|
|
|
|
|
|
|
$formCreate.ajaxSubmit({ |
|
|
|
$createForm.ajaxSubmit({ |
|
|
|
success: function (result) { |
|
|
|
submitEntityContent(result.id); |
|
|
|
abp.notify.success(l('SuccessfullySaved')); |
|
|
|
abp.ui.clearBusy(); |
|
|
|
location.href = "/CmsKit/Pages/"; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -24,28 +27,9 @@ |
|
|
|
|
|
|
|
$buttonSubmit.click(function (e) { |
|
|
|
e.preventDefault(); |
|
|
|
$formCreate.submit(); |
|
|
|
$createForm.submit(); |
|
|
|
}); |
|
|
|
|
|
|
|
function submitEntityContent(pageId) { |
|
|
|
volo.cmsKit.admin.contents.contentAdmin |
|
|
|
.create( |
|
|
|
{ |
|
|
|
entityType: 'Page', |
|
|
|
entityId: pageId, |
|
|
|
value: $pageContentInput.val() |
|
|
|
}) |
|
|
|
.then(function (result) { |
|
|
|
finishSaving(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function finishSaving() { |
|
|
|
abp.notify.success(l('SuccessfullySaved')); |
|
|
|
abp.ui.clearBusy(); |
|
|
|
location.href = "/CmsKit/Pages/"; |
|
|
|
} |
|
|
|
|
|
|
|
var slugEdited = false; |
|
|
|
|
|
|
|
$title.on('change paste keyup', function () { |
|
|
|
@ -69,4 +53,84 @@ |
|
|
|
$slug.change(function () { |
|
|
|
slugEdited = true; |
|
|
|
}); |
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
function getUppyHeaders() { |
|
|
|
var headers = {}; |
|
|
|
headers[abp.security.antiForgery.tokenHeaderName] = abp.security.antiForgery.getToken(); |
|
|
|
|
|
|
|
return headers; |
|
|
|
} |
|
|
|
|
|
|
|
var fileUploadUri = "/api/cms-kit-admin/media/page"; |
|
|
|
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); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |