$(function () { $('button.convertCsvReplacement').on('click', function (e) { e.preventDefault(); var csv = $('textarea.replacements-csv-convert').val(); var rows = csv.split("\n"); for (var i in rows) { $('.addReplacement').trigger('click'); var cells = rows[i].split('";"'); cells[0] = cells[0].substr(1, cells[0].length); cells[1] = cells[1].substr(0, cells[1].length - 1); $('.replacements .replacement:last-child input.find').val(cells[0]); $('.replacements .replacement:last-child input.replace').val(cells[1]); } return false; }); $(document).on('click', '.removeReplacement', function (e) { e.preventDefault(); var replacementsInfo = $(this).parent().parent().parent().parent().parent().parent().find('.replacements-info').eq(0); if (($(this).parent().parent().parent().parent().parent().parent().find('.replacement').length - 1) > 0) { replacementsInfo.addClass('hidden'); } else { replacementsInfo.removeClass('hidden'); } $(this).parent().parent().parent().parent().remove(); return false; }); $(document).on('click', '.addReplacement', function (e) { e.preventDefault(); var replacementsInfo = $(this).parent().parent().parent().find('.replacements-info').eq(0); if (!replacementsInfo.hasClass('hidden')) { replacementsInfo.addClass('hidden'); } var replacements = $(this).parent().parent().parent().find('.replacements').eq(0); var nameKey = 'replacement[' + replacementCounter + ']'; var html = '
\
\
\
\ \
\ \
\
\
\ \
\ \
\
\
\
\
\ \
\ \ \ \ \ \ \ \
\
\
\ \
\
\
\
\
'; ++replacementCounter; replacements.append(html); return false; }); // conditions var token = document.location.href.split('&token=')[1].split('&')[0]; var file = document.location.href.split('&file=')[1].split('&')[0]; $.get("index.php?controller=PShowImporterConfig&token=" + token + "&page=getsavedconditions&file=" + file, function (conditions) { conditions = JSON.parse(conditions); for (var k in conditions) { addConditionToTable(conditions[k].field, conditions[k].condition, conditions[k].value, conditions[k].action); } }); $(document).on('click', '.btn-addCondition', function (e) { e.preventDefault(); var field = $('select#condition_field').val(); var condition = $('select#condition_condition').val(); var value = $('input#condition_value').val(); var action = $('select#condition_action').val(); addConditionToTable(field, condition, value, action); return false; }); $(document).on('click', '.btn-delCondition', function (e) { e.preventDefault(); $(this).parent().parent().remove(); return false; }); }); var conditionsCounter = 0; /** * Add condition to conditions table * * @param string field * @param string condition * @param string value * @param string action */ function addConditionToTable(field, condition, value, action) { //if (field === '' || condition === '' || value === '' || action === '') { // alert("Fill all fields"); // return; //} var conditions_table = $('tbody.conditions-table'); var nameKey = 'conditions[' + conditionsCounter + ']'; var tr = ""; tr += "" + field + ""; tr += "" + condition + ""; tr += "" + value + ""; tr += "" + action + ""; tr += "\ \ "; tr += ""; ++conditionsCounter; conditions_table.append(tr); }