1
|
/*
|
2
|
* This file should only contain functions that will be used on more than 2 pages
|
3
|
*/
|
4
|
|
5
|
$(function() {
|
6
|
// Run in-page defined events
|
7
|
var runEvents = function()
|
8
|
{
|
9
|
while (func = window.events.shift())
|
10
|
func();
|
11
|
};
|
12
|
|
13
|
// Attach collapsable behaviour to select options
|
14
|
var bindCollapseToOptions = function()
|
15
|
{
|
16
|
var selects = $('select[data-toggle="collapse"]');
|
17
|
|
18
|
selects.on('change', function(){
|
19
|
var options = $(this).find('option');
|
20
|
var selectedValue = $(this).find(':selected').val();
|
21
|
|
22
|
// Hide related collapsables which are visible (.in)
|
23
|
options.each(function(){
|
24
|
if ($(this).val() == selectedValue)
|
25
|
return;
|
26
|
|
27
|
$('.toggle-' + $(this).val() + '.in').collapse('hide');
|
28
|
|
29
|
// Disable all invisible inputs
|
30
|
$('.toggle-' + $(this).val()).find('input,select,textarea').prop('disabled', true);
|
31
|
});
|
32
|
|
33
|
$('.toggle-' + selectedValue).collapse('show').find('input,select,textarea').prop('disabled', false);
|
34
|
});
|
35
|
|
36
|
// Trigger change to open currently selected item
|
37
|
selects.trigger('change');
|
38
|
};
|
39
|
|
40
|
// Add +/- buttons to certain Groups; to allow adding multiple entries
|
41
|
var allowUserGroupDuplication = function()
|
42
|
{
|
43
|
var groups = $('div.form-group.user-duplication');
|
44
|
var plus = $('<a><i class="icon icon-plus"></i></a>');
|
45
|
var minus = $('<a><i class="icon icon-minus"></i></a>')
|
46
|
|
47
|
minus.on('click', function(){
|
48
|
$(this).parent('div.form-group').remove();
|
49
|
});
|
50
|
|
51
|
plus.on('click', function(){
|
52
|
var group = $(this).parent('div.form-group');
|
53
|
|
54
|
var clone = group.clone(true);
|
55
|
clone.find('*').removeAttr('value');
|
56
|
clone.appendTo(group.parent());
|
57
|
});
|
58
|
|
59
|
groups.each(function(idx, group){
|
60
|
minus.clone(true).appendTo(group);
|
61
|
|
62
|
if (group == group.parentNode.lastElementChild)
|
63
|
plus.clone(true).appendTo(group);
|
64
|
})
|
65
|
};
|
66
|
|
67
|
// Enable popovers globally
|
68
|
$('[data-toggle="popover"]').popover()
|
69
|
|
70
|
// Focus first input
|
71
|
$(':input:enabled:visible:first').focus();
|
72
|
|
73
|
runEvents();
|
74
|
bindCollapseToOptions();
|
75
|
allowUserGroupDuplication();
|
76
|
});
|