Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | 18x 18x 18x 18x 18x 2x 16x 4x 22x 22x 24x 24x 24x 24x 22x 24x 22x 20x 24x 24x 24x 2x 22x 22x 22x 22x 18x 18x 18x 4x 22x 22x 22x 22x 22x 22x 54x 22x 22x 22x 22x 2x 20x 2x 22x 22x | /* Copyright © 2016 Kuali, Inc. - All Rights Reserved
* You may use and modify this code under the terms of the Kuali, Inc.
* Pre-Release License Agreement. You may not distribute it.
*
* You should have received a copy of the Kuali, Inc. Pre-Release License
* Agreement with this file. If not, please write to license@kuali.co.
*/
import DialogPrintView from './dialog-print-view'
import React from 'react'
import rendererStyles from '@kuali/formbot/dist/lib/gadget-renderer.css'
import shortid from 'shortid'
import Table from './table.js'
import { get, isArray, partial, xor } from 'lodash'
import {
getHiddenColumns,
getHiddenColumnsUpdateHandler
} from './context-helper'
function renderRow (
Formbot,
context,
listFormKey,
mode,
rowTemplates,
data,
onChange,
rowIndex,
additionalContext = {}
) {
// wrap the children in a section so formbot knows what to do with them
const template = {
type: 'Section',
id: 'root',
children: rowTemplates
}
const row = Formbot.render(mode, template, [], data, {
onChange,
context: {
...context,
list: true,
listContext: {
listFormKey,
listPath: buildListPath(context, listFormKey, rowIndex),
rowId: get(data, 'id'),
...additionalContext
}
}
})
// strip the root div
return get(row, ['props', 'children', 'props', 'children'], [])
}
function buildListPath (context, listFormKey, rowIndex) {
const parentPath = get(context, 'listContext.listPath', false)
if (parentPath) {
return `${parentPath}.${listFormKey}.${rowIndex}`
} else {
return `${listFormKey}.${rowIndex}`
}
}
function createRow (defaultValues) {
return {
...defaultValues,
id: shortid.generate()
}
}
function extractValuesFromChildren (Formbot, template, mode, options) {
const defaultValues = {}
const headers = options.childrenTemplates.map(template => {
const { formKey, label } = template
const childGadget = Formbot.getGadget(template.type)
// ewww side effect
defaultValues[formKey] = childGadget.defaultValue
return {
key: formKey,
label: label,
template
}
})
return { defaultValues, headers }
}
export function customGadgetRenderer (Formbot, mode, template, options) {
if (options.value && isArray(options.value)) {
options.value = options.value.map(row => {
return row.id ? row : createRow(row)
})
}
const { context, onChange, shouldShow } = options
const { printableView } = context || {}
if (!shouldShow) {
return null
}
const {
defaultValues: defaultChildValues,
headers
} = extractValuesFromChildren(Formbot, template, mode, options)
const value = options.value || []
let hiddenColumns = printableView
? []
: getHiddenColumns(template.formKey, context)
if (hiddenColumns.length === 0 && !printableView) {
const allHeaderKeys = headers.map(header => header.key)
const defaultHeaders = get(template, 'details.defaultHeaders', [])
if (defaultHeaders.length > 0) {
hiddenColumns = xor(allHeaderKeys, defaultHeaders)
}
}
const handleColumnVisibilityChange = getHiddenColumnsUpdateHandler(
template.formKey,
context
)
const decorators = Formbot.getDecorators({ type: template.type, mode })
const gadgetDef = Formbot.getGadget(template.type)
const props = {
context,
template,
mode,
formKey: template.formKey,
id: template.id
}
const createComponent = _props => {
const decorate = (items, createComponent) =>
decorators.length
? Formbot.decorate(
decorators,
items,
_props,
gadgetDef,
createComponent
)
: items
const className = rendererStyles[`size-${template.fieldSize || 'large'}`]
const headingParts = Formbot.buildHeadingParts(
Formbot,
_props.mode,
template
)
const showColumnVisibilityControl = get(
template,
['details', 'columnVisibilityControl'],
true
)
if (printableView) {
return (
<DialogPrintView
key={template.id}
rows={value}
template={template}
headingParts={headingParts}
renderRow={partial(
renderRow,
Formbot,
context,
template.formKey,
'view',
template.children
)}
/>
)
} else {
return (
<Table
className={className}
decorate={decorate}
renderRow={partial(renderRow, Formbot, context, template.formKey)}
addId={createRow}
createNewRow={partial(createRow, defaultChildValues)}
key={template.id}
headers={headers}
initialHiddenColumns={hiddenColumns}
listType={get(template, 'details.type', 'inline')}
mode={_props.mode}
onColumnVisibilityChange={hiddenColumns => {
handleColumnVisibilityChange(template.formKey, hiddenColumns)
}}
onChange={onChange}
rows={value}
showColumnVisibilityControl={showColumnVisibilityControl}
template={template}
formbotOptions={Formbot.options}
headingParts={headingParts}
/>
)
}
}
const component = createComponent(props)
return decorators.length
? Formbot.decorate(
decorators,
{ component },
props,
gadgetDef,
createComponent
).component
: component
}
|