2019-11-20 21:57:53 +08:00
|
|
|
/* global dropdownSelector TinyMCE */
|
|
|
|
var ProtocolRepositoryHeader = (function() {
|
|
|
|
function initEditKeywords() {
|
|
|
|
dropdownSelector.init('#keyword-input-field', {
|
|
|
|
inputTagMode: true,
|
|
|
|
onChange: function() {
|
|
|
|
$.ajax({
|
|
|
|
url: $('#keyword-input-field').data('update-url'),
|
|
|
|
type: 'PATCH',
|
|
|
|
dataType: 'json',
|
|
|
|
data: { keywords: dropdownSelector.getValues('#keyword-input-field') },
|
|
|
|
success: function() {
|
|
|
|
dropdownSelector.highlightSuccess('#keyword-input-field');
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
dropdownSelector.highlightError('#keyword-input-field');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initEditDescription() {
|
2020-03-19 22:45:14 +08:00
|
|
|
var viewObject = $('#protocol_description_view');
|
2020-09-28 18:03:01 +08:00
|
|
|
viewObject.on('click', function(e) {
|
|
|
|
if ($(e.target).hasClass('record-info-link')) return;
|
2019-11-20 21:57:53 +08:00
|
|
|
TinyMCE.init('#protocol_description_textarea');
|
2020-09-28 18:03:01 +08:00
|
|
|
}).on('click', 'a', function(e) {
|
|
|
|
if ($(this).hasClass('record-info-link')) return;
|
|
|
|
e.stopPropagation();
|
2019-11-20 21:57:53 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
init: () => {
|
|
|
|
if ($('.protocol-repository-header').length > 0) {
|
|
|
|
initEditKeywords();
|
|
|
|
initEditDescription();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
|
|
|
$(document).on('turbolinks:load', function() {
|
|
|
|
ProtocolRepositoryHeader.init();
|
|
|
|
});
|