mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-05 20:54:27 +08:00
Removed ruby constants duplicates in JS, because of caching problems.
This commit is contained in:
parent
5966911b92
commit
ece89da391
18 changed files with 57 additions and 51 deletions
|
@ -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 %>);
|
||||
});
|
||||
});
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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");
|
|
@ -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();
|
||||
initModalSubmitAndHide();
|
|
@ -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;
|
|
@ -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) {
|
|
@ -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);
|
||||
});
|
|
@ -1,4 +0,0 @@
|
|||
// All Ruby global constants are provided to JS
|
||||
<%= Constants.output_to_js %>
|
||||
|
||||
// JS global constants
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 %> %>
|
||||
<div class="modal-tooltip">
|
||||
<%= truncate(activity.my_module.experiment.project.name,
|
||||
lenght: Constants::NAME_TRUNCATION_LENGTH).strip %>
|
||||
|
@ -17,7 +17,7 @@
|
|||
<%= activity.my_module.experiment.project.name %>
|
||||
<% end %>, <%=t 'Module' %>:
|
||||
<% if activity.my_module.name.length >
|
||||
Constants::NAME_TRUNCATION_LENGTH %>
|
||||
<%= Constants::NAME_TRUNCATION_LENGTH %> %>
|
||||
<div class="modal-tooltip"><%= truncate(
|
||||
activity.my_module.name,
|
||||
lenght: Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<%= f.text_field :name, hide_label: true %>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<%= f.color_picker_select :color, TAG_COLORS, class: "edit-tag-color" %>
|
||||
<%= f.color_picker_select :color, <%= Constants::TAG_COLORS %>, class: "edit-tag-color" %>
|
||||
<%= f.button class: "btn btn-link save-tag-link", title: t("experiments.canvas.modal_manage_tags.save_tag") do %>
|
||||
<span class="glyphicon glyphicon-ok"></span>
|
||||
<% end %>
|
||||
|
@ -84,7 +84,7 @@
|
|||
<%= hidden_field_tag :my_module_id, @my_module.id %>
|
||||
<%= f.hidden_field :project_id, :value => @my_module.experiment.project.id %>
|
||||
<%= f.hidden_field :name, :value => t("tags.create.new_name") %>
|
||||
<%= f.hidden_field :color, :value => TAG_COLORS[0] %>
|
||||
<%= f.hidden_field :color, :value => <%= Constants::TAG_COLORS[0] %> %>
|
||||
<%= f.button class: "btn btn-primary" do %>
|
||||
<span class="glyphicon glyphicon-tag"></span>
|
||||
<span class="hidden-xs"><%=t "experiments.canvas.modal_manage_tags.create_new" %></span>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<div class="workflowimg-container">
|
||||
<%= image_tag(
|
||||
experiment.workflowimg.expiring_url(
|
||||
Constants::URL_SHORT_EXPIRE_TIME
|
||||
<%= Constants::URL_SHORT_EXPIRE_TIME %>
|
||||
),
|
||||
class: 'img-responsive center-block') %>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%= link_to image_tag(@experiment.workflowimg.expiring_url(
|
||||
Constants::URL_SHORT_EXPIRE_TIME
|
||||
<%= Constants::URL_SHORT_EXPIRE_TIME %>
|
||||
),
|
||||
class: 'img-responsive center-block'),
|
||||
canvas_experiment_path(@experiment) %>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<span class="glyphicon <%= icon_class %>"></span>
|
||||
</div>
|
||||
<div class="pull-left file-name">
|
||||
<em><%=t 'projects.reports.elements.step_asset.file_name', file: truncate( asset.file_file_name, length: 40 ) %></em>
|
||||
<em><%=t 'projects.reports.elements.step_asset.file_name', file: truncate( asset.file_file_name, length: Constants::FILENAME_TRUNCATION_LENGTH) %></em>
|
||||
</div>
|
||||
<div class="pull-left user-time">
|
||||
<%=t 'projects.reports.elements.step_asset.user_time', timestamp: l(timestamp, format: :full) %>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<%= bootstrap_form_for SampleGroup.new, remote: true, url: organization_sample_groups_path(@organization) do |f| %>
|
||||
<div class="modal-body">
|
||||
<%= f.text_field :name, id: "name-input" %>
|
||||
<%= f.color_picker_btn_group :color, TAG_COLORS, id: "color-input", class: "btn-group-sample-group-color", label: t("sample_groups.color_label")%>
|
||||
<%= f.color_picker_btn_group :color, <%= Constants::TAG_COLORS %>, id: "color-input", class: "btn-group-sample-group-color", label: t("sample_groups.color_label")%>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t("general.cancel")%></button>
|
||||
|
@ -17,4 +17,4 @@
|
|||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -83,15 +83,20 @@
|
|||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><%= link_to t('nav.help.tutorials'),
|
||||
Constants::TUTORIALS_URL %></li>
|
||||
Constants::TUTORIALS_URL,
|
||||
target: "_blank" %></li>
|
||||
<li><%= link_to t('nav.help.faq'),
|
||||
Constants::FAQ_URL %></li>
|
||||
Constants::FAQ_URL,
|
||||
target: "_blank" %></li>
|
||||
<li><%= link_to t('nav.help.support'),
|
||||
Constants::SUPPORT_URL %></li>
|
||||
Constants::SUPPORT_URL,
|
||||
target: "_blank" %></li>
|
||||
<li><%= link_to t('nav.help.plans'),
|
||||
Constants::PLANS_URL %></li>
|
||||
Constants::PLANS_URL,
|
||||
target: "_blank" %></li>
|
||||
<li><%= link_to t('nav.help.contact'),
|
||||
Constants::CONTACT_URL %></li>
|
||||
Constants::CONTACT_URL,
|
||||
target: "_blank" %></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<%= link_to download_asset_path(asset), data: {no_turbolink: true, id: true, status: "asset-present"} do %>
|
||||
<%= image_tag preview_asset_path(asset) if asset.is_image? %>
|
||||
<p><%= truncate(asset.file_file_name,
|
||||
length: FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
length: Constants::FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= asset_loading_span(asset) %>
|
||||
|
@ -70,7 +70,7 @@
|
|||
<% else %>
|
||||
<%= image_tag preview_asset_path(asset) if asset.is_image? %>
|
||||
<p><%= truncate(asset.file_file_name,
|
||||
length: FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
length: Constants::FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Reference in a new issue