Permalink
Browse files

Webclient fix: truncate link texts (#247).

New functions in js_utils.js:
- strip_html(text)
- truncate(text, max_length)

Close ticket 247.
  • Loading branch information...
1 parent a41da3b commit 99d9ebeaecb30c5341c468ce3f396021c86a1cc5 @jri committed May 15, 2012
@@ -110,7 +110,7 @@ public AssociationDefinitionModel getAssocDef(String assocDefUri) {
public void addAssocDef(AssociationDefinitionModel assocDef) {
String assocDefUri = assocDef.getUri();
- // sanity check ### FIXME: drop this check or provide proper feedback to the type editor user
+ // error check ### FIXME: drop this check or provide proper feedback to the type editor user
if (!getDataTypeUri().equals("dm4.core.composite")) {
throw new RuntimeException("Association definitions can only be added to composite topic types. " +
"Topic type \"" + getUri() + "\" is of data type \"" + getDataTypeUri() + "\". (" + assocDef + ")");
@@ -1,7 +1,8 @@
/**
- * A GUI toolkit to create buttons, menus, combo boxes, and dialog boxes.
+ * A generic (DeepaMehta independent) GUI toolkit to create buttons, menus, combo boxes, and dialog boxes.
+ * Based on jQuery UI.
*
- * A toolkit instance is accessible as dm4c.ui
+ * The DeepaMehta Webclient's toolkit instance is accessible as dm4c.ui
*/
function GUIToolkit(config) {
@@ -1,5 +1,5 @@
/**
- * Generic JavaScript Utilities.
+ * Generic (DeepaMehta independent) JavaScript Utilities.
*/
var js = {
@@ -233,6 +233,20 @@ var js = {
return text.replace ? text.replace(/\n/g, "<br>") : text
},
+ strip_html: function(text) {
+ // Compare to the Java-equivalent stripHTML() in JavaUtils.java
+ // *? is the reluctant version of the * quantifier (which is greedy).
+ return text.replace(/<.*?>/g, "")
+ },
+
+ truncate: function(text, max_length) {
+ if (text.length <= max_length) {
+ return text
+ }
+ var i = text.lastIndexOf(" ", max_length)
+ return text.substr(0, i >= 0 ? i : max_length) + " ..."
+ },
+
/**
* "vendor/dm4-time/script/dm4-time.js" -> "dm4-time"
*/
@@ -1,3 +1,6 @@
+/**
+ * DeepaMehta-specific rendering functions.
+ */
function RenderHelper() {
/**
@@ -70,13 +73,23 @@ function RenderHelper() {
*/
this.topic_link = function(topic, handler) {
var title = dm4c.type_label(topic.type_uri)
- return $("<a>").attr({href: "#", title: title}).append(topic.value).click(handler)
+ var text = this.link_text(topic)
+ return $("<a>").attr({href: "#", title: title}).append(text).click(handler)
}
this.icon_link = function(topic, handler) {
return this.type_icon(topic.type_uri).click(handler)
}
+ this.link_text = function(topic) {
+ if (dm4c.get_topic_type(topic.type_uri).data_type_uri == "dm4.core.html") {
+ var text = js.strip_html(topic.value)
+ } else {
+ var text = topic.value
+ }
+ return js.truncate(text, dm4c.MAX_LINK_TEXT_LENGTH)
+ }
+
/**
* @return The <img> element (jQuery object).
*/
@@ -10,6 +10,7 @@ var dm4c = new function() {
// preferences
this.MAX_RESULT_SIZE = 100
+ this.MAX_LINK_TEXT_LENGTH = 50
this.DEFAULT_TOPIC_ICON = "/images/ball-gray.png"
var DEFAULT_FIELD_ROWS = 1

0 comments on commit 99d9ebe

Please sign in to comment.