divio/django-cms

View on GitHub
cms/static/cms/js/modules/cms.modal.js

Summary

Maintainability
F
1 wk
Test Coverage

File cms.modal.js has 743 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright https://github.com/divio/django-cms
 */

import ChangeTracker from './cms.changetracker';
Severity: Major
Found in cms/static/cms/js/modules/cms.modal.js - About 1 day to fix

    Function _loadIframe has 160 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _loadIframe(opts) {
            var that = this;
            const SHOW_LOADER_TIMEOUT = 500;
    
            opts.url = Helpers.makeURL(opts.url);
    Severity: Major
    Found in cms/static/cms/js/modules/cms.modal.js - About 6 hrs to fix

      Function _setButtons has 105 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _setButtons(iframe) {
              var djangoSuit = iframe.contents().find('.suit-columns').length > 0;
              var that = this;
              var group = $('<div class="cms-modal-item-buttons"></div>');
              var render = $('<div class="cms-modal-buttons-inner"></div>');
      Severity: Major
      Found in cms/static/cms/js/modules/cms.modal.js - About 4 hrs to fix

        Modal has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Modal {
            constructor(options) {
                this.options = $.extend(true, {}, Modal.options, options);
        
                // elements
        Severity: Minor
        Found in cms/static/cms/js/modules/cms.modal.js - About 2 hrs to fix

          Function open has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              open(opts) {
                  // setup internals
                  if (!((opts && opts.url) || (opts && opts.html))) {
                      throw new Error('The arguments passed to "open" were invalid.');
                  }
          Severity: Minor
          Found in cms/static/cms/js/modules/cms.modal.js - About 1 hr to fix

            Function _show has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                _show(opts) {
                    // we need to position the modal in the center
                    var that = this;
                    var width = opts.width;
                    var height = opts.height;
            Severity: Minor
            Found in cms/static/cms/js/modules/cms.modal.js - About 1 hr to fix

              Function _calculateNewPosition has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  _calculateNewPosition(opts) {
                      // lets set the modal width and height to the size of the browser
                      var widthOffset = 300; // adds margin left and right
                      var heightOffset = 300; // adds margin top and bottom;
                      var screenWidth = this.ui.window.width();
              Severity: Minor
              Found in cms/static/cms/js/modules/cms.modal.js - About 1 hr to fix

                Function _events has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    _events() {
                        var that = this;
                
                        // modal behaviours
                        this.ui.minimizeButton
                Severity: Minor
                Found in cms/static/cms/js/modules/cms.modal.js - About 1 hr to fix

                  Function _startResize has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      _startResize(pointerEvent) {
                          // cancel if in fullscreen
                          if (this.maximized) {
                              return false;
                          }
                  Severity: Minor
                  Found in cms/static/cms/js/modules/cms.modal.js - About 1 hr to fix

                    Function _calculateNewPosition has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        _calculateNewPosition(opts) {
                            // lets set the modal width and height to the size of the browser
                            var widthOffset = 300; // adds margin left and right
                            var heightOffset = 300; // adds margin top and bottom;
                            var screenWidth = this.ui.window.width();
                    Severity: Minor
                    Found in cms/static/cms/js/modules/cms.modal.js - About 55 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function open has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        open(opts) {
                            // setup internals
                            if (!((opts && opts.url) || (opts && opts.html))) {
                                throw new Error('The arguments passed to "open" were invalid.');
                            }
                    Severity: Minor
                    Found in cms/static/cms/js/modules/cms.modal.js - About 45 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                            this.ui.maximizeButton
                                .off(this.click + ' ' + this.touchEnd + ' ' + this.keyUp)
                                .on(this.click + ' ' + this.touchEnd + ' ' + this.keyUp, function(e) {
                                    if (e.type !== 'keyup' || (e.type === 'keyup' && e.keyCode === KEYS.ENTER)) {
                                        e.preventDefault();
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 2 other locations - About 5 hrs to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 88..95
                    cms/static/cms/js/modules/cms.modal.js on lines 118..125

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 152.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                            this.ui.closeAndCancel
                                .off(this.click + ' ' + this.touchEnd + ' ' + this.keyUp)
                                .on(this.click + ' ' + this.touchEnd + ' ' + this.keyUp, function(e) {
                                    if (e.type !== 'keyup' || (e.type === 'keyup' && e.keyCode === KEYS.ENTER)) {
                                        e.preventDefault();
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 2 other locations - About 5 hrs to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 88..95
                    cms/static/cms/js/modules/cms.modal.js on lines 96..103

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 152.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                            this.ui.minimizeButton
                                .off(this.click + ' ' + this.touchEnd + ' ' + this.keyUp)
                                .on(this.click + ' ' + this.touchEnd + ' ' + this.keyUp, function(e) {
                                    if (e.type !== 'keyup' || (e.type === 'keyup' && e.keyCode === KEYS.ENTER)) {
                                        e.preventDefault();
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 2 other locations - About 5 hrs to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 96..103
                    cms/static/cms/js/modules/cms.modal.js on lines 118..125

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 152.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                                    body.on('keydown.cms', function(e) {
                                        if (e.keyCode === KEYS.ESC && that.options.closeOnEsc) {
                                            e.stopPropagation();
                                            if (that._confirmDirtyEscCancel()) {
                                                that._cancelHandler();
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 359..366

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 74.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            this.ui.body.off('keydown.cms.close').on('keydown.cms.close', function(e) {
                                if (e.keyCode === KEYS.ESC && that.options.closeOnEsc) {
                                    e.stopPropagation();
                                    if (that._confirmDirtyEscCancel()) {
                                        that._cancelHandler();
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 1053..1060

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 74.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        _stopMove() {
                            this.ui.shim.hide();
                            this.ui.body.off(this.pointerMove + ' ' + this.pointerUp).removeAttr('data-touch-action');
                        }
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 625..628

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 73.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        _stopResize() {
                            this.ui.shim.hide();
                            this.ui.body.off(this.pointerMove + ' ' + this.pointerUp).removeAttr('data-touch-action');
                        }
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 555..558

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 73.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            this.ui.title.off(this.pointerDown).on(this.pointerDown, function(e) {
                                e.preventDefault();
                                that._startMove(e);
                            });
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 113..116

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 63.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            this.ui.resize.off(this.pointerDown).on(this.pointerDown, function(e) {
                                e.preventDefault();
                                that._startResize(e);
                            });
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 105..108

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 63.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                                        if (e.keyCode === KEYS.CMD_LEFT || e.keyCode === KEYS.CMD_RIGHT || e.keyCode === KEYS.CMD_FIREFOX) {
                                            cmdPressed = true;
                                        }
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 1224..1226

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 58.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                                        if (e.keyCode === KEYS.CMD_LEFT || e.keyCode === KEYS.CMD_RIGHT || e.keyCode === KEYS.CMD_FIREFOX) {
                                            cmdPressed = false;
                                        }
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.modal.js on lines 1213..1215

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 58.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                            this.ui.title.off(this.doubleClick).on(this.doubleClick, function() {
                                that.maximize();
                            });
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.modal.js and 2 other locations - About 45 mins to fix
                    cms/static/cms/js/modules/cms.sideframe.js on lines 78..80
                    cms/static/cms/js/modules/cms.sideframe.js on lines 83..85

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 50.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status