app/assets/javascripts/dradis/plugins/calculators/cvss/calculator.js.coffee in dradis-calculator_cvss-4.0.0 vs app/assets/javascripts/dradis/plugins/calculators/cvss/calculator.js.coffee in dradis-calculator_cvss-4.1.0

- old
+ new

@@ -1,7 +1,14 @@ -@CVSSCalculator = - calculate: -> +class CVSSCalculator + constructor: -> + $('[data-cvss]').each (_, item)=> + title = $(item).data('cvss') + $(item).attr('title', @cvssHelp.helpText_en[title]) + + @calculate() + + calculate: => av = $("input[name=av]").val() ac = $("input[name=ac]").val() pr = $("input[name=pr]").val() ui = $("input[name=ui]").val() s = $("input[name=s]").val() @@ -29,11 +36,11 @@ # Confidentiality, Integrity, Availability, Exploitability, RemediationLevel, # ReportConfidence, ConfidentialityRequirement, IntegrityRequirement, # AvailabilityRequirement, ModifiedAttackVector, ModifiedAttackComplexity, # ModifiedPrivilegesRequired, ModifiedUserInteraction, ModifiedScope, # ModifiedConfidentiality, ModifiedIntegrity, ModifiedAvailability - output = CVSS.calculateCVSSFromMetrics(av, ac, pr, ui, s, c, i, a, + output = @calc.calculateCVSSFromMetrics(av, ac, pr, ui, s, c, i, a, e, rl, rc, cr, ir, ar, mav, mac, mpr, mui, ms, mc, mi, ma); if output.success == true @@ -119,17 +126,40 @@ errorMessage = "All Base metrics are required" $('input[type=submit]').attr('disabled', 'disabled') $('[data-behavior~=cvss-error]').removeClass('d-none').text(errorMessage) +class CVSS30Calculator extends CVSSCalculator + constructor: -> + @calc = CVSS + @cvssHelp = CVSS_Help + + super() + +class CVSS31Calculator extends CVSSCalculator + constructor: -> + @calc = CVSS31 + @cvssHelp = CVSS31_Help + + super() + document.addEventListener "turbolinks:load", -> if $('[data-behavior~=cvss-buttons]').length - CVSSCalculator.calculate() + if $('[data-behavior~=cvss-version-toggle]').prop('checked') + window.calculator = new CVSS30Calculator() + else + window.calculator = new CVSS31Calculator() + $('[data-behavior~=cvss-error]').addClass('d-none') $('[data-behavior~=cvss-buttons] button').on 'click', -> - $this = $(this) - $this.parent().find('button').removeClass('active btn-primary'); - $this.addClass('active btn-primary'); + $this.parent().find('button').removeClass('active btn-primary') + $this.addClass('active btn-primary') $("input[name=#{$this.attr('name')}]").val($this.val()) - CVSSCalculator.calculate() + window.calculator.calculate() + + $('[data-behavior~=cvss-version-toggle]').on 'change', -> + if $('[data-behavior~=cvss-version-toggle]').prop('checked') + window.calculator = new CVSS30Calculator() + else + window.calculator = new CVSS31Calculator()