Skip to content

Instantly share code, notes, and snippets.

@chanwit
Created October 3, 2011 07:57
Show Gist options
  • Select an option

  • Save chanwit/1258658 to your computer and use it in GitHub Desktop.

Select an option

Save chanwit/1258658 to your computer and use it in GitHub Desktop.
<window apply="PersonComposer">
<grid>
<rows>
<row> <textbox id="txtFirstName"/> </row>
<row> <textbox id="txtLastName"/> </row>
<row> <textbox id="txtFullName"/> </row>
<row>
<hbox id="boxDialog">
<button>Save</button>
<button>Cancel</button>
</hbox>
</row>
</rows>
</grid>
</window>
class PersonComposer {
def viewModel // MyViewModel
// handler
def onClick_btnSave(e) {
def person = viewModel.person
Person.withTransaction {
person.save()
}
}
}
/*
page-scoped
*/
class PersonViewModel {
def binder
List<Person> personList
Person person
static binding = {
txtFirstName value:"firstName"
txtLastName value:"lastName"
txtFullName value: fullname
boxDialog.$("> button") {
disabled = disable
}
txtDayRemain style: dayRemain
}
def fullname = [
forward: { "${person.firstName} ${person.lastName}" },
reverse: { fullname -> (person.firstName, person.lastName) = fullname.split(' ') }
]
def dayRemain = {
if (person.dayRemains < 10)
"red"
else
"black"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment