|
|
@@ -6,6 +6,8 @@ const { dollarIcon } = require('../../assets')
|
|
|
*/
|
|
|
const details = (opts) => {
|
|
|
|
|
|
+ const hideCriteria = column => column.routeParam ? `ctrl.$routeParams.${column.routeParam} !== '${opts.paramAll}'` : 'false'
|
|
|
+
|
|
|
const autocompleteInput = column => {
|
|
|
if (!column.apiPrefix) throw new Error('apiPrefix is required for autocomplete fields')
|
|
|
|
|
|
@@ -19,7 +21,7 @@ const details = (opts) => {
|
|
|
md-selected-item-change="ctrl.autocomplete.${raw(column.camelName)}.onChange()"
|
|
|
md-min-length="0"s
|
|
|
placeholder="${column.titleName}"
|
|
|
- >
|
|
|
+ ng-hide="${hideCriteria(column)}">
|
|
|
<md-item-template>
|
|
|
<span md-highlight-text="ctrl.searchText.${raw(column.camelName)}" md-highlight-flags="^i">{{item.name || item.key || item.id}}</span>
|
|
|
</md-item-template>
|
|
|
@@ -30,14 +32,14 @@ const details = (opts) => {
|
|
|
const attrs = obj => obj ? _.toPairs().map((key, value) => html`${key}="${value}"`).join(' ') : ''
|
|
|
|
|
|
const standardInput = column => html`
|
|
|
- <md-input-container flex>
|
|
|
+ <md-input-container flex ng-hide="${hideCriteria(column)}">
|
|
|
<label>${column.titleName}</label>
|
|
|
<input type="${column.type || 'text'}" ${attrs(column.attrs)} ng-model="model.${raw(column.camelName)}" />
|
|
|
</md-input-container>
|
|
|
`
|
|
|
|
|
|
const currencyInput = column => html`
|
|
|
- <md-input-container flex>
|
|
|
+ <md-input-container flex ng-hide="${hideCriteria(column)}">
|
|
|
<label>${column.titleName}</label>
|
|
|
<input type="number" step="0.01" ng-model="model.${raw(column.camelName)}" />
|
|
|
<md-icon md-svg-src="${dollarIcon}"></md-icon>
|
|
|
@@ -56,32 +58,46 @@ const details = (opts) => {
|
|
|
const cols = _.fromPairs(opts.columns.map(col => [col.camelName, col]))
|
|
|
|
|
|
return opts.layout.map(section => html`
|
|
|
- ${section.section ? html`<md-subheader>${section.section}</md-subheader>`:''}
|
|
|
- ${raw(section.rows ? section.rows.map(
|
|
|
- row => html`
|
|
|
- <div layout-gt-sm="row" layout-padding>
|
|
|
- ${raw(row
|
|
|
- .map(field => cols[field])
|
|
|
- .map(c => c.field || defaultField(c))
|
|
|
- .join('\n')
|
|
|
- )}
|
|
|
- </div>
|
|
|
- `).join('\n')
|
|
|
- : '')}
|
|
|
- `).join('\n')
|
|
|
+ <md-card>
|
|
|
+ ${section.section ? html`<h2 style="padding-left: 15px">${section.section}</h2>`:''}
|
|
|
+ <md-card-content layout="column" layout-margin>
|
|
|
+ ${raw(section.rows ? section.rows.map(
|
|
|
+ row => html`
|
|
|
+ <div flex layout="column" layout-gt-sm="row" layout-margin>
|
|
|
+ ${raw(row
|
|
|
+ .map(field => cols[field])
|
|
|
+ .map(c => c.field || defaultField(c))
|
|
|
+ .join('\n')
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ `).join('\n')
|
|
|
+ : '')}
|
|
|
+ </md-card-content>
|
|
|
+ </md-card>`).join('\n')
|
|
|
} else {
|
|
|
return html`
|
|
|
- <div layout-gt-sm="row" layout-padding>
|
|
|
- ${opts.columns.map(c => c.field || defaultField(c))}
|
|
|
- </div>
|
|
|
+ <md-card>
|
|
|
+ <md-card-content layout="column" layout-gt-sm="column" layout-margin>
|
|
|
+ ${opts.columns.map(c => html`
|
|
|
+ ${c.field || defaultField(c)}
|
|
|
+ `)}
|
|
|
+ </md-card-content>
|
|
|
+ </md-card>
|
|
|
`
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const template = html`
|
|
|
<app-user-area>
|
|
|
- <h1>{{ctrl.isNew ? 'New ${opts.titleName}' : '${opts.titleName} Details'}}</h1>
|
|
|
- <form name="form" ng-submit="ctrl.submit()">
|
|
|
+ <h1 ng-show="ctrl.isNew">New ${opts.titleName}</h1>
|
|
|
+ <h1 ng-hide="ctrl.isNew">${opts.titleName} Details</h1>
|
|
|
+ <form name="form" ng-submit="ctrl.submit()" layout="column" layout-margin
|
|
|
+ flex-xs="100"
|
|
|
+ flex-sm="100"
|
|
|
+ flex-md="70"
|
|
|
+ flex-lg="70"
|
|
|
+ flex-xl="70"
|
|
|
+ >
|
|
|
${raw(layout())}
|
|
|
<div>
|
|
|
<md-button type="submit" class="md-raised md-primary">Submit</md-button>
|
|
|
@@ -95,10 +111,15 @@ const details = (opts) => {
|
|
|
|
|
|
template,
|
|
|
controllerAs: 'ctrl',
|
|
|
- controller: function(api, $scope, $routeParams, $mdToast, $location, $q) {
|
|
|
+ controller: function(api, $scope, $routeParams, $mdToast, $location, $q, util) {
|
|
|
+ this.$routeParams = $routeParams
|
|
|
this.template = template // For inspection purposes
|
|
|
+
|
|
|
+ this.apiPrefix = util.fillPath(opts.apiPrefix, $routeParams)
|
|
|
+ this.appPrefix = util.fillPath(opts.appPrefix, $routeParams)
|
|
|
+
|
|
|
this.isNew = $routeParams[opts.routeParam] === opts.paramNew
|
|
|
- const crud = api.crud(opts.apiPrefix)
|
|
|
+ const crud = api.crud(this.apiPrefix)
|
|
|
let original
|
|
|
if (this.isNew) {
|
|
|
original = {}
|
|
|
@@ -126,7 +147,7 @@ const details = (opts) => {
|
|
|
await crud.update(original.id, obj)
|
|
|
}
|
|
|
$mdToast.showSimple(`${opts.titleName} saved.`)
|
|
|
- $location.url(opts.appPrefix)
|
|
|
+ $location.url(this.appPrefix)
|
|
|
} catch (err) {
|
|
|
console.error(err)
|
|
|
$mdToast.showSimple(`Could not save ${opts.titleName}: ${err.message || err.statusText || err}`)
|
|
|
@@ -138,7 +159,7 @@ const details = (opts) => {
|
|
|
this.autocomplete = {}
|
|
|
|
|
|
opts.columns.filter(c => c.type === 'autocomplete').forEach(c => {
|
|
|
- const crud = api.crud(c.apiPrefix)
|
|
|
+ const crud = api.crud(util.fillPath(c.apiPrefix, $routeParams))
|
|
|
const ac = this.autocomplete[c.camelName] = {
|
|
|
onChange() {
|
|
|
$scope.model[c.camelName] = ac.selectedItem
|