From 24265397152b37b98823cdf0580a5f3ddeba3a1f Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 13 Dec 2016 14:54:37 +0100 Subject: [PATCH] fixes long names in columns dropdown [fixes SCI-784] --- ...e_datatable.js => sample_datatable.js.erb} | 11 ++++++---- .../javascripts/sitewide/string_utils.js | 21 ++++++++++++++++--- config/initializers/constants.rb | 2 ++ 3 files changed, 27 insertions(+), 7 deletions(-) rename app/assets/javascripts/samples/{sample_datatable.js => sample_datatable.js.erb} (99%) diff --git a/app/assets/javascripts/samples/sample_datatable.js b/app/assets/javascripts/samples/sample_datatable.js.erb similarity index 99% rename from app/assets/javascripts/samples/sample_datatable.js rename to app/assets/javascripts/samples/sample_datatable.js.erb index 246a7c79f..172c3ca26 100644 --- a/app/assets/javascripts/samples/sample_datatable.js +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -841,6 +841,7 @@ function changeToEditMode() { ''); }, success: function(data) { + debugger; var form = $('#new-column-form'); form.find('.help-block').remove(); if (form.hasClass('has-error')) { @@ -857,8 +858,8 @@ function changeToEditMode() { 'data-editable data-deletable ' + 'data-edit-url="' + data.edit_url + '" ' + 'data-destroy-html-url="' + data.destroy_html_url + '"' + - '>' + - data.name + ''); + '>' + truncateLongString(data.name, + <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>) + ''); var colOrder = table.colReorder.order(); colOrder.push(colOrder.length); // Remove all event handlers as we re-initialize them later with @@ -936,7 +937,8 @@ function changeToEditMode() { 'class="' + visLi + '"' + '>' + ' ' + - '' + el.innerText + ' ' + + '' + truncateLongString(el.innerText, + <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>) + ' ' + '' + '' + '' + @@ -1032,7 +1034,8 @@ function changeToEditMode() { data: {custom_field: {name: newName}}, dataType: 'json', success: function() { - text.text(newName); + text.text(truncateLongString(newName, + <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>)); $(table.columns().header()).filter('#' + id).text(newName); cancelEditMode(); }, diff --git a/app/assets/javascripts/sitewide/string_utils.js b/app/assets/javascripts/sitewide/string_utils.js index ff59943e8..44ef3057c 100644 --- a/app/assets/javascripts/sitewide/string_utils.js +++ b/app/assets/javascripts/sitewide/string_utils.js @@ -2,15 +2,24 @@ * Truncate long strings where is necessary. */ function truncateLongString( el, chars ) { - var input = $.trim(el.text()); + if($.type(el) !== 'string'){ + var input = $.trim(el.text()); + } else { + var input = $.trim(el); + } var html = ""; - if( el.children().hasClass("glyphicon") ){ + if( $.type(el) !== 'string' && + el.children().hasClass("glyphicon")) { html = el.children()[0]; } if( input.length >= chars ){ - var newText = el.text().slice(0, chars); + if($.type(el) != 'string') { + var newText = el.text().slice(0, chars); + }else { + var newText = el.slice(0, chars); + } for( var i = newText.length; i > 0; i--){ if(newText[i] === ' ' && i > 10){ newText = newText.slice(0, i); @@ -21,8 +30,14 @@ function truncateLongString( el, chars ) { if ( html ) { el.html(html.outerHTML + newText + '...' ); } else { + if($.type(el) === 'string'){ + return newText + '...'; + } else { el.html(newText + '...' ); + } } + } else { + return el; } } diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index b6c48d551..a23da0f6d 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -9,6 +9,8 @@ class Constants NAME_MAX_LENGTH = 255 # Max characters for short text fields, after which they get truncated NAME_TRUNCATION_LENGTH = 25 + # Max characters for short text fields, in dropdownList + NAME_TRUNCATION_LENGTH_DROPDOWN = 20 # Max characters for long text fields TEXT_MAX_LENGTH = 10000 # Max characters for rich text fields (in html format)