mangroveorg/datawinners

View on GitHub
datawinners/media/javascript/entity/questionnaire_helper.js

Summary

Maintainability
F
1 wk
Test Coverage

File questionnaire_helper.js has 643 lines of code (exceeds 250 allowed). Consider refactoring.
Open

//DW is the global name space for DataWinner
DW.init_inform_datasender_about_changes = function () {
    var kwargs = {container: "#inform_datasender_about_changes",
        is_continue: true,
        title: gettext('Inform Your Data Senders about the Changes'),
Severity: Major
Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 day to fix

    Function _init has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
    Open

        _init: function () {
            var self = this;
            var q = this.options;
            this.newly_added_question = ko.observable(q.newly_added_question);
            this.range_min = DW.ko.createValidatableObservable({value: q.range.min});
    Severity: Minor
    Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 day 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 _init has 208 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _init: function () {
            var self = this;
            var q = this.options;
            this.newly_added_question = ko.observable(q.newly_added_question);
            this.range_min = DW.ko.createValidatableObservable({value: q.range.min});
    Severity: Major
    Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 day to fix

      Function CancelQuestionnaireWarningDialog has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      DW.CancelQuestionnaireWarningDialog = function (options) {
          var self = this;
          var successCallBack = options.successCallBack;
          var isQuestionnaireModified = options.isQuestionnaireModified;
      
      
      Severity: Major
      Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 2 hrs to fix

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

                    read: function () {
                        if (this.isEntityQuestion() && this.max_length() == 20) {
                            return DW.instruction_template.short_code_question;
                        }
        
        
        Severity: Minor
        Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 hr to fix

          Function UniqueIdHelpSection has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          DW.UniqueIdHelpSection = function(){
          
              function _closeDialogHandler(){
                  $("#unique_id_learn_more_form").dialog('close');
              }
          Severity: Minor
          Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 hr to fix

            Function _initializeObservableValidations has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                _initializeObservableValidations: function () {
                    this.title.subscribe(function () {
                        DW.ko.mandatoryValidator(this.title);
                    }, this);
            
            
            Severity: Minor
            Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 hr to fix

              Function _initializeObservableValidations has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  _initializeObservableValidations: function () {
                      this.title.subscribe(function () {
                          DW.ko.mandatoryValidator(this.title);
                      }, this);
              
              
              Severity: Minor
              Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 hr 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 questionnaire_has_submission has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              DW.questionnaire_has_submission = function () {
                  var subject_questionnaire = (typeof(is_edit) == "undefined");
                  if (subject_questionnaire) {
                      var entity_type = $("#entity-type").val();
                      var url_get = $.sprintf("/questionnaire/entities/%s/", entity_type);
              Severity: Minor
              Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 1 hr to fix

                Function next_option_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                DW.next_option_value = function (lastChoice) {
                    var nextOption = "a";
                    if (lastChoice.charCodeAt(lastChoice.length - 1) == 122) {
                        if (lastChoice.length == 2) {
                            nextOption = String.fromCharCode(lastChoice.charCodeAt(0) + 1) + "a";
                Severity: Minor
                Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 35 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

                Avoid too many return statements within this function.
                Open

                                        return $.sprintf(DW.instruction_template.min_number, this.range_min());
                Severity: Major
                Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return "No instruction can be generated";
                  Severity: Major
                  Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                        return DW.instruction_template.unique_id;
                    Severity: Major
                    Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                              return $.sprintf(DW.instruction_template.range_number, this.range_min(), this.range_max());
                      Severity: Major
                      Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                            return $.sprintf(DW.instruction_template.date, DW.date_template[this.date_format()], DW.instruction_template[this.date_format()]);
                        Severity: Major
                        Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                                  return $.sprintf(DW.instruction_template.unique_id_type, this.uniqueIdType());
                          Severity: Major
                          Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                                    return DW.instruction_template.number;
                            Severity: Major
                            Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                                      return DW.instruction_template.number;
                              Severity: Major
                              Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                    return DW.instruction_template.multi_select;
                                Severity: Major
                                Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                                      return DW.instruction_template.text;
                                  Severity: Major
                                  Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                        return DW.instruction_template.gps;
                                    Severity: Major
                                    Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                          return DW.instruction_template.single_select;
                                      Severity: Major
                                      Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                                return $.sprintf(DW.instruction_template.max_number, this.range_max());
                                        Severity: Major
                                        Found in datawinners/media/javascript/entity/questionnaire_helper.js - About 30 mins to fix

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

                                              function _initializeDialog(dialogSection){
                                                  dialogSection.dialog({
                                                          autoOpen: false,
                                                          width: 940,
                                                          modal: true,
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 5 hrs to fix
                                          datawinners/media/javascript/project/submission_results.js on lines 228..245

                                          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 142.

                                          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

                                              bind_cancel_link: function () {
                                                  $(DW.option_warning_dialog.dialog_id + "_cancel").bind("click", function () {
                                                      $(DW.option_warning_dialog.dialog_id).dialog("close");
                                                      DW.option_warning_dialog.cancelEventHandler();
                                                      DW.hide_dialog_overlay();
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 2 hrs to fix
                                          datawinners/media/javascript/entity/questionnaire_helper.js on lines 509..515

                                          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 90.

                                          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

                                              bind_continue: function () {
                                                  $(DW.option_warning_dialog.dialog_id + "_continue").bind("click", function () {
                                                      $(DW.option_warning_dialog.dialog_id).dialog("close");
                                                      DW.option_warning_dialog.continueEventHandler();
                                                      DW.hide_dialog_overlay();
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 2 hrs to fix
                                          datawinners/media/javascript/entity/questionnaire_helper.js on lines 495..501

                                          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 90.

                                          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

                                                  $("#question-detail-panel").on('click', '#unique_id_learn_more_link', function(){
                                                      var dialogSection = $("#unique_id_learn_more_form");
                                                      _initializeDialog(dialogSection);
                                                      dialogSection.removeClass("none");
                                                      dialogSection.dialog("open");
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 1 hr to fix
                                          datawinners/media/javascript/project/submission_results.js on lines 248..254

                                          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 68.

                                          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.range_max.subscribe(function () {
                                          
                                                      if (!this.showAddRange())
                                                          return;
                                          
                                          
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 1 hr to fix
                                          datawinners/media/javascript/entity/questionnaire_helper.js on lines 384..391

                                          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 64.

                                          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.range_min.subscribe(function () {
                                                      if (!this.showAddRange())
                                                          return;
                                          
                                                      DW.ko.numericValidator(this.range_min);
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 1 hr to fix
                                          datawinners/media/javascript/entity/questionnaire_helper.js on lines 393..401

                                          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 64.

                                          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 (question_top < div_top + 15) {
                                                  var scrolltop = $("div.questions").scrollTop() - (div_top + 15 - question_top);
                                                  $("div.questions").scrollTop(scrolltop);
                                              }
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 1 hr to fix
                                          datawinners/media/javascript/data_tables/js/dwtable.js on lines 143..153

                                          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 60.

                                          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

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

                                              var _initializeDialog = function () {
                                                  self.cancelDialog.dialog({
                                                      title: gettext("You Have Unsaved Changes"),
                                                      modal: true,
                                                      autoOpen: false,
                                          Severity: Major
                                          Found in datawinners/media/javascript/entity/questionnaire_helper.js and 1 other location - About 1 hr to fix
                                          datawinners/media/javascript/common/form_edited_warning_dialog.js on lines 30..38

                                          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 57.

                                          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