forked from cosmocode/dokuwiki-plugin-structstatus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
93 lines (83 loc) · 2.85 KB
/
Copy pathscript.js
File metadata and controls
93 lines (83 loc) · 2.85 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
jQuery(function () {
/**
* Attach the click handler
*/
jQuery('.structstatus-full.editable').find('button.struct_status')
.click(function () {
var $self = jQuery(this);
$self.parent().css('visibility', 'hidden');
var set = makeDataSet($self.parent(), $self.data('pid'));
var data = {
sectok: $self.parent().data('st'),
field: $self.parent().data('field'),
pid: $self.parent().data('page'),
entry: set,
call: 'plugin_struct_inline_save'
};
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
data
)
.error(function (jqXHR) {
alert(jqXHR.responseText);
})
.success(function (response) {
applyDataSet($self.parent(), set);
jQuery('#plugin__struct_output').find('td[data-struct="'+ $self.parent().data('field') +'"]').html(response);
})
.done(function () {
$self.parent().css('visibility', 'visible');
})
;
})
;
/**
* Set the statuses accrding to the given set
*
* @param {jQuery} $full the wrapper around the statuses
* @param {int|int[]} set the status or the list of statuses to enable
*/
function applyDataSet($full, set) {
$full.find('button.struct_status').each(function () {
if (typeof set == 'undefined') {
set = [];
}
if (typeof set == 'number') {
set = [set];
}
var $self = jQuery(this);
if (set.indexOf($self.data('pid')) === -1) {
$self.addClass('disabled');
} else {
$self.removeClass('disabled');
}
});
}
/**
* Create a set based on the current set and the status to toggle
*
* @param {jQuery} $full the wrapper around the statuses
* @param {int} toggle the pid of the status to toggle
* @return {int|int[]} the resulting new set
*/
function makeDataSet($full, toggle) {
var set = [];
var wason = false;
$full.find('button.struct_status').not('.disabled').each(function () {
var pid = jQuery(this).data('pid');
if (pid === toggle) {
wason = true; // this is the value we're toggling
} else {
set.push(pid); // this is an enabled value we keep
}
});
if (!wason) {
set.push(toggle); // value was not enabled previously, we toggle it
}
// for non-multi field only one value is allowed
if (!$full.data('multi')) {
return set.pop();
}
return set;
}
});