Those use cases show what is up to the application developer responsibility (on diagrams, it is the controller actor), what is done automatically by the framework (light blue rectangle).
Displaying a form and saving an object
Two actions are involved, using 2 services:
def userForm(User user) { (1)
if (!user) user = new User() (2)
UiFormSpecifier f = new UiFormSpecifier() (3)
f.ui user, {
hiddenField user.subsidiary_
hiddenField user.origin_
section "User", {
field "Username", user.username_
field "First Name", user.firstName_
field "Last Name", user.lastName_
ajaxField "Manager", user.manager_, this.&selectUserM2O as MC
field "Trigram", user.trigram_
field "Passwd", user.password_
}
section "Coords", {
field "Business Unit", user.businessUnit_
field "Job", user.job_
field "Tel.", user.directPhone_
field "Other Tel.", user.additionalPhone_
field "Mail", user.mail_
field "Subsidiary", user.mainSubsidiary_
field "Allowed Subsidiaries", user.allowedSubsidiaries_
}
// [. . .]
formAction "Save", this.&saveUser as MC, user.id, true (4)
}
UiBlockSpecifier b = new UiBlockSpecifier()
b.ui {
modal {
ajaxBlock "userForm", {
form "User Form", f, BlockSpec.Width.MAX
}
}
}
taackUiSimpleService.show(b) (5)
}
@Secured("ROLE_ADMIN") (6)
def saveUser(String redirectAction) { (7)
taackSimpleSaveService.saveThenRedirectOrRenderErrors(User, this.&listUser) (8)
}
-
Action displaying the form
-
Create the object if object is null
-
Create the form
-
Form button that send the form data to the saveUser action
-
show the form
-
Secure the save action
-
Action that will save the object
-
Call to taackSimpleSaveService, here if the object is valid, user is redirected to
listUsers
action.
Display a table with sortable columns, inline actions, and a filter
Only one action is necessary to manage pagination, filtering and sorting:
def index() { (1)
User cu = authenticatedUser as User
UiFilterSpecifier f = buildUserTableFilter cu (2)
UiTableSpecifier t = buildUserTable f (3)
UiBlockSpecifier b = new UiBlockSpecifier() (4)
b.ui {
ajaxBlock "userList", {
tableFilter "Filter", f, "Users", t, BlockSpec.Width.MAX, {
if (cu.authorities*.authority.contains("ROLE_ADMIN"))
action "Create User",
ActionIcon.CREATE, this.&userForm as MC, true (5)
}
}
}
taackUiSimpleService.show(b, buildMenu()) (6)
}
-
Action that display a list of objects
-
Build the filter, here the filter takes the current connected user as parameter, because we want to be able to list user team.
-
Build the table
-
Build the block containing the table and the filter
-
Add an action to create a new user
-
Show the block
Warning
|
We exceptionally pass the filter to the buildTable for building the query and avoiding filter hacking |
Display a modal then close it and refresh part of current content
taackSimpleSaveService.saveThenDisplayBlockOrRenderErrors(EngineeringChangeRequest, (1)
new UiBlockSpecifier().ui { (2)
closeModalAndUpdateBlock { (3)
ajaxBlock ajaxBlockId, { (4)
show "Projects", buildShowProjects(ecr), BlockSpec.Width.MAX, {
action "Edit projects 2", ActionIcon.ADD,
Ecr2Controller.&projectsForm as MC,
[id: ecr.id, ajaxBlockId: ajaxBlockId], true
}
}
}
})
-
After an action implying to save an object is called into a modal, you can close the modal and refresh page elements in one action
-
saveThenDisplayBlockOrRenderErrors
take aUiBlockSpecifier
as parameter -
closeModalAndUpdateBlock
will first close the last opened modal and then apply the modification -
Here, the block with the name contained in
ajaxBlockId
will be updated
TODO
-
Updating a portion of a page
-
Show some object with an editable field
-
Show a graph
-
Export a table in CSV
-
Rendering a block in a PDF
-
Rendering a block in a Mail
-
…