Skip to content

Commit

Permalink
fix: limit description length for tmx
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jul 19, 2017
1 parent 8ea283a commit 1dfa940
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Expand Up @@ -34,6 +34,8 @@
import javax.persistence.MapKeyColumn;
import javax.persistence.MapKeyEnumerated;
import javax.persistence.OneToMany;
import javax.validation.constraints.Size;

import org.zanata.model.SlugEntityBase;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
Expand All @@ -49,6 +51,7 @@
public class TransMemory extends SlugEntityBase implements HasTMMetadata {
private static final long serialVersionUID = 1L;
@Column(columnDefinition = "longtext")
@Size(max = 100)
private String description;
// This is the BCP-47 language code. Null means any source language (*all*
// in TMX)
Expand Down
Expand Up @@ -159,4 +159,10 @@
<addPrimaryKey tableName="HTextFlowTargetContentHistory" columnNames="pos,text_flow_target_history_id"/>
</changeSet>

<changeSet id="1" author="aeng@redhat.com">
<comment>Alter TransMemory description, limit max length</comment>
<sql>UPDATE TransMemory SET description=SUBSTRING(description,1,100);</sql>
<modifyDataType tableName="TransMemory" columnName="description"
newDataType="char(100)"/>
</changeSet>
</databaseChangeLog>
Expand Up @@ -2,8 +2,28 @@
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j">
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">

<script>
function getDescriptionMessageCountField() {
return jQuery('#' + jqSelector('#{rich:clientId('trans-memory-desc-count')}'));
}

function validateDescriptionField(textArea) {
var len = 100 - textArea.value.length;
getDescriptionMessageCountField().text('Characters left: ' + len);
if (textArea.value.length > 100) {
getDescriptionMessageCountField().addClass("txt--danger");
getDescriptionMessageCountField().parent('div').addClass("form__item--error")
} else {
getDescriptionMessageCountField().removeClass("txt--danger");
getDescriptionMessageCountField().parent('div').removeClass("form__item--error")
}
}
</script>

<div class="l--push-top-half form__item">
<h:outputLabel for="slug">#{msgs['jsf.transmemory.TransMemoryId']}
Expand All @@ -24,7 +44,11 @@
<h:outputLabel for="description">#{msgs['jsf.Description']}</h:outputLabel>
<zanata:decorate id="description" componentId="descriptionField">
<h:inputTextarea id="description" required="false"
value="#{translationMemoryHome.instance.description}"/>
value="#{translationMemoryHome.instance.description}"
onkeyup="validateDescriptionField(this)">
<f:validateLength maximum="100"/>
</h:inputTextarea>
<h:outputLabel id="trans-memory-desc-count" styleClass="txt--meta"></h:outputLabel>
</zanata:decorate>
</div>

Expand Down

0 comments on commit 1dfa940

Please sign in to comment.