forked from onozaty/redmine-view-customize-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink_custom_field.js
57 lines (45 loc) · 1.6 KB
/
link_custom_field.js
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
// カスタムフィールドを連動させる(親の値に応じて、子を絞り込む)
//
// Path pattern: /issues/
// Type: JavaScript
$(function() {
var parentFieldId = 'issue_custom_field_values_1';
var childFieldId = 'issue_custom_field_values_2';
// 表示条件
var isTarget = function(child, parent) {
// 前方一致のものを対象に
return child.text().indexOf(parent.text()) == 0;
}
// 子フィールドの絞り込み
var narrowChildField = function() {
// 親で選択している項目
var parentSelected = $('#' + parentFieldId + ' > option:selected');
$('#' + childFieldId + ' > option').each(function() {
var child = $(this);
// 一致したものだけに絞り込む
// (IEの場合はoptionがdisplay:noneで非表示にならないのでdisabledで選択不可に)
if (isTarget(child, parentSelected)) {
child.show();
child.prop('disabled', false);
} else {
child.hide();
child.prop('disabled', true);
}
});
}
// 現時点のもので子を絞り込み
narrowChildField();
// 親フィールドが変わった際に子フィールドを絞り込み
$('#all_attributes').change(function(e) {
if (e.target.id == parentFieldId) {
narrowChildField();
}
});
// ステータス変更時などにDOMが差し替えられるので
// フォームの内容が書き変わるたびに絞り込みを反映
var _replaceIssueFormWith = replaceIssueFormWith;
replaceIssueFormWith = function(html){
_replaceIssueFormWith(html);
narrowChildField();
};
});