forked from xprototype/skeleton-quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[revamp] Redistribute methods of components
- Loading branch information
Showing
15 changed files
with
479 additions
and
345 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/app/Prototype/Components/Buttons/PrototypeButtonDropdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @typedef {PrototypeButtonDropdown} | ||
*/ | ||
export default { | ||
/** | ||
*/ | ||
methods: { | ||
/** | ||
* @param {Function} h | ||
* @param {Object} data | ||
* @returns {*} | ||
*/ | ||
renderButtonDropdown (h, data) { | ||
// TODO: implement dropdown items | ||
/* | ||
<q-list link> | ||
<q-item | ||
v-bind="button.attrs" | ||
v-for="(action, key) in button.actions" | ||
:key="key" | ||
v-close-overlay | ||
@click.native="action.native" | ||
> | ||
<q-item-main> | ||
<q-item-tile label>{{ action.label }}</q-item-tile> | ||
</q-item-main> | ||
</q-item> | ||
</q-list> | ||
*/ | ||
data.attrs.split = true | ||
|
||
return h('q-btn-dropdown', data) | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/app/Prototype/Components/Buttons/PrototypeButtonParse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @typedef {PrototypeButtonParse} | ||
*/ | ||
export default { | ||
/** | ||
*/ | ||
methods: { | ||
/** | ||
* @param {Object} button | ||
* @returns {Object} | ||
*/ | ||
parseAttrs (button) { | ||
return { ...button.attrs, ...this.override } | ||
}, | ||
/** | ||
* @param {Object} button | ||
* @returns {Object} | ||
*/ | ||
parseListeners (button) { | ||
if (typeof button.listeners !== 'object') { | ||
return button.listeners | ||
} | ||
let context = {} | ||
if (this.context) { | ||
context = this.$util.clone(this.context) | ||
} | ||
const reduce = (listeners, key) => { | ||
listeners[key] = ($event) => button.listeners[key]($event, { context }) | ||
return listeners | ||
} | ||
return Object.keys(button.listeners).reduce(reduce, {}) | ||
}, | ||
/** | ||
* @param {Object} button | ||
*/ | ||
parseButton (button) { | ||
let action = button | ||
if (button.configure && typeof button.configure === 'function') { | ||
const clone = this.$util.clone(button) | ||
const parameters = { context: this.context, position: this.position, scope: this.scope } | ||
action = button.configure.call(this, clone, parameters) | ||
} | ||
return { | ||
...action, | ||
attrs: this.parseAttrs(action), | ||
listeners: this.parseListeners(action) | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/app/Prototype/Components/Buttons/PrototypeButtonSingle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @typedef {PrototypeButtonSingle} | ||
*/ | ||
export default { | ||
/** | ||
*/ | ||
methods: { | ||
/** | ||
* @param {Function} h | ||
* @param {Object} data | ||
* @returns {*} | ||
*/ | ||
renderButtonSingle (h, data) { | ||
return h('q-btn', data) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/app/Prototype/Components/Form/PrototypeFieldComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* @typedef {PrototypeFieldComponent} | ||
*/ | ||
export default { | ||
/** | ||
*/ | ||
props: { | ||
value: { | ||
type: Object, | ||
default: () => ({}) | ||
}, | ||
validations: { | ||
type: Object, | ||
default: () => ({}) | ||
} | ||
}, | ||
/** | ||
*/ | ||
data: () => ({ | ||
record: {} | ||
}), | ||
/** | ||
*/ | ||
methods: { | ||
/** | ||
* @param {Object} field | ||
*/ | ||
componentRef (field) { | ||
return `form:component-${field.$layout.formOrder}` | ||
}, | ||
/** | ||
* @returns {number} | ||
*/ | ||
componentTabIndex () { | ||
if (!this.counter) { | ||
this.counter = 0 | ||
} | ||
this.counter++ | ||
return this.counter | ||
}, | ||
/** | ||
* @param {Object} $event | ||
* @param {Object} component | ||
*/ | ||
componentInput ($event, component) { | ||
this.record[component.$key] = component.parseInput($event) | ||
this.$emit('input', component.$key, component.parseInput($event)) | ||
if (component.listeners.input) { | ||
component.listeners.input($event) | ||
} | ||
}, | ||
/** | ||
* @param {Function} h | ||
* @param {Object} field | ||
* @returns {*} | ||
*/ | ||
renderFieldComponent (h, field) { | ||
const key = field.$key | ||
|
||
return h(field.is, { | ||
ref: this.componentRef(field), | ||
domProps: { tabIndex: this.componentTabIndex(), value: this.record[key] }, | ||
props: { value: this.record[key] }, | ||
attrs: { ...field.attrs }, | ||
on: { ...field.listeners, input: ($event) => this.componentInput($event, field) } | ||
}) | ||
} | ||
}, | ||
/** | ||
*/ | ||
watch: { | ||
/** | ||
* @param value | ||
*/ | ||
value: { | ||
deep: true, | ||
handler (value) { | ||
this.record = this.$util.clone(value) | ||
} | ||
} | ||
}, | ||
/** | ||
*/ | ||
created () { | ||
this.counter = 1 | ||
this.record = this.$util.clone(this.value) | ||
} | ||
} |
Oops, something went wrong.