Skip to content

Commit

Permalink
remove ajaxBlock around show, improve table rendering, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Taack committed Apr 29, 2024
1 parent b17357f commit 97dafb0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 71 deletions.
42 changes: 2 additions & 40 deletions taack-ui/grails-app/services/taack/render/TaackUiService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ final class TaackUiService implements WebAttributes, ResponseRenderer, DataBinde
}

/**
* Retrieve hidden field passed with {@link UiFilterSpecifier#ui(java.lang.Class, groovy.lang.Closure, taack.ast.type.FieldInfo[])}.
* Retrieve hidden field passed with {@link UiFilterSpecifier#ui(java.lang.Class, groovy.lang.Closure, taack.ast.type.FieldInf o [])}.
*
* @param aClass
* @return objectClass initialized
Expand Down Expand Up @@ -460,42 +460,4 @@ final class TaackUiService implements WebAttributes, ResponseRenderer, DataBinde
]
html
}

/**
* Helper displaying a dialog allowing to confirm before processing the action.
*
* <pre>{@code
* Long option = taackUiSimpleService.showOptions(tr('default.button.confirm.message'), ['Yes', 'No'])
* if (option == 0) // do things
* }</pre>
* @param i18n content of the text
* @param options list of options
* @param isAjax set to true if the next action is ajax
* @return the index, starting from zero the user click on
*/
final Long showOptions(String i18n, List<String> options, boolean isAjax = true) {
final String confirmKey = 'showOptions'
Long confirm = params.containsKey(confirmKey) ? params.long(confirmKey) : null
params.remove(confirmKey)
def b = new UiBlockSpecifier()
if (confirm == null)
show(b.ui {
modal {
ajaxBlock "showConfirm", {
delegate.show("Action Options", new UiShowSpecifier().ui({
field(i18n)
int i = 0
for (String opt in options) {
showAction("<br><b>${opt}</b>", controllerName, actionName, null, params + [showOptions: "${i}"], isAjax)
i++
}
}), BlockSpec.Width.MAX)
}
}
})
else {
closeModal()
}
return confirm
}
}
}
31 changes: 2 additions & 29 deletions taack-ui/src/main/groovy/taack/ui/base/show/ShowSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,16 @@ class ShowSpec extends SectionSpec {
showVisitor.visitSectionEnd()
}

/**
* Link action to insert in the show block
*
* @param i18n label of the action
* @param controller controller targeted by a click on the link
* @param action action targeted by a click on the link
* @param id object ID to pass
* @param params additional params
* @param isAjax if true, target action is an ajax one
*/
void showAction(final String i18n, final String controller, final String action, final Long id = null, final Map params = null, boolean isAjax = true) {
showVisitor.visitShowAction(i18n, controller, action, id, params, isAjax)
}

/**
* see {@link #showAction(java.lang.String, java.lang.String, java.lang.String, java.lang.Long, java.util.Map)}
*
* @param i18n
* @param action action closure
* @param id
* @param params
* @param isAjax
*/
void showAction(final String i18n, final MethodClosure action, final Long id = null, final Map params = null, boolean isAjax = true) {
showVisitor.visitShowAction(i18n, Utils.getControllerName(action), action.method, id, params, isAjax)
void showAction(final MethodClosure action, final Long id = null, final Map params = null) {
showVisitor.visitShowAction(null, Utils.getControllerName(action), action.method, id, params, true)
}

/**
* see {@link #showAction(java.lang.String, java.lang.String, java.lang.String, java.lang.Long, java.util.Map)}
*
* @param i18n
* @param action
* @param id
* @param isAjax
*/
void showAction(final String i18n, final MethodClosure action, final Long id, boolean isAjax) {
showVisitor.visitShowAction(i18n, Utils.getControllerName(action), action.method, id, null, isAjax)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ final class RawHtmlShowDump implements IUiShowVisitor {

@Override
void visitShowAction(String i18n, String controller, String action, Long id, Map additionalParams, boolean isAjax = true) {
i18n ?= parameter.trField(controller, action)
additionalParams ?= [:]
additionalParams['isAjax'] = isAjax
out << """<a class="taackShowAction" ${isAjax ? "taackShowActionLink" : "href"}="${parameter.urlMapped(controller, action, id, additionalParams)}">${i18n}</a>"""
Expand Down
13 changes: 11 additions & 2 deletions taack-ui/src/main/groovy/taack/ui/dump/RawHtmlTableDump.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class RawHtmlTableDump implements IUiTableVisitor {
int level = 0
private Style rowStyle = null
int stripped = 0
private boolean firstSurround = false

RawHtmlTableDump(final String id, final ByteArrayOutputStream out, final Parameter parameter) {
this.out = out
Expand Down Expand Up @@ -151,6 +152,8 @@ final class RawHtmlTableDump implements IUiTableVisitor {

@Override
void visitRowColumnEnd() {
firstSurround = false

isInCol = false
out << "</td>"
}
Expand All @@ -163,6 +166,7 @@ final class RawHtmlTableDump implements IUiTableVisitor {
} else {
out << """<td ${style ? "style='${style.cssStyleString}'" : (rowStyle ? "style='${rowStyle.cssStyleString}'" : "")}>"""
}
firstSurround = true
}

void visitRowFieldCommon(Class type, Object value, final String format = null, final Style style, final String controller = null, final String action = null, final Long id = null) {
Expand Down Expand Up @@ -196,15 +200,20 @@ final class RawHtmlTableDump implements IUiTableVisitor {
visitRowFieldCommon (fieldInfo.getMethod().returnType, fieldInfo.value, null, style, controller, action, id)
}

private static String surroundCell(final String cell, final Style style = null, final String url = null) {
private String surroundCell(final String cell, final Style style = null, final String url = null) {
if (style) {
if (!cell || cell.empty) return ""
return """
<div class="${style.cssClassesString ?: ''}" style="${style.cssStyleString ?: ''}">
${url ? "<a class='link' href='${url}'>${cell ?: ''}</a>" : "${cell ?: ''}"}
</div>
"""
} else return "${cell && !cell.empty ? "${url ? "<a class='link' href='${url}'>${cell ?: ''}</a>" : "${cell}"} <br>" : ''}"
} else {
String ret = "${cell && !cell.empty ? "${url ? "<a class='link' href='${url}'>${cell ?: ''}</a>" : "${cell}"}" : ''}"
ret = ret.empty ? '' : ((!firstSurround ? '<br>' : '') + ret)
firstSurround = false
return ret
}
}

@Override
Expand Down

0 comments on commit 97dafb0

Please sign in to comment.