export.js 1.71 KB
// straszna i zła copypasta
function selected_qualifiers_text(num, total, checked) {
  if (num >= 4)
    return num + ' kwalifikatorów';
  grouped = {};
  $.each(checked, function(i, elem) {
    id = elem.value;
    vocab = vocabs[id];
    if (grouped[vocab] === undefined)
      grouped[vocab] = [];
    grouped[vocab].push(elem.title);
  });
  vocab_table = [];
  owner = $('#owner-vocabulary').text();
  if (grouped[owner])
    vocab_table.push(owner + ': ' + grouped[owner].join(', '));
  for (vocab in grouped) {
    if (vocab != owner)
      vocab_table.push(vocab + ': ' + grouped[vocab].join(', '));
  }
  return vocab_table.join('; ');
}

var qualifier_options = {
  noneSelectedText: 'Wybierz',
  selectedText: selected_qualifiers_text,
  selectedList: 4,
  header: false,
};

var new_row_counter = 1;
function get_new_qualifier_row_html() {
  var new_row_html = $.ajax({
    type: 'get',
    url: ajax_new_qualifier_row,
    async: false
  }).responseText;
  var row_html = new_row_html.replace(/NUM/g, new_row_counter);
  new_row_counter++;
  return row_html;
}

function add_qualifier_row() {
  var new_row = $(get_new_qualifier_row_html());
  $('#magic-qualifiers').append(new_row);
  new_row.find('button').button();
}

function remove_qualifier_row() {
  $(this).closest('li').remove();
}

$(function() {
  var opts = {
    noneSelectedText: 'Wybierz słowniki',
    selectedText: '# słowników',
    selectedList: 4,
    header: false
  };
  $('#id_vocabs').multiselect(opts);
  $('#id_antivocabs').multiselect(opts);
  $('#id_excluding_qualifiers').multiselect(qualifier_options);
  $('#add-magic-qualifier-row').on('click', add_qualifier_row);
  $(document).on('click', '#magic-qualifiers .remove', remove_qualifier_row);
})