Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWiki 7783 - Add hints for class properties in the class editor #141

Merged
merged 11 commits into from Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -36,7 +36,7 @@
#end
#foreach ($prop in $properties)
<dt class="label#if($prop.isDisabled()) disabled#end"><label for="${escapetool.xml($class.name)}_${obj.number}_${escapetool.xml($prop.name)}">${escapetool.xml($prop.translatedPrettyName)}</label></dt>
<dd#if ($prop.isDisabled()) class="disabled"#end>$doc.display($prop.name, "edit", $obj)</dd>
<dd#if ($prop.isDisabled()) class="disabled"#end>#if ("$!prop.hint" != '')<p><span class="xHint">$prop.hint</span></p>#end$doc.display($prop.name, "edit", $obj)</dd>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we escape the HTML from the hint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, fixed in dc6655f.

#end
</dl>
#set ($deprecatedProperties = $class.getDeprecatedObjectProperties($obj))
Expand Down Expand Up @@ -270,7 +270,7 @@
</div>
#end
#set ($redirect = $xwiki.relativeRequestURL)
<form id="update" method="post" action="$doc.getURL("save")" class="withLock">
<form id="update" method="post" action="$doc.getURL("save")" class="withLock xform">
<div id="xwikieditcontent" class="clear">

#checkPropertyDeprecation()
Expand Down
Expand Up @@ -152,6 +152,18 @@ public String getTranslatedPrettyName()
return getBasePropertyClass().getTranslatedPrettyName(this.context);
}

/**
* Get the translated hint string that should be displayed for input fields for instances of this property
* definition.
*
* @return the hint string
* @since 9.11RC1
*/
public String getHint()
{
return getBasePropertyClass().getHint();
}

/**
* Get the message that should be displayed when a value for an instance of this property definition fails the
* validation. For example, {@code Please enter a valid IP address}.
Expand Down
Expand Up @@ -406,6 +406,43 @@ public void setPrettyName(String prettyName)
setStringValue("prettyName", prettyName);
}

/**
* @param property name of the property
* @return the localized value of the property, with a fallback to the inner value
*/
private String getLocalizedPropertyValue(String property)
{
String propertyName = String.format("%s_%s", getFieldFullName(), property);
String propertyValue = localizePlain(propertyName);
if (propertyValue == null) {
propertyName = getLargeStringValue(property);
if (StringUtils.isNotBlank(propertyName)) {
propertyValue = localizePlainOrKey(propertyName, propertyName);
}
}
return propertyValue;
}

/**
* Get the localized hint. A hint is a text displayed in the object editor to help the user filling some content.
*
* @return the localized hint.
* @since 9.11RC1
*/
public String getHint()
{
return getLocalizedPropertyValue("hint");
}

/**
* Set the text displayed in the object editor to help the user filling some content.
* @since 9.11RC1
*/
public void setHint(String hint)
{
setLargeStringValue("hint", hint);
}

public String getTooltip()
{
return getLargeStringValue("tooltip");
Expand All @@ -419,15 +456,7 @@ public String getTooltip()
*/
public String getTooltip(XWikiContext context)
{
String tooltipName = getFieldFullName() + "_tooltip";
String tooltip = localizePlain(tooltipName);
if (tooltip == null) {
tooltipName = getLargeStringValue("tooltip");
if ((tooltipName != null) && (!tooltipName.trim().equals(""))) {
tooltip = localizePlainOrKey(tooltipName, tooltipName);
}
}
return tooltip;
return getLocalizedPropertyValue("tooltip");
}

public void setTooltip(String tooltip)
Expand Down
Expand Up @@ -96,6 +96,12 @@ private void addPresentationMetaProperties()
prettyNameClass.setSize(40);
safeput(prettyNameClass.getName(), prettyNameClass);

StringClass hintClass = new StringClass(this);
hintClass.setName("hint");
hintClass.setPrettyName("Hint");
hintClass.setSize(40);
safeput(hintClass.getName(), hintClass);

TextAreaClass toolTipClass = new TextAreaClass(this);
toolTipClass.setName("tooltip");
toolTipClass.setPrettyName("Tooltip");
Expand Down