Skip to content

Commit

Permalink
Enhanced the display of values in forms and grids.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Jan 11, 2015
1 parent 3dbc8e6 commit 22b449b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
8 changes: 6 additions & 2 deletions rapidoid-html/src/main/resources/public/rapidoid.css
Expand Up @@ -2,7 +2,7 @@
cursor: pointer;
}

.value-display {
.display-wrap {
padding-top: 1px;
padding-bottom: 1px;
padding-left: 2px;
Expand Down Expand Up @@ -45,10 +45,14 @@ span.highlight {
}

.table-hover tbody tr:hover td {
background-color: #FFC !important;
background-color: #FFB !important;
}

.field-error {
font-weight: bold;
color: #700;
}

.nothing {
color: #BBB;
}
Expand Up @@ -573,7 +573,7 @@ public static Tag[] checkboxes(Collection<?> options, Var<?> var) {
return checkboxes(U.rndStr(30), options, var);
}

public static Object display(Object item) {
public static Tag display(Object item) {
if (item instanceof Var<?>) {
Var<?> var = (Var<?>) item;
return display(var.get());
Expand All @@ -585,12 +585,11 @@ public static Object display(Object item) {
return display(U.arrayIterator(arr));
}

Tag itemDisplay = isEntity(item) ? a(item).href(urlFor(item)) : span(Cls.convert(item, String.class));
itemDisplay = itemDisplay.class_("value-display");
Tag itemDisplay = isEntity(item) ? a(item).href(urlFor(item)) : span(Cls.str(item));
return itemDisplay;
}

private static Object display(Iterator<?> it) {
private static Tag display(Iterator<?> it) {
Tag icon = awesome("circle-o");
Tag wrap = div();

Expand All @@ -600,14 +599,14 @@ private static Object display(Iterator<?> it) {
}

if (wrap.isEmpty()) {
return nothing().class_("value-line");
return span(nothing()).class_("value-line");
}

return wrap;
}

public static Tag nothing() {
return div(awesome("ban"), " No entries!");
return span(awesome("ban"), " N/A").class_("nothing");
}

}
Expand Up @@ -244,6 +244,10 @@ public int fieldIndex(String fieldName) {
throw U.rte("Cannot find field '%s'!", fieldName);
}

public FormWidget addField(String fieldName, Tag field) {
throw U.notReady();
}

protected void init(Item item, String... properties) {

props = editable() ? item.editableProperties(properties) : item.readableProperties(properties);
Expand Down Expand Up @@ -564,7 +568,7 @@ protected Object input_(String name, String desc, FieldType type, Collection<?>
}

protected Object readonly(Object item) {
return display(item);
return display(item).class_("form-display");
}

protected Object checkboxesInput(String name, Collection<?> options, Var<?> var) {
Expand Down
Expand Up @@ -141,7 +141,7 @@ protected Tag itemRow(List<Property> properties, Item item) {
for (Property prop : properties) {
Object value = item.get(prop.name());
value = U.or(value, "");
row = row.append(cell(value));
row = row.append(cell(display(value).class_("grid-display")));
}

String js = onClickScript(item);
Expand Down
4 changes: 4 additions & 0 deletions rapidoid-utils/src/main/java/org/rapidoid/util/Cls.java
Expand Up @@ -1034,4 +1034,8 @@ public static <FROM, TO> List<TO> projection(Collection<FROM> coll, String prope
return projection;
}

public static Object str(Object value) {
return convert(value, String.class);
}

}

0 comments on commit 22b449b

Please sign in to comment.