manager-view.js
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$(function() {
$('#vocabulary-select').change(function() {
$('#user-privileges input[type=checkbox]').prop('checked', false);
$.ajaxJSON({
method: 'get',
url: ajax_get_privileges,
data: {name: $(this).value()},
callback: function(data) {
$.each(data.viewers, function(i, id) {
$('#view-'+id).prop('checked', true);
});
$.each(data.editors, function(i, id) {
$('#change-'+id).prop('checked', true);
});
$.each(data.managers, function(i, id) {
$('#manage-'+id).prop('checked', true);
});
}
});
});
$('#add-vocabulary').click(function() {
var name = $('#new-vocabulary').value();
$('#new-vocabulary').val('');
$.ajaxJSON({
method: 'post',
url: ajax_add_vocabulary,
data: {name: name},
callback: function() {
var option = $('<option/>').text(name).val(name);
$('#vocabulary-select').append(option);
}
});
});
$('#user-privileges input[type=checkbox]').change(function() {
var $t = $(this),
id = this.id.split('-')[1],
type = this.id.split('-')[0],
name = $('#vocabulary-select').value();
$.ajaxJSON({
method: 'post',
url: ajax_set_privilege,
data: {
name: name,
id: id,
type: type,
set: $t.is(':checked')
}
});
if (type == 'change' && $t.is(':checked') && ! $('#view-'+id).is(':checked')) {
$('#view-'+id).prop('checked', true).change();
}
if (type == 'view' && ! $t.is(':checked') && $('#change-'+id).is(':checked')) {
$('#change-'+id).prop('checked', false).change();
}
});
});