Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const perm = (permission, component, failureComponent=null) => {
const { store } = app.context
return (user => {
if(user && user.isSuper) { return true }
if(user && user.permissions) {
if(_.isArray(permission)) {
return !_.some(permission, p => user.permissions.indexOf(p) == -1)
} else if(_.isFunction(permission)) {
return permission(user)
} else {
return user.permissions.indexOf(permission) > -1
}
} else {
return false
}
})(store.getState().user) ? component: failureComponent
}
render() {
const { input: { name, value, onBlur, onChange, ...inputProps }, field } = this.props
const { gte, lte } = this.state
const { _t } = app.context
return (
this.onBlur(e, 'gte')} onChange={(e)=>this.onChange(e, 'gte')} />
this.onBlur(e, 'lte')} onChange={(e)=>this.onChange(e, 'lte')} />
)
}
render() {
const { input: { name, value, onChange }, field } = this.props
const { _t } = app.context
return (
<button>{
onChange(value === true?null:true)
}}>{field.boolLabel ? field.boolLabel[0] : _t('True')}</button>
<button>{
onChange(value === false?null:false)
}}>{field.boolLabel ? field.boolLabel[1] : _t('False')}</button>
)
}
let headers = () => {
const { store } = app.context
const user = store != undefined ? store.getState().user : null
const hs = {
'Content-Type': 'application/json'
}
if( user && user.id ) {
hs['Authorization'] = user.id
}
return hs
}
let resource = model.resource_name || model.name
render() {
const { input: { name, value, onBlur, onChange, ...inputProps }, field } = this.props
const { checks } = this.state
const { _t } = app.context
return (
<>
{
if(e.target.checked) {
this.clear()
}
}} {...inputProps} >{_t('All')}
{field.titleMap.map(option => { return (
= 0}
onChange={(e)=>this.onChange(e, option.value)}
{...inputProps} value={option.value} >{option.name}) })}
)
function *handle_get_list({ model, filter, wheres }) {
yield put({ type: 'START_LOADING', model, key: `${model.key}.items` })
const { store } = app.context
const modelState = store.getState().model[model.key]
try {
const { items, total } = yield api(model).query(filter || modelState.filter, wheres || modelState.wheres)
yield put({ type: 'GET_ITEMS', model: model, items: items || [], filter, wheres, count: total })
} catch(err) {
app.error(err)
yield put({ type: 'GET_ITEMS', model: model, items: [], filter, wheres, count: 0 })
}
yield put({ type: 'END_LOADING', model, key: `${model.key}.items` })
}
const ModalLayout = ({ children, invalid, handleSubmit, submitting, title, show, onClose, saveText }) => {
const { _t } = app.context
return (
{title}
<form>{children}</form>
<button>{_t('Close')}</button>
<button disabled="{invalid" type="submit">
{saveText || _t('Save')}
</button>
)
}
const _t = (...props) => app.context._t(...props)
onChange: ({ dispatch }) => (item) => {
const { _t } = app.context
return new Promise((resolve, reject) => {
dispatch({ model: UserChangePassword(app), type: 'SAVE_ITEM', item, promise: { resolve, reject },
message: _t('Change password success') })
}).then(user => {
app.go('/app/')
}).catch(error => {
throw new SubmissionError({ old_password: _t('Incorrect old password') })
})
}
}
render() {
const { _t } = app.context
const { input: { value: item }, field } = this.props
const displayField = field.displayField || 'name'
return (
)
}
}