Issues (3)

CustomOperatorFlags.js (3 issues)

1
/** global: VRS */
2
    if(VRS && VRS.globalDispatch && VRS.serverConfig) {
3
        VRS.globalDispatch.hook(VRS.globalEvent.bootstrapCreated, function(bootStrap) {
0 ignored issues
show
The parameter bootStrap 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...
4
            if(VRS.renderPropertyHandlers) {
5
                VRS.renderPropertyHandlers[VRS.RenderProperty.OperatorFlag] = new VRS.RenderPropertyHandler({
6
                    property:               VRS.RenderProperty.OperatorFlag,
7
                    surfaces:               VRS.RenderSurface.List + VRS.RenderSurface.DetailHead + VRS.RenderSurface.InfoWindow,
8
                    headingKey:             'ListOperatorFlag',
9
                    labelKey:               'OperatorFlag',
10
                    sortableField:          VRS.AircraftListSortableField.OperatorIcao,
11
                    headingAlignment:       VRS.Alignment.Centre,
12
                    suppressLabelCallback:  function() { return true; },
13
                    fixedWidth:             function() { return VRS.globalOptions.aircraftOperatorFlagSize.width.toString() + 'px'; },
14
                    hasChangedCallback:     function(aircraft) { return aircraft.operatorIcao.chg || aircraft.icao.chg || aircraft.registration.chg || aircraft.manufacturer.chg; },
15
                    renderCallback:         function(aircraft) { return customFormatOperatorIcaoImageHtmlAircraft(aircraft); },
16
                    tooltipChangedCallback: function(aircraft) { return aircraft.operatorIcao.chg || aircraft.operator.chg; },
17
                    tooltipCallback:        function(aircraft) { return aircraft.formatOperatorIcaoAndName(); }
18
                });
19
20
                VRS.renderPropertyHandlers[VRS.RenderProperty.SilhouetteAndOpFlag] = new VRS.RenderPropertyHandler({
21
                    property:               VRS.RenderProperty.SilhouetteAndOpFlag,
22
                    surfaces:               VRS.RenderSurface.List,
23
                    headingKey:             'ListModelSilhouetteAndOpFlag',
24
                    labelKey:               'SilhouetteAndOpFlag',
25
                    headingAlignment:       VRS.Alignment.Centre,
26
                    sortableField:          VRS.AircraftListSortableField.OperatorIcao,
27
                    fixedWidth:             function() { return Math.max(VRS.globalOptions.aircraftSilhouetteSize.width, VRS.globalOptions.aircraftOperatorFlagSize.width).toString() + 'px'; },
28
                    // Changed the following line to include manufacturer
29
                    hasChangedCallback:     function(aircraft) { return aircraft.modelIcao.chg || aircraft.operatorIcao.chg || aircraft.registration.chg || aircraft.manufacturer.chg; },
30
                    // And this line to include a call to the custom HTML
31
                    renderCallback:         function(aircraft) { return aircraft.formatModelIcaoImageHtml() + customFormatOperatorIcaoImageHtmlAircraft(aircraft); },
32
                    tooltipChangedCallback: function(aircraft) { return aircraft.model.chg || aircraft.modelIcao.chg || aircraft.countEngines.chg || aircraft.engineType.chg || aircraft.species.chg || aircraft.wakeTurbulenceCat.chg || aircraft.operatorIcao.chg || aircraft.operator.chg; },
33
                    tooltipCallback:        function(aircraft) {
34
                        var silhouetteTooltip = aircraft.formatModelIcaoNameAndDetail();
35
                        var opFlagTooltip = aircraft.formatOperatorIcaoAndName();
36
                        return silhouetteTooltip && opFlagTooltip ? silhouetteTooltip + '. ' + opFlagTooltip : silhouetteTooltip ? silhouetteTooltip : opFlagTooltip;
37
                    }
38
                });
39
            }
40
            
41
            if(VRS.reportPropertyHandlers) {
42
                VRS.reportPropertyHandlers[VRS.ReportAircraftProperty.OperatorFlag] = new VRS.ReportPropertyHandler({
43
                    property:           VRS.ReportAircraftProperty.OperatorFlag,
44
                    surfaces:           VRS.ReportSurface.List + VRS.ReportSurface.DetailHead,
45
                    headingKey:         'ListOperatorFlag',
46
                    labelKey:           'OperatorFlag',
47
                    headingAlignment:   VRS.Alignment.Centre,
48
                    fixedWidth:         function() { return VRS.globalOptions.aircraftOperatorFlagSize.width.toString() + 'px'; },
49
                    hasValue:           function(/** VRS_JSON_REPORT_AIRCRAFT */ json) { return !!json.opFlag || !!json.icao || !!json.reg || !!json.manufacturer; },
50
                    renderCallback:     function(/** VRS_JSON_REPORT_AIRCRAFT */ json) { return customFormatOperatorIcaoImageHtml(json.manufacturer, json.opFlag, json.reg, json.icao); },
51
                    tooltipCallback:    function(/** VRS_JSON_REPORT_AIRCRAFT */ json) { return VRS.format.operatorIcaoAndName(json.owner, json.opFlag); }
52
                });
53
            }
54
        });
55
    }
56
    
57
    function customFormatOperatorIcaoImageHtmlAircraft(aircraft)
58
    {
59
        return customFormatOperatorIcaoImageHtml(aircraft.manufacturer.val, aircraft.operatorIcao.val, aircraft.registration.val, aircraft.icao.val);
60
    }
61
    
62
    function customFormatOperatorIcaoImageHtml(manufacturer, operatorIcao, registration, icao)
63
    {
64
        var codeToUse = '';
65
        codeToUse = customPipeSeparatedCode(codeToUse, registration);        
66
        codeToUse = customPipeSeparatedCode(codeToUse, operatorIcao);
67
        codeToUse = customPipeSeparatedCode(codeToUse, icao);
68
	codeToUse = customPipeSeparatedCode(codeToUse, manufacturer);
69
70
        var size = VRS.globalOptions.aircraftOperatorFlagSize;
71
        var result = '<img src="images/File-' + encodeURIComponent(codeToUse);
72
        if(VRS.browserHelper.isHighDpi()) result += '/HiDpi';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
73
        result += '/OpFlag.png"' +
74
            ' width="' + size.width.toString() + 'px"' +
75
            ' height="' + size.height.toString() + 'px"' +
76
            ' />';
77
78
        return result;
79
    }
80
81
////////
82
    
83
    function customPipeSeparatedCode(text, code)
84
    {
85
        var result = text;        
86
        if(code && code.length) {
87
            if(result.length) result += '|';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
88
            result += code;
89
        }
90
        return result;
91
    }
92