Use delegated events instead of local handlers
This commit is contained in:
parent
8bf5dedd80
commit
ea68c75361
4 changed files with 48 additions and 59 deletions
|
@ -1,52 +1,47 @@
|
|||
$(document).on('turbolinks:load', init_admin);
|
||||
$(document).on('click', '.delete', function() {
|
||||
$(this).hide();
|
||||
$(this)
|
||||
.closest('td')
|
||||
.find('.confirm')
|
||||
.show();
|
||||
});
|
||||
|
||||
function init_admin(){
|
||||
destroy_action();
|
||||
on_change_type_de_champ_select();
|
||||
}
|
||||
$(document).on('click', '.cancel', function() {
|
||||
$(this)
|
||||
.closest('td')
|
||||
.find('.delete')
|
||||
.show();
|
||||
$(this)
|
||||
.closest('td')
|
||||
.find('.confirm')
|
||||
.hide();
|
||||
});
|
||||
|
||||
function destroy_action(){
|
||||
$(".delete").on('click', function(){
|
||||
$(this).hide();
|
||||
$(this).closest('td').find(".confirm").show();
|
||||
});
|
||||
$(document).on('change', 'select.form-control.type-champ', function() {
|
||||
var parent = $(this)
|
||||
.parent()
|
||||
.parent();
|
||||
|
||||
$(".cancel").on('click', function(){
|
||||
$(this).closest('td').find(".delete").show();
|
||||
$(this).closest('td').find(".confirm").hide();
|
||||
});
|
||||
parent.removeClass('header-section');
|
||||
parent.children('.drop-down-list').removeClass('show-inline');
|
||||
parent.children('.pj-template').removeClass('show-inline');
|
||||
|
||||
$("#liste-gestionnaire #libelle").on('click', function(){
|
||||
setTimeout(destroy_action, 500);
|
||||
});
|
||||
}
|
||||
$('.mandatory', parent).show();
|
||||
|
||||
function on_change_type_de_champ_select (){
|
||||
$("select.form-control.type-champ").on('change', function(e){
|
||||
|
||||
parent = $(this).parent().parent();
|
||||
|
||||
parent.removeClass('header-section');
|
||||
parent.children(".drop-down-list").removeClass('show-inline');
|
||||
parent.children(".pj-template").removeClass('show-inline');
|
||||
|
||||
$('.mandatory', parent).show();
|
||||
|
||||
switch(this.value){
|
||||
case 'header_section':
|
||||
parent.addClass('header-section');
|
||||
break;
|
||||
case 'drop_down_list':
|
||||
case 'multiple_drop_down_list':
|
||||
case 'linked_drop_down_list':
|
||||
parent.children(".drop-down-list").addClass('show-inline');
|
||||
break;
|
||||
case 'piece_justificative':
|
||||
parent.children(".pj-template").addClass('show-inline');
|
||||
break;
|
||||
case 'explication':
|
||||
$('.mandatory', parent).hide();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
switch (this.value) {
|
||||
case 'header_section':
|
||||
parent.addClass('header-section');
|
||||
break;
|
||||
case 'drop_down_list':
|
||||
case 'multiple_drop_down_list':
|
||||
case 'linked_drop_down_list':
|
||||
parent.children('.drop-down-list').addClass('show-inline');
|
||||
break;
|
||||
case 'piece_justificative':
|
||||
parent.children('.pj-template').addClass('show-inline');
|
||||
break;
|
||||
case 'explication':
|
||||
$('.mandatory', parent).hide();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
$(document).on('turbolinks:load', link_init);
|
||||
|
||||
function link_init() {
|
||||
$('#dossiers-list tr').on('click', function(event) {
|
||||
var href = $(this).data('href');
|
||||
if (href && event.target.tagName !== 'A') {
|
||||
location.href = href;
|
||||
}
|
||||
});
|
||||
}
|
||||
$(document).on('click', '#dossiers-list tr', function(event) {
|
||||
var href = $(this).data('href');
|
||||
if (href && event.target.tagName !== 'A') {
|
||||
location.href = href;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
<%= smart_listing_update :procedures %>
|
||||
link_init();
|
|
@ -1,3 +1,2 @@
|
|||
<%= render_flash(timeout: 3000, sticky: true) %>
|
||||
<%= render_to_element('#liste-champ', partial: 'admin/types_de_champ/form', locals: { procedure: @procedure, types_de_champ: @types_de_champ }) %>
|
||||
on_change_type_de_champ_select();
|
||||
|
|
Loading…
Reference in a new issue