2017-03-30 17:00:35 +02:00
|
|
|
$(document).on('turbolinks:load', init_path_modal);
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
function init_path_modal() {
|
2017-04-04 16:15:33 +02:00
|
|
|
path_modal_action();
|
|
|
|
path_validation_action();
|
|
|
|
path_type_init();
|
|
|
|
path_validation($("input[id='procedure_path']"));
|
2016-06-24 16:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function path_modal_action() {
|
2017-04-12 11:12:05 +02:00
|
|
|
$('#publish-modal').on('show.bs.modal', function (event) {
|
|
|
|
$("#publish-modal .modal-body .table .tr-content").hide();
|
2016-06-24 16:41:44 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
var button = $(event.relatedTarget) // Button that triggered the modal
|
|
|
|
var modal_title = button.data('modal_title'); // Extract info from data-* attributes
|
|
|
|
var modal_index = button.data('modal_index'); // Extract info from data-* attributes
|
2016-06-24 16:41:44 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
var modal = $(this)
|
2017-04-12 11:12:05 +02:00
|
|
|
modal.find('#publish-modal-title').html(modal_title);
|
|
|
|
$("#publish-modal .modal-body .table #"+modal_index).show();
|
2017-04-04 16:15:33 +02:00
|
|
|
})
|
2016-06-24 16:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function path_validation_action() {
|
2017-04-04 16:15:33 +02:00
|
|
|
$("input[id='procedure_path']").keyup(function (key) {
|
|
|
|
if (key.keyCode != 13)
|
|
|
|
path_validation(this);
|
|
|
|
});
|
2016-06-24 16:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function togglePathMessage(valid, mine) {
|
2017-04-12 11:12:05 +02:00
|
|
|
$('#path-messages .message').hide();
|
2017-04-04 16:15:33 +02:00
|
|
|
|
|
|
|
if (valid === true && mine === true) {
|
|
|
|
$('#path_is_mine').show();
|
|
|
|
} else if (valid === true && mine === false) {
|
|
|
|
$('#path_is_not_mine').show();
|
|
|
|
} else if (valid === false && mine === null) {
|
|
|
|
$('#path_is_invalid').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((valid && mine === null) || mine === true)
|
2017-04-12 11:12:05 +02:00
|
|
|
$('#publish-modal #publish').removeAttr('disabled')
|
2017-04-04 16:15:33 +02:00
|
|
|
else
|
2017-04-12 11:12:05 +02:00
|
|
|
$('#publish-modal #publish').attr('disabled', 'disabled')
|
2016-06-24 16:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function path_validation(el) {
|
2017-04-04 16:15:33 +02:00
|
|
|
var valid = validatePath($(el).val());
|
|
|
|
toggleErrorClass(el, valid);
|
|
|
|
togglePathMessage(valid, null);
|
2016-06-24 16:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function validatePath(path) {
|
2017-04-14 11:34:53 +02:00
|
|
|
var re = /^[a-z0-9_\-]{3,50}$/;
|
2017-04-04 16:15:33 +02:00
|
|
|
return re.test(path);
|
2016-06-24 16:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function path_type_init() {
|
2017-04-04 16:15:33 +02:00
|
|
|
display = 'label';
|
|
|
|
|
|
|
|
var bloodhound = new Bloodhound({
|
|
|
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(display),
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
|
|
|
|
remote: {
|
|
|
|
url: '/admin/procedures/path_list?request=%QUERY',
|
|
|
|
wildcard: '%QUERY'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
bloodhound.initialize();
|
|
|
|
|
|
|
|
$("#procedure_path").typeahead({
|
|
|
|
minLength: 1
|
|
|
|
}, {
|
|
|
|
display: display,
|
|
|
|
source: bloodhound,
|
|
|
|
templates: {
|
|
|
|
empty: 'Ce lien est disponible !',
|
2017-04-12 11:12:05 +02:00
|
|
|
suggestion: Handlebars.compile("<div class='path-mine-{{mine}}'>{{label}}</div>")
|
2017-04-04 16:15:33 +02:00
|
|
|
},
|
|
|
|
limit: 5
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#procedure_path').bind('typeahead:select', function(ev, suggestion) {
|
|
|
|
togglePathMessage(true, suggestion['mine']);
|
|
|
|
});
|
2016-07-22 11:34:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function transfer_errors_message(show) {
|
2017-04-04 16:15:33 +02:00
|
|
|
if(show){
|
|
|
|
$("#not_found_admin").slideDown(100)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#not_found_admin").slideUp(100)
|
|
|
|
}
|
2017-03-30 17:00:35 +02:00
|
|
|
}
|