Completed
Push — master ( 2fb092...058edd )
by Craig
06:38
created

  B

Complexity

Conditions 4
Paths 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A ZikulaRoutesModule.js ➔ ... ➔ quickNavForm.change 0 3 1
1
'use strict';
2
3
function zikulaRoutesCapitaliseFirstLetter(string)
4
{
5
    return string.charAt(0).toUpperCase() + string.substring(1);
6
}
7
8
/**
9
 * Initialise the quick navigation panel in list views.
10
 */
11
function zikulaRoutesInitQuickNavigation()
12
{
13
    var quickNavForm;
14
    var objectType;
15
16
    if (jQuery('.zikularoutesmodule-quicknav').length < 1) {
17
        return;
18
    }
19
20
    quickNavForm = jQuery('.zikularoutesmodule-quicknav').first();
21
    objectType = quickNavForm.attr('id').replace('zikulaRoutesModule', '').replace('QuickNavForm', '');
22
23
    quickNavForm.find('select').change(function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
24
        quickNavForm.submit();
25
    });
26
27
    var fieldPrefix = 'zikularoutesmodule_' + objectType.toLowerCase() + 'quicknav_';
28
    // we can hide the submit button if we have no visible quick search field
29
    if (jQuery('#' + fieldPrefix + 'q').length < 1 || jQuery('#' + fieldPrefix + 'q').parent().parent().hasClass('hidden')) {
30
        jQuery('#' + fieldPrefix + 'updateview').addClass('hidden');
31
    }
32
}
33
34
/**
35
 * Simulates a simple alert using bootstrap.
36
 */
37
function zikulaRoutesSimpleAlert(beforeElem, title, content, alertId, cssClass)
38
{
39
    var alertBox;
40
41
    alertBox = ' \
42
        <div id="' + alertId + '" class="alert alert-' + cssClass + ' fade"> \
43
          <button type="button" class="close" data-dismiss="alert">&times;</button> \
44
          <h4>' + title + '</h4> \
45
          <p>' + content + '</p> \
46
        </div>';
47
48
    // insert alert before the given element
49
    beforeElem.before(alertBox);
50
51
    jQuery('#' + alertId).delay(200).addClass('in').fadeOut(4000, function () {
52
        jQuery(this).remove();
53
    });
54
}
55
56
/**
57
 * Initialises the mass toggle functionality for admin view pages.
58
 */
59
function zikulaRoutesInitMassToggle()
60
{
61
    if (jQuery('.zikularoutes-mass-toggle').length > 0) {
62
        jQuery('.zikularoutes-mass-toggle').click(function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
63
            jQuery('.zikularoutes-toggle-checkbox').prop('checked', jQuery(this).prop('checked'));
64
        });
65
    }
66
}
67
68
/**
69
 * Creates a dropdown menu for the item actions.
70
 */
71
function zikulaRoutesInitItemActions(context)
72
{
73
    var containerSelector;
74
    var containers;
75
    var listClasses;
76
77
    containerSelector = '';
78
    if (context == 'view') {
79
        containerSelector = '.zikularoutesmodule-view';
80
        listClasses = 'list-unstyled dropdown-menu dropdown-menu-right';
81
    } else if (context == 'display') {
82
        containerSelector = 'h2, h3';
83
        listClasses = 'list-unstyled dropdown-menu';
84
    }
85
86
    if (containerSelector == '') {
87
        return;
88
    }
89
90
    containers = jQuery(containerSelector);
91
    if (containers.length < 1) {
92
        return;
93
    }
94
95
    containers.find('.dropdown > ul').removeClass('list-inline').addClass(listClasses);
0 ignored issues
show
Bug introduced by
The variable listClasses does not seem to be initialized in case context == "display" on line 81 is false. Are you sure the function addClass handles undefined variables?
Loading history...
96
    containers.find('.dropdown > ul a').each(function (index) {
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
97
        jQuery(this).html(jQuery(this).html() + jQuery(this).find('i').first().data('original-title'));
98
    });
99
    containers.find('.dropdown > ul a i').addClass('fa-fw');
100
    containers.find('.dropdown-toggle').removeClass('hidden').dropdown();
101
}
102
103
jQuery(document).ready(function() {
104
    var isViewPage;
105
    var isDisplayPage;
106
107
    isViewPage = jQuery('.zikularoutesmodule-view').length > 0;
108
    isDisplayPage = jQuery('.zikularoutesmodule-display').length > 0;
109
110
    if (isViewPage) {
111
        zikulaRoutesInitQuickNavigation();
112
        zikulaRoutesInitMassToggle();
113
        zikulaRoutesInitItemActions('view');
114
    } else if (isDisplayPage) {
115
        zikulaRoutesInitItemActions('display');
116
    }
117
});
118