Skip to content

Commit

Permalink
[xprototype#4/feature] Improvements on example that use hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
wilcorrea committed Mar 29, 2019
1 parent d64200f commit 402057d
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions src/domains/Example/Test/Prototype/TestWithHooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Test from './Test'
import { path } from 'src/domains/Example/Test/Routes'
import { gender } from 'src/domains/Common/options'

/**
* @type {TestWithHooks}
Expand All @@ -21,22 +22,44 @@ export default class TestWithHooks extends Test {
construct () {
// construct the parent
super.construct()

// configure some fields
this.configureFields()
// configure some actions
this.configureActions()

// configure some hooks
this.configureHooks()
}

/**
*/
configureFields () {
this.field('active')
.fieldIsCheckbox({ label: 'if checked will hide "Description"' })
.fieldFormWidth(45)
.fieldFormOrder(3, true)
.fieldOn('input', function ({ $event }) {
this.setFieldLayout('description', 'formHidden', $event)
})

this.field('gender')
.fieldIsRadio(gender(TestWithHooks.domain))
.fieldFormOrder(4, true)
.fieldFormWidth(55)
.fieldOn('input', function ({ $event }) {
this.setFieldLayout('active', 'formHidden', $event === 'male')
})

this.field('description').fieldOn('input', this.changeDescriptionLabel)
}

/**
*/
configureActions () {
this.action('cancel')
.actionColor('red')
.actionTextColor('white')

this.action('go-to-test')
this.action('goToTest')
.actionScopes(['index', 'create', 'read', 'update'])
.actionPositions(['form-footer'])
.actionIcon('send')
Expand All @@ -56,13 +79,32 @@ export default class TestWithHooks extends Test {
/**
*/
this.hook('fetch:record', function () {
this.$message.toast(this.$lang(`domains.${this.domain}.messages.record`))
this.$message.toast(this.$lang(`domains.${this.domain}.messages.record`), { position: 'top-right' })
if (this.record.active === undefined) {
this.setRecord('active', false)
}
})

/**
*/
this.hook('fetch:records', function () {
this.$message.toast(this.$lang(`domains.${this.domain}.messages.records`))
this.$message.toast(this.$lang(`domains.${this.domain}.messages.records`), { position: 'top-left' })
})
}

/**
* @param $event
* @param field
*/
changeDescriptionLabel ({ $event, field }) {
if (!field.originalLabel) {
field.originalLabel = field.label
}
let label = $event
if (!label) {
label = field.originalLabel
field.originalLabel = undefined
}
field.label = label
}
}

0 comments on commit 402057d

Please sign in to comment.