diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js.erb similarity index 97% rename from app/assets/javascripts/application.js rename to app/assets/javascripts/application.js.erb index e0dc620ee..a4319f77e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js.erb @@ -194,9 +194,9 @@ function notificationAlertClose(){ $(document).ready(function(){ $('.tree-link a').each( function(){ - truncateLongString( $(this), NAME_TRUNCATION_LENGTH); + truncateLongString( $(this), <%= Constants::NAME_TRUNCATION_LENGTH %>); }); $(".tree-link span").each( function(){ - truncateLongString( $(this), NAME_TRUNCATION_LENGTH); + truncateLongString( $(this), <%= Constants::NAME_TRUNCATION_LENGTH %>); }); }); diff --git a/app/assets/javascripts/my_modules/results.js b/app/assets/javascripts/my_modules/results.js.erb similarity index 94% rename from app/assets/javascripts/my_modules/results.js rename to app/assets/javascripts/my_modules/results.js.erb index 2bfd3b6b1..c024550f0 100644 --- a/app/assets/javascripts/my_modules/results.js +++ b/app/assets/javascripts/my_modules/results.js.erb @@ -192,7 +192,8 @@ function processResult(ev, resultTypeEnum, editMode, forS3) { switch(resultTypeEnum) { case ResultTypeEnum.FILE: var $nameInput = $form.find("#result_name"); - var nameValid = textValidator(ev, $nameInput, 0, NAME_MAX_LENGTH); + var nameValid = textValidator(ev, $nameInput, 0, + <%= Constants::NAME_MAX_LENGTH %>); var $fileInput = $form.find("#result_asset_attributes_file"); var filesValid = filesValidator(ev, $fileInput, FileTypeEnum.FILE, editMode); @@ -210,17 +211,20 @@ function processResult(ev, resultTypeEnum, editMode, forS3) { break; case ResultTypeEnum.TABLE: var $nameInput = $form.find("#result_name"); - var nameValid = textValidator(ev, $nameInput, 0, NAME_MAX_LENGTH); + var nameValid = textValidator(ev, $nameInput, 0, + <%= Constants::NAME_MAX_LENGTH %>); break; case ResultTypeEnum.TEXT: var $nameInput = $form.find("#result_name"); - var nameValid = textValidator(ev, $nameInput, 0, NAME_MAX_LENGTH); + var nameValid = textValidator(ev, $nameInput, 0, + <%= Constants::NAME_MAX_LENGTH %>); var $textInput = $form.find("#result_result_text_attributes_text"); - textValidator(ev, $textInput, 1, TEXT_MAX_LENGTH); + textValidator(ev, $textInput, 1, <%= Constants::TEXT_MAX_LENGTH %>); break; case ResultTypeEnum.COMMENT: var $commentInput = $form.find("#comment_message"); - var commentValid = textValidator(ev, $commentInput, 1, TEXT_MAX_LENGTH); + var commentValid = textValidator(ev, $commentInput, 1, + <%= Constants::TEXT_MAX_LENGTH %>); break; } } diff --git a/app/assets/javascripts/projects/canvas.js b/app/assets/javascripts/projects/canvas.js.erb similarity index 99% rename from app/assets/javascripts/projects/canvas.js rename to app/assets/javascripts/projects/canvas.js.erb index f8b096eb6..31ff3ab11 100644 --- a/app/assets/javascripts/projects/canvas.js +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -4,11 +4,6 @@ // CONSTANTS //************************************ -var NAME_VALID = 0; -var NAME_LENGTH_ERROR = -1; -var NAME_INVALID_CHARACTERS_ERROR = -2; -var NAME_WHITESPACES_ERROR = -3; - var DRAG_INVALID = 0; var DRAG_MOUSE = 1; var DRAG_TOUCH = 2; @@ -1438,8 +1433,9 @@ function bindNewModuleAction(gridDistX, gridDistY) { function handleNewNameConfirm(ev) { var input = $("#new-module-name-input"); // Validate module name - var moduleNameValid = textValidator(ev, input, NAME_MIN_LENGTH, - NAME_MAX_LENGTH, true); + var moduleNameValid = textValidator(ev, input, + <%= Constants::NAME_MIN_LENGTH %>, <%= Constants::NAME_MAX_LENGTH %>, + true); if (moduleNameValid) { // Set the "clicked" property to true modal.data("submit", "true"); @@ -1528,8 +1524,9 @@ function initEditModules() { function handleRenameConfirm(modal, ev) { var input = modal.find("#edit-module-name-input"); // Validate module name - var moduleNameValid = textValidator(ev, input, NAME_MIN_LENGTH, - NAME_MAX_LENGTH, true); + var moduleNameValid = textValidator(ev, input, + <%= Constants::NAME_MIN_LENGTH %>, <%= Constants::NAME_MAX_LENGTH %>, + true); if (moduleNameValid) { var newName = input.val(); var moduleId = modal.attr("data-module-id"); @@ -1636,7 +1633,8 @@ function initEditModuleGroups() { function handleRenameConfirm(modal, ev) { var input = modal.find("#edit-module-group-name-input"); // Validate module group name - var moduleNameValid = textValidator(ev, input, 1, NAME_MAX_LENGTH, true); + var moduleNameValid = textValidator(ev, input, 1, + <%= Constants::NAME_MAX_LENGTH %>, true); if (moduleNameValid) { var newModuleGroupName = input.val(); var moduleId = modal.attr("data-module-id"); diff --git a/app/assets/javascripts/protocols/header.js b/app/assets/javascripts/protocols/header.js.erb similarity index 97% rename from app/assets/javascripts/protocols/header.js rename to app/assets/javascripts/protocols/header.js.erb index 2686bdc3c..de0fc30f3 100644 --- a/app/assets/javascripts/protocols/header.js +++ b/app/assets/javascripts/protocols/header.js.erb @@ -88,11 +88,11 @@ function initEditKeywords() { // Init tagsinput & typeahead input.tagsinput({ - maxChars: NAME_MAX_LENGTH, + maxChars: <%= Constants::NAME_MAX_LENGTH %>, trimValue: true, typeaheadjs: { highlight: true, - minLength: NAME_MIN_LENGTH, + minLength: <%= Constants::NAME_MIN_LENGTH %>, name: "keywords", source: keywordsEngine } @@ -193,4 +193,4 @@ initEditName(); initEditKeywords(); initEditAuthors(); initEditDescription(); -initModalSubmitAndHide(); \ No newline at end of file +initModalSubmitAndHide(); diff --git a/app/assets/javascripts/protocols/import_export/import.js b/app/assets/javascripts/protocols/import_export/import.js.erb similarity index 99% rename from app/assets/javascripts/protocols/import_export/import.js rename to app/assets/javascripts/protocols/import_export/import.js.erb index 5246829ed..1ff9df895 100644 --- a/app/assets/javascripts/protocols/import_export/import.js +++ b/app/assets/javascripts/protocols/import_export/import.js.erb @@ -497,7 +497,7 @@ function importProtocolFromFile( $.extend(data_json, params); var rough_size = roughSizeOfObject(data_json); - if (rough_size > FILE_MAX_SIZE_B) { + if (rough_size > <%= Constants::FILE_MAX_SIZE_MB.megabytes %>) { // Call the callback function resultCallback({ name: protocolJson["name"], new_name: null, status: "size_too_large" }); return; diff --git a/app/assets/javascripts/protocols/steps.js b/app/assets/javascripts/protocols/steps.js.erb similarity index 98% rename from app/assets/javascripts/protocols/steps.js rename to app/assets/javascripts/protocols/steps.js.erb index 000a241eb..c5976319b 100644 --- a/app/assets/javascripts/protocols/steps.js +++ b/app/assets/javascripts/protocols/steps.js.erb @@ -497,9 +497,11 @@ function processStep(ev, editMode, forS3) { var $checklists = $form.find(".nested_step_checklists"); var checklistsValid = checklistsValidator(ev, $checklists, editMode); var $nameInput = $form.find("#step_name"); - var nameValid = textValidator(ev, $nameInput, 1, NAME_MAX_LENGTH); + var nameValid = textValidator(ev, $nameInput, 1, + <%= Constants::NAME_MAX_LENGTH %>); var $descrTextarea = $form.find("#step_description"); - var descriptionValid = textValidator(ev, $descrTextarea, 0, TEXT_MAX_LENGTH); + var descriptionValid = textValidator(ev, $descrTextarea, 0, + <%= Constants::TEXT_MAX_LENGTH %>); if (filesValid && checklistsValid && nameValid && descriptionValid) { if (forS3) { diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js.erb similarity index 99% rename from app/assets/javascripts/reports/new.js rename to app/assets/javascripts/reports/new.js.erb index 6b6ad4dc7..7e1faa939 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js.erb @@ -1124,7 +1124,8 @@ function initializeReportSidebartruncation() { function() { $.each($("a.report-nav-link"), function(){ - truncateLongString($(this), NAME_TRUNCATION_LENGTH); + truncateLongString($(this), + <%= Constants::NAME_TRUNCATION_LENGTH %>); }); } ); @@ -1215,7 +1216,7 @@ $(document).ready(function() { initializeTutorial(); $('.report-nav-link').each(function() { - truncateLongString($(this), NAME_TRUNCATION_LENGTH); + truncateLongString($(this), <%= Constants::NAME_TRUNCATION_LENGTH %>); }); } }) @@ -1223,7 +1224,7 @@ $(document).ready(function() { $(document).change(function(){ setTimeout(function(){ $(".report-nav-link").each( function(){ - truncateLongString( $(this), NAME_TRUNCATION_LENGTH); + truncateLongString( $(this), <%= Constants::NAME_TRUNCATION_LENGTH %>); }); }, 1000); }); diff --git a/app/assets/javascripts/sitewide/constants.js.erb b/app/assets/javascripts/sitewide/constants.js.erb deleted file mode 100644 index 6bbfee306..000000000 --- a/app/assets/javascripts/sitewide/constants.js.erb +++ /dev/null @@ -1,4 +0,0 @@ -// All Ruby global constants are provided to JS -<%= Constants.output_to_js %> - -// JS global constants diff --git a/app/assets/javascripts/sitewide/form_validators.js.erb b/app/assets/javascripts/sitewide/form_validators.js.erb index 27d8cc102..e6c8da54e 100644 --- a/app/assets/javascripts/sitewide/form_validators.js.erb +++ b/app/assets/javascripts/sitewide/form_validators.js.erb @@ -64,7 +64,7 @@ function checklistsValidator(ev, checklists, editMode) { if ($itemInput.val()) { var itemNameValid = textValidator(ev, $itemInput, 1, - TEXT_MAX_LENGTH); + <%= Constants::TEXT_MAX_LENGTH %>); if (!itemNameValid) { noErrors = false; } @@ -81,7 +81,7 @@ function checklistsValidator(ev, checklists, editMode) { var allowBlankChklstName = !(anyChecklistItemFilled || editMode); var textLimitMin = allowBlankChklstName ? 0 : 1; var checklistNameValid = textValidator(ev, $checklistInput, - textLimitMin, TEXT_MAX_LENGTH); + textLimitMin, <%= Constants::TEXT_MAX_LENGTH %>); if (!checklistNameValid) { noErrors = false; } else if (allowBlankChklstName) { @@ -95,8 +95,8 @@ function checklistsValidator(ev, checklists, editMode) { } var FileTypeEnum = Object.freeze({ - FILE: 0, - AVATAR: 1 + FILE: <%= Constants::FILE_MAX_SIZE_MB.megabytes %>, + AVATAR: <%= Constants::AVATAR_MAX_SIZE_MB.megabytes %> }); function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) { diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index d8ce8fe68..3aa3ab5e6 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -20,7 +20,7 @@ class TagsController < ApplicationController end if @tag.color.blank? - @tag.color = TAG_COLORS[0] + @tag.color = Constants::TAG_COLORS[0] end if @tag.save diff --git a/app/views/activities/_activity.html.erb b/app/views/activities/_activity.html.erb index 0b77bf2be..42604ad08 100644 --- a/app/views/activities/_activity.html.erb +++ b/app/views/activities/_activity.html.erb @@ -7,7 +7,7 @@ <% if activity.my_module %> [<%=t 'Project' %>: <% if activity.my_module.experiment.project.name.length > - Constants::NAME_TRUNCATION_LENGTH %> + <%= Constants::NAME_TRUNCATION_LENGTH %> %>
<%= truncate(asset.file_file_name, - length: FILENAME_TRUNCATION_LENGTH) %>
+ length: Constants::FILENAME_TRUNCATION_LENGTH) %> <% end %> <% else %> <%= asset_loading_span(asset) %> @@ -70,7 +70,7 @@ <% else %> <%= image_tag preview_asset_path(asset) if asset.is_image? %><%= truncate(asset.file_file_name, - length: FILENAME_TRUNCATION_LENGTH) %>
+ length: Constants::FILENAME_TRUNCATION_LENGTH) %> <% end %> <% end %>