228 lines
6.2 KiB
Plaintext
228 lines
6.2 KiB
Plaintext
| {% from '_macros/_node_edit_form.html' import render_field %}
|
|
|
|
| {% block body %}
|
|
|
|
| {% with errors = errors %}
|
|
| {% if errors %}
|
|
|
|
| {% for field in errors %}
|
|
.alert.alert-danger(role="alert")
|
|
strong {{field}}
|
|
| {% for message in errors[field] %}
|
|
| {{message}}|
|
|
| {% endfor %}
|
|
|
|
| {% endfor %}
|
|
|
|
| {% endif %}
|
|
| {% endwith %}
|
|
|
|
| {% if error!="" %}
|
|
.alert.alert-danger(role="alert")
|
|
| {{error}}
|
|
| {% endif %}
|
|
|
|
#node-edit-container
|
|
|
|
form(
|
|
id="node-edit-form",
|
|
class="{{ node.node_type }}",
|
|
method="POST",
|
|
enctype="multipart/form-data",
|
|
action="{{url_for('nodes.edit', node_id=node._id)}}")
|
|
|
|
| {% for field in form %}
|
|
|
|
| {% if field.name == 'csrf_token' %}
|
|
| {{ field }}
|
|
|
|
| {% elif field.type == 'HiddenField' %}
|
|
| {{ field }}
|
|
|
|
| {% elif field.name == 'attachments' %}
|
|
hr
|
|
#attachments-actions
|
|
.btn.btn-info#attachments-action-add
|
|
i.pi-plus
|
|
| Add New Attachment
|
|
|
|
p.text-muted.mt-3
|
|
| Attachments can be included in any MarkDown field by using the #[code {attachment slug}] shortcode
|
|
| (#[a(href='https://pillarframework.org/shortcodes/#attachments', target='_blank') help]).
|
|
| This shortcode is placed on your copy-paste buffer by clicking "Copy to clipboard".
|
|
|
|
| {{ render_field(field, field.name) }}
|
|
hr
|
|
|
|
| {% elif field.name == 'files' %}
|
|
#files-actions
|
|
#files-action-add
|
|
i.pi-plus
|
|
| Add New File
|
|
| {{ render_field(field, field.name) }}
|
|
|
|
| {% else %}
|
|
|
|
| {{ render_field(field) }}
|
|
|
|
| {% endif %}
|
|
|
|
| {% endfor %}
|
|
|
|
hr
|
|
|
|
ul.project-edit-tools.disabled.d-flex.list-unstyled.p-2.mb-0.h-auto.justify-content-end
|
|
li.button-cancel
|
|
a#item_cancel.item-cancel.project-mode-edit.btn.btn-outline-secondary(
|
|
href="javascript:void(0);",
|
|
title="Cancel changes")
|
|
i.button-cancel-icon.pi-cancel
|
|
| Cancel
|
|
|
|
li.button-save
|
|
a#item_save.item-save.project-mode-edit.btn.btn-outline-success.ml-2(
|
|
href="javascript:void(0);",
|
|
title="Save changes")
|
|
i.button-save-icon.pi-check
|
|
| Save Changes
|
|
|
|
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.ui.widget.min.js') }}")
|
|
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.iframe-transport.min.js') }}")
|
|
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.fileupload.min.js') }}")
|
|
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.select2.min.js') }}")
|
|
script(src="{{ url_for('static_pillar', filename='assets/js/file_upload.min.js') }}")
|
|
|
|
script(type="text/javascript").
|
|
|
|
$(function () {
|
|
$('#tags').select2();
|
|
|
|
// Set the page title on the document
|
|
var page_title = 'Edit: {{ node.name }} - {{ project.name }} — Blender Cloud';
|
|
DocumentTitleAPI.set_page_title(page_title);
|
|
|
|
var $contentField = $('.form-group.description textarea'),
|
|
$contentPreview = $('<div class="node-edit-form-md-preview" />').insertAfter($contentField);
|
|
|
|
function parseDescriptionContent(content) {
|
|
|
|
pillar.api.thenMarkdownToHtml(content)
|
|
.done(function (data) {
|
|
$contentPreview.html(data.content);
|
|
})
|
|
.fail(function (err) {
|
|
toastr.error(xhrErrorResponseMessage(err), 'Parsing failed');
|
|
});
|
|
}
|
|
|
|
var options = {
|
|
callback: parseDescriptionContent,
|
|
wait: 750,
|
|
highlight: false,
|
|
allowSubmit: false,
|
|
captureLength: 2
|
|
}
|
|
|
|
$contentField.typeWatch(options);
|
|
|
|
|
|
$('input, textarea').keypress(function () {
|
|
// Unused: save status of the page as 'edited'
|
|
ProjectUtils.setProjectAttributes({isModified: true});
|
|
// Set the beforeunload to warn the user of unsaved changes
|
|
$(window).on('beforeunload', function () {
|
|
return 'You have unsaved changes in your asset.';
|
|
});
|
|
});
|
|
});
|
|
|
|
$("#item_save").unbind( "click" );
|
|
$("#item_cancel").unbind( "click" );
|
|
$(".file_delete").unbind( "click" );
|
|
|
|
/* Reset Save Changes button status */
|
|
$("li.button-save").removeClass('field-error saving');
|
|
$("li.button-save a#item_save").html('<i class="pi-check"></i> Save Changes');
|
|
|
|
|
|
/* Submit changes */
|
|
$("#node-edit-form").unbind("submit").submit(function(e) {
|
|
e.preventDefault();
|
|
|
|
// Assets always need a file
|
|
var $file = $('.form-group.file #file');
|
|
if ($file.val() == '') {
|
|
$file.addClass('error');
|
|
toastr.error('No file selected');
|
|
return jQuery.Deferred().reject("nofile");
|
|
}
|
|
|
|
$file.removeClass('error');
|
|
|
|
/* Let us know started saving */
|
|
$("li.button-save").addClass('saving');
|
|
$("li.button-save a#item_save").html('<i class="pi-spin pr-2 spin"></i> Saving...');
|
|
|
|
$.ajax({
|
|
url: "{{url_for('nodes.edit', node_id=node._id)}}",
|
|
data: $(this).serialize(),
|
|
type: 'POST'
|
|
})
|
|
.fail(function(data){
|
|
/* Something went wrong, print it */
|
|
if (data.status == 422) {
|
|
toastr.error('The submitted data could not be validated');
|
|
} else {
|
|
toastr.error(data.status + ' ' + data.statusText, 'Error saving');
|
|
}
|
|
|
|
$("li.button-save").addClass('field-error');
|
|
$("li.button-save a#item_save").html('<i class="pi-warning"></i> Houston!');
|
|
|
|
/* Back to normal */
|
|
setTimeout(function(){
|
|
$("li.button-save").removeClass('saving field-error');
|
|
$("li.button-save a#item_save").html('<i class="pi-check"></i> Save Changes');
|
|
}, 8000);
|
|
})
|
|
.done(function(dataHtml){
|
|
/* Success! */
|
|
// Disable beforeunolad when submitting a form
|
|
$(window).off('beforeunload');
|
|
|
|
{% if is_embedded_edit %}
|
|
/* Load content*/
|
|
$('#project_context').html(dataHtml);
|
|
toastr.success('Saved!');
|
|
|
|
/* Style button */
|
|
$("li.button-save").removeClass('saving field-error');
|
|
$("li.button-save a#item_save").html('<i class="pi-check"></i> Save Changes');
|
|
|
|
// XXX TODO - Keeps displaying 'loading', needs further investigation
|
|
//- $('#project_tree').jstree("refresh");
|
|
|
|
updateUi(ProjectUtils.nodeId(), 'view');
|
|
{% else %}
|
|
// This code runs only if we are in direct node editing mode, and since we do a redirect,
|
|
// nothing of what follows is executed, because of the redirect.
|
|
location.href = "{{ url_for('nodes.view', node_id=node._id)}}";
|
|
{% endif %}
|
|
});
|
|
|
|
});
|
|
|
|
$('#item_save, .item-save').click(function(e){
|
|
e.preventDefault();
|
|
$("#node-edit-form").submit();
|
|
});
|
|
|
|
$('#item_cancel, .item-cancel').click(function(e){
|
|
displayNode('{{node._id}}');
|
|
});
|
|
|
|
$("#attachments-action-add").addNewFileButton();
|
|
$("#files-action-add").addNewFileButton();
|
|
|
|
| {% endblock %}
|