manager-view.js 1.32 KB
$(function() {
  "use strict";
  $('#add-vocabulary').click(function() {
    var new_vocab = $('#new-vocabulary');
    var name = new_vocab.value();
    new_vocab.val('');
    $.ajaxJSON({
      method: 'post',
      url: $dj.ajax_add_vocabulary,
      data: {name: name},
      callback: function() {
        location.reload(); // porządniejszy by był zwykły formularz...
      }
    });
  });
  $('.user-privileges').find('input[type=checkbox]').change(function() {
    var $t = $(this),
      id = this.id.split('-')[1],
      type = this.id.split('-')[0],
      table_id = $t.closest('table')[0].id,
      vocab_name = table_id.substr(table_id.indexOf('_') + 1);
    $.ajaxJSON({
      method: 'post',
      url: $dj.ajax_set_permission,
      data: {
        name: vocab_name,
        vocab_id: id,
        perm: type,
        on: $t.is(':checked')
      }
    });
    var view_checkbox = $('#view-'+id), change_checkbox = $('#change-'+id);
    if (type === 'change' && $t.is(':checked') &&
        !view_checkbox.is(':checked')) {
      view_checkbox.prop('checked', true).change();
    }
    if (type === 'view' && ! $t.is(':checked') && change_checkbox.is(':checked')) {
      change_checkbox.prop('checked', false).change();
    }
  });
  $('#vocab-accordion').togglepanels();
    //{autoHeight: false, collapsible: true, active: false});
});