Rename TypeDeChamps to TypeDeChamp

This commit is contained in:
Xavier J 2015-11-05 11:21:44 +01:00
parent 519af34c82
commit f3d8645426
34 changed files with 644 additions and 634 deletions

View file

@ -1,14 +1,14 @@
var ready = function () {
$("#add_type_de_champs_procedure").on('click', function (e) {
add_new_type_de('champs');
$("#add_type_de_champ_procedure").on('click', function (e) {
add_new_type_de('champ');
});
$("#add_type_de_piece_justificative_procedure").on('click', function (e) {
add_new_type_de('piece_justificative');
});
add_delete_listener_on_click_for_type_de("champs", "#liste_champs .btn-danger");
add_delete_listener_on_click_for_type_de("champs", "#new_type_de_champs .btn-danger");
add_delete_listener_on_click_for_type_de("champ", "#liste_champ .btn-danger");
add_delete_listener_on_click_for_type_de("champ", "#new_type_de_champ .btn-danger");
add_delete_listener_on_click_for_type_de("piece_justificative", "#liste_piece_justificative .btn-danger");
add_delete_listener_on_click_for_type_de("piece_justificative", "#new_type_de_piece_justificative .btn-danger");
@ -35,16 +35,16 @@ function add_new_type_de(type_libelle) {
PJ = 1,
ERROR = -1;
if (is_champs_or_pj() == ERROR) return false;
if (is_champ_or_pj() == ERROR) return false;
function is_champs_or_pj() {
if (type_libelle == 'champs') return CHAMPS;
function is_champ_or_pj() {
if (type_libelle == 'champ') return CHAMPS;
else if (type_libelle == 'piece_justificative') return PJ;
else return ERROR;
}
function which_index() {
return (is_champs_or_pj() == CHAMPS ? types_de_champs_index : types_de_piece_justificative_index)
return (is_champ_or_pj() == CHAMPS ? types_de_champ_index : types_de_piece_justificative_index)
}
$("#liste_" + type_libelle).append($("#type_de_" + type_libelle + "_" + which_index()));
@ -52,11 +52,11 @@ function add_new_type_de(type_libelle) {
$("#delete_type_de_" + type_libelle + "_" + which_index() + "_button").show();
if (is_champs_or_pj() == CHAMPS) {
types_de_champs_index++;
add_new_type_de_champs_params(which_index());
if (is_champ_or_pj() == CHAMPS) {
types_de_champ_index++;
add_new_type_de_champ_params(which_index());
}
else if (is_champs_or_pj() == PJ) {
else if (is_champ_or_pj() == PJ) {
types_de_piece_justificative_index++;
add_new_type_de_piece_justificative_params(which_index());
}
@ -72,9 +72,9 @@ function add_new_type_de(type_libelle) {
$("#new_type_de_" + type_libelle + " #delete_type_de_" + type_libelle + "_" + (which_index() - 1) + "_button").attr('id', "delete_type_de_" + type_libelle + "_" + which_index() + "_button");
$("#new_type_de_" + type_libelle + " #delete_type_de_" + type_libelle + "_" + (which_index() - 1) + "_procedure").attr('id', "delete_type_de_" + type_libelle + "_" + which_index() + "_procedure");
if (is_champs_or_pj() == CHAMPS)
add_delete_listener_on_click_for_type_de("champs", "#delete_type_de_champs_" + which_index() + "_procedure");
else if (is_champs_or_pj() == PJ)
if (is_champ_or_pj() == CHAMPS)
add_delete_listener_on_click_for_type_de("champ", "#delete_type_de_champ_" + which_index() + "_procedure");
else if (is_champ_or_pj() == PJ)
add_delete_listener_on_click_for_type_de("piece_justificative", "#delete_type_de_piece_justificative_" + which_index() + "_procedure");
$("#new_type_de_" + type_libelle + " #add_type_de_" + type_libelle + "_button").remove();
@ -86,21 +86,21 @@ function add_new_type_de(type_libelle) {
config_up_and_down_button();
}
function add_new_type_de_champs_params() {
$("#new_type_de_champs #libelle").attr('name', 'type_de_champs[' + types_de_champs_index + '][libelle]');
$("#new_type_de_champs #libelle").val('');
function add_new_type_de_champ_params() {
$("#new_type_de_champ #libelle").attr('name', 'type_de_champ[' + types_de_champ_index + '][libelle]');
$("#new_type_de_champ #libelle").val('');
$("#new_type_de_champs #description").attr('name', 'type_de_champs[' + types_de_champs_index + '][description]');
$("#new_type_de_champs #description").val('');
$("#new_type_de_champ #description").attr('name', 'type_de_champ[' + types_de_champ_index + '][description]');
$("#new_type_de_champ #description").val('');
$("#new_type_de_champs #type_champs").attr('name', 'type_de_champs[' + types_de_champs_index + '][type]');
$("#new_type_de_champ #type_champs").attr('name', 'type_de_champ[' + types_de_champ_index + '][type]');
$("#new_type_de_champs .order_place").attr('name', 'type_de_champs[' + types_de_champs_index + '][order_place]');
$("#new_type_de_champs .order_place").val(parseInt($("#liste_champs .order_place").last().val()) + 1);
$("#new_type_de_champ .order_place").attr('name', 'type_de_champ[' + types_de_champ_index + '][order_place]');
$("#new_type_de_champ .order_place").val(parseInt($("#liste_champ .order_place").last().val()) + 1);
$("#new_type_de_champs .order_type_de_champs_button").attr('id', 'order_type_de_champs_' + types_de_champs_index + '_button')
$("#new_type_de_champs .order_type_de_champs_button .button_up").attr('id', 'order_type_de_champs_' + types_de_champs_index + '_up_procedure')
$("#new_type_de_champs .order_type_de_champs_button .button_down").attr('id', 'order_type_de_champs_' + types_de_champs_index + '_down_procedure')
$("#new_type_de_champ .order_type_de_champ_button").attr('id', 'order_type_de_champ_' + types_de_champ_index + '_button')
$("#new_type_de_champ .order_type_de_champ_button .button_up").attr('id', 'order_type_de_champ_' + types_de_champ_index + '_up_procedure')
$("#new_type_de_champ .order_type_de_champ_button .button_down").attr('id', 'order_type_de_champ_' + types_de_champ_index + '_down_procedure')
}
function add_new_type_de_piece_justificative_params() {
@ -117,57 +117,57 @@ function delete_type_de(type_libelle, index) {
$("#liste_delete_" + type_libelle).append(delete_node);
$("#type_de_" + type_libelle + "_" + index + " #delete").val('true');
if (type_libelle == 'champs') {
if (type_libelle == 'champ') {
var next_order_place = parseInt($("#type_de_" + type_libelle + "_" + index + " .order_place").val());
var type_de_champs_to_change_order_place = $("#liste_champs .order_place");
var type_de_champ_to_change_order_place = $("#liste_champ .order_place");
type_de_champs_to_change_order_place.each(function () {
type_de_champ_to_change_order_place.each(function () {
if ($(this).val() > next_order_place) {
$(this).val(next_order_place++);
}
});
$("#new_type_de_champs .order_place").val(next_order_place);
$("#new_type_de_champ .order_place").val(next_order_place);
config_up_and_down_button();
}
}
function config_up_and_down_button() {
if ($("#liste_champs .order_place").size() > 0) {
var first_index = $("#liste_champs .order_place").first()
if ($("#liste_champ .order_place").size() > 0) {
var first_index = $("#liste_champ .order_place").first()
.attr('name')
.replace('type_de_champs[', '')
.replace('type_de_champ[', '')
.replace('][order_place]', '');
var last_index = $("#liste_champs .order_place").last()
var last_index = $("#liste_champ .order_place").last()
.attr('name')
.replace('type_de_champs[', '')
.replace('type_de_champ[', '')
.replace('][order_place]', '');
$(".button_up").show();
$(".button_down").show();
$("#liste_champs .order_type_de_champs_button").show();
$("#liste_champ .order_type_de_champ_button").show();
$("#order_type_de_champs_" + first_index + "_up_procedure").hide();
$("#order_type_de_champs_" + last_index + "_down_procedure").hide();
$("#order_type_de_champ_" + first_index + "_up_procedure").hide();
$("#order_type_de_champ_" + last_index + "_down_procedure").hide();
}
}
function add_action_listener_on_click_for_button_up(node_id) {
$(node_id).on('click', function (e) {
var index = (e.target.id).replace('order_type_de_champs_', '').replace('_up_procedure', '');
var order_place = parseInt($("#type_de_champs_" + index + " .order_place").val());
var index = (e.target.id).replace('order_type_de_champ_', '').replace('_up_procedure', '');
var order_place = parseInt($("#type_de_champ_" + index + " .order_place").val());
var order_place_before = order_place - 1;
var node_before = $("input[class='order_place'][value='" + order_place_before + "']").parent();
var index_before = (node_before.attr('id')).replace('type_de_champs_', '');
var index_before = (node_before.attr('id')).replace('type_de_champ_', '');
$("#type_de_champs_" + index).insertBefore("#type_de_champs_" + index_before);
$("#type_de_champs_" + index_before);
$("#type_de_champ_" + index).insertBefore("#type_de_champ_" + index_before);
$("#type_de_champ_" + index_before);
$("#type_de_champs_" + index_before + " .order_place").val(order_place);
$("#type_de_champs_" + index + " .order_place").val(order_place_before);
$("#type_de_champ_" + index_before + " .order_place").val(order_place);
$("#type_de_champ_" + index + " .order_place").val(order_place_before);
config_up_and_down_button();
});
@ -175,19 +175,19 @@ function add_action_listener_on_click_for_button_up(node_id) {
function add_action_listener_on_click_for_button_down(node_id) {
$(node_id).on('click', function (e) {
var index = (e.target.id).replace('order_type_de_champs_', '').replace('_down_procedure', '');
var order_place = parseInt($("#type_de_champs_" + index + " .order_place").val());
var index = (e.target.id).replace('order_type_de_champ_', '').replace('_down_procedure', '');
var order_place = parseInt($("#type_de_champ_" + index + " .order_place").val());
var order_place_after = order_place + 1;
var node_after = $("input[class='order_place'][value='" + order_place_after + "']").parent();
var index_after = (node_after.attr('id')).replace('type_de_champs_', '');
var index_after = (node_after.attr('id')).replace('type_de_champ_', '');
$("#type_de_champs_" + index).insertAfter("#type_de_champs_" + index_after);
$("#type_de_champs_" + index_after);
$("#type_de_champ_" + index).insertAfter("#type_de_champ_" + index_after);
$("#type_de_champ_" + index_after);
$("#type_de_champs_" + index_after + " .order_place").val(order_place);
$("#type_de_champs_" + index + " .order_place").val(order_place_after);
$("#type_de_champ_" + index_after + " .order_place").val(order_place);
$("#type_de_champ_" + index + " .order_place").val(order_place_after);
config_up_and_down_button();
});