Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linted most of the linty bits of app manager #35653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
hqDefine("app_manager/js/details/case_list_callout", function () {
var caseListLookupViewModel = function ($el, state, lang, saveButton) {
'use strict';
var self = {};
var detailType = $el.data('detail-type');

Expand Down Expand Up @@ -83,8 +82,7 @@ hqDefine("app_manager/js/details/case_list_callout", function () {
var $help = $this.siblings('.help-block');
$help.show();
errors.push($help.text());
}
else {
} else {
$this.closest('.form-group').removeClass('has-error');
$this.siblings('.help-block').hide();
}
Expand All @@ -95,21 +93,20 @@ hqDefine("app_manager/js/details/case_list_callout", function () {
var _validateExtras = function (errors) {
errors = errors || [];
var $extras = $el.find("." + detailType + "-extras"),
$extra_help = $extras.find(".help-block");
$extraHelp = $extras.find(".help-block");

if (!_trimmedExtras().length) {
$extras.addClass('has-error');
$extra_help.show();
errors.push($extra_help.text());
}
else {
$extraHelp.show();
errors.push($extraHelp.text());
} else {
$extras.removeClass('has-error');
$extra_help.hide();
$extraHelp.hide();
}
return errors;
};

var _validate_responses = function (errors) {
var _validateResponses = function (errors) {
errors = errors || [];
var $responses = $el.find("." + detailType + "-responses"),
$responseHelp = $responses.find(".help-block");
Expand All @@ -118,8 +115,7 @@ hqDefine("app_manager/js/details/case_list_callout", function () {
$responses.addClass('has-error');
$responseHelp.show();
errors.push($responseHelp.text());
}
else {
} else {
$responses.removeClass('has-error');
$responseHelp.hide();
}
Expand All @@ -136,13 +132,13 @@ hqDefine("app_manager/js/details/case_list_callout", function () {
if (self.lookup_enabled()) {
_validateInputs(errors);
_validateExtras(errors);
_validate_responses(errors);
_validateResponses(errors);
}

if (errors.length) {
var alert_user = hqImport("hqwebapp/js/bootstrap3/alert_user").alert_user;
var alertUser = hqImport("hqwebapp/js/bootstrap3/alert_user").alert_user;
_.each(errors, function (error) {
alert_user(error, "danger");
alertUser(error, "danger");
});
return false;
}
Expand Down Expand Up @@ -171,7 +167,8 @@ hqDefine("app_manager/js/details/case_list_callout", function () {
}

self.lookup_display_results = ko.observable(state.lookup_display_results);
var invisible = "", visible = "";
let invisible = "",
visible = "";
if (state.lookup_field_header[lang]) {
visible = invisible = state.lookup_field_header[lang];
} else {
Expand All @@ -195,17 +192,17 @@ hqDefine("app_manager/js/details/case_list_callout", function () {

self.show_add_extra = ko.computed(function () {
if (self.extras().length) {
var last_key = self.extras()[self.extras().length - 1].key(),
last_value = self.extras()[self.extras().length - 1].value();
return !(last_key === "" && last_value === "");
var lastKey = self.extras()[self.extras().length - 1].key(),
lastValue = self.extras()[self.extras().length - 1].value();
return !(lastKey === "" && lastValue === "");
}
return true;
});

self.show_add_response = ko.computed(function () {
if (self.responses().length) {
var last_key = self.responses()[self.responses().length - 1].key();
return last_key !== "";
var lastKey = self.responses()[self.responses().length - 1].key();
return lastKey !== "";
}
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ hqDefine("app_manager/js/forms/case_knockout_bindings", [
},
_truncateLabel: function (label, suffix, MAXLEN) {
suffix = suffix || "";
var MAXLEN = MAXLEN || 40,
maxlen = MAXLEN - suffix.length;
MAXLEN = MAXLEN || 40;
const maxlen = MAXLEN - suffix.length;
return ((label.length <= maxlen) ? (label) : (label.slice(0, maxlen) + "...")) + suffix;
},
_truncateValue: function (value, MAXLEN) {
Expand Down Expand Up @@ -95,8 +95,7 @@ hqDefine("app_manager/js/forms/case_knockout_bindings", [
var paperclip = '<i class="fa fa-paperclip"></i> ';
if (m.includes(paperclip)) {
m = m.replace(paperclip, '');
}
else {
} else {
paperclip = '';
}
return paperclip + DOMPurify.sanitize(m).replace(/</g, '&lt;').replace(/>/g, '&gt;');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
/* globals $ */
/* globals window */

hqDefine('app_manager/js/forms/edit_form_details', function () {
'use strict';
var module = {};

module.name = ko.observable();
module.comment = ko.observable();

var _updateCallbackFn = function (name, comment) {};

// Callback for when comment update is successful
// Arguments: name, comment
var _updateCallbackFn = function () {};

module.initName = function (name, url) {
module.name(name);
module.updateNameUrl = url;
};
module.initComment = function (comment, url) {

module.initComment = function (comment, url) {
module.comment(comment);
module.updateCommentUrl = url;
};

module.setUpdateCallbackFn = function (callbackFn) {
_updateCallbackFn = callbackFn;
};
Expand All @@ -30,13 +28,13 @@ hqDefine('app_manager/js/forms/edit_form_details', function () {
type: 'POST',
dataType: 'JSON',
data: { name: module.name() },
success: function (data) {
success: function () {
$.ajax({
url: module.updateCommentUrl,
type: 'POST',
dataType: 'JSON',
data: { comment: module.comment() },
success: function (data) {
success: function () {
_updateCallbackFn(module.name(), module.comment());
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals define, require, WS4Redis */
/* globals require, WS4Redis */
hqDefine("app_manager/js/forms/form_designer", function () {
var initialPageData = hqImport("hqwebapp/js/initial_page_data"),
appcues = hqImport('analytix/js/appcues'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ hqDefine("app_manager/js/managed_app", function () {
var that = this;
if ($langcodeInput) {
$langcodeInput.change(function () {
if ($(this).val() == "")
if ($(this).val() === "") {
$(that).show();
else
} else {
$(that).hide();
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ hqDefine("app_manager/js/modules/module_view", function () {
_.extend(detailScreenConfigOptions, options.search_config);
var detailScreenConfig = hqImport("app_manager/js/details/screen_config")(detailScreenConfigOptions);

var $list_home = $("#" + detail.type + "-detail-screen-config-tab");
$list_home.koApplyBindings(detailScreenConfig);
var $listHome = $("#" + detail.type + "-detail-screen-config-tab");
$listHome.koApplyBindings(detailScreenConfig);

if (detail.long !== undefined) {
var $detail_home = $("#" + detail.type + "-detail-screen-detail-config-tab");
$detail_home.koApplyBindings(detailScreenConfig);
var $detailHome = $("#" + detail.type + "-detail-screen-detail-config-tab");
$detailHome.koApplyBindings(detailScreenConfig);
}
}
}
Expand Down Expand Up @@ -166,9 +166,9 @@ hqDefine("app_manager/js/modules/module_view", function () {
});
}

var lazyloadCaseListFields = $('#lazy-load-case-list-fields')
var lazyloadCaseListFields = $('#lazy-load-case-list-fields');
if (lazyloadCaseListFields.length > 0) {
lazyloadCaseListFields.koApplyBindings({
lazyloadCaseListFields.koApplyBindings({
lazy_load_case_list_fields: ko.observable(initialPageData.get('lazy_load_case_list_fields')),
});
}
Expand Down Expand Up @@ -229,11 +229,11 @@ hqDefine("app_manager/js/modules/module_view", function () {

return self;
};
var case_list_form_options = initialPageData.get('case_list_form_options');
var caseListFormOptions = initialPageData.get('case_list_form_options');
var caseListForm = caseListFormModel(
case_list_form_options ? case_list_form_options.form.form_id : null,
case_list_form_options ? case_list_form_options.options : [],
case_list_form_options ? case_list_form_options.form.post_form_workflow : 'default'
caseListFormOptions ? caseListFormOptions.form.form_id : null,
caseListFormOptions ? caseListFormOptions.options : [],
caseListFormOptions ? caseListFormOptions.form.post_form_workflow : 'default'
);
$('#case-list-form').koApplyBindings(caseListForm);

Expand Down Expand Up @@ -277,16 +277,16 @@ hqDefine("app_manager/js/modules/module_view", function () {
setupValidation(initialPageData.reverse('validate_module_for_build'));

// show display style options only when module configured to show module and then forms
var $menu_mode = $('#put_in_root');
var $display_style_container = $('#display_style_container');
var update_display_view = function () {
if ($menu_mode.val() === 'false') {
$display_style_container.show();
var $menuMode = $('#put_in_root');
var $displayStyleContainer = $('#display_style_container');
var updateDisplayView = function () {
if ($menuMode.val() === 'false') {
$displayStyleContainer.show();
} else {
$display_style_container.hide();
$displayStyleContainer.hide();
}
};
update_display_view();
$menu_mode.on('change', update_display_view);
updateDisplayView();
$menuMode.on('change', updateDisplayView);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ hqDefine("app_manager/js/section_changer", function () {
// Determine if section should be shown or not, based on localStorage and given default
var shouldCollapse = function (page, section, defaultCollapse) {
var key = getKey(page, section);
return localStorage.hasOwnProperty(key) ? localStorage.getItem(key) : defaultCollapse;
return _.has(localStorage, key) ? localStorage.getItem(key) : defaultCollapse;
};

// Attach section changer UI to a form's save bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ hqDefine('app_manager/js/supported_languages',[
var i;
for (i = 0; i < langs.length; i++) {
if (langs[i] !== data[i]) {
throw "There was an error saving.";
throw new Error("There was an error saving.");
}
}
self.removedLanguages.removeAll();
Expand Down
28 changes: 13 additions & 15 deletions corehq/apps/app_manager/static/app_manager/js/visit_scheduler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*globals $, _, ko, console, hqImport */
hqDefine('app_manager/js/visit_scheduler', function () {
'use strict';
var app_manager = hqImport('app_manager/js/app_manager');
var appManager = hqImport('app_manager/js/app_manager');
var caseConfigUtils = hqImport('app_manager/js/case_config_utils');
var moduleScheduler = function (params) {
// Edits the schedule phases on the module setting page
Expand Down Expand Up @@ -40,7 +38,7 @@ hqDefine('app_manager/js/visit_scheduler', function () {
},
dataType: 'json',
success: function (data) {
app_manager.updateDOM(data.update);
appManager.updateDOM(data.update);
},
});
},
Expand Down Expand Up @@ -71,7 +69,7 @@ hqDefine('app_manager/js/visit_scheduler', function () {
return phaseModel(phase.id, phase.anchor, phase.forms);
})
);
self.phases.subscribe(function (phase) {
self.phases.subscribe(function () {
self.change();
});

Expand Down Expand Up @@ -122,7 +120,7 @@ hqDefine('app_manager/js/visit_scheduler', function () {
},
dataType: 'json',
success: function (data) {
app_manager.updateDOM(data.update);
appManager.updateDOM(data.update);
},
});
}
Expand All @@ -142,15 +140,15 @@ hqDefine('app_manager/js/visit_scheduler', function () {

self.validate = function () {
var errors = 0;
var $add_visit_button = self.home.find("#add-visit");
var $addVisitButton = self.home.find("#add-visit");

if (self.formSchedule.visits().length === 0) {
$add_visit_button.closest(".form-group").addClass("has-error");
$add_visit_button.siblings(".error-text").show();
$addVisitButton.closest(".form-group").addClass("has-error");
$addVisitButton.siblings(".error-text").show();
errors += 1;
} else {
$add_visit_button.closest(".form-group").removeClass("has-error");
$add_visit_button.siblings(".error-text").hide();
$addVisitButton.closest(".form-group").removeClass("has-error");
$addVisitButton.siblings(".error-text").hide();
}

var required = self.home.find(":required").not(":disabled");
Expand Down Expand Up @@ -200,7 +198,7 @@ hqDefine('app_manager/js/visit_scheduler', function () {
};

var scheduleRelevancy = {
mapping: function (self) {
mapping: function () {
return {
include: [
'starts',
Expand All @@ -224,7 +222,7 @@ hqDefine('app_manager/js/visit_scheduler', function () {
};

var scheduleVisit = {
mapping: function (self) {
mapping: function () {
return {
include: [
'due',
Expand Down Expand Up @@ -255,14 +253,14 @@ hqDefine('app_manager/js/visit_scheduler', function () {
};

var schedulePhase = {
mapping: function (self) {
mapping: function () {
return {
include: [
'anchor',
],
};
},
wrap: function (data, config) {
wrap: function (data) {
var self = {};
ko.mapping.fromJS(data, schedulePhase.mapping(self), self);
return self;
Expand Down
Loading
Loading