fix: forms

This commit is contained in:
devezhao 2020-11-07 00:03:56 +08:00
parent d2014a03af
commit 7647161de1
4 changed files with 49 additions and 22 deletions

View file

@ -535,6 +535,8 @@ public class UserStore implements Initialization {
for (User user : USERS.values()) {
Role role = user.getOwningRole();
if (role == null) continue;
if (role.getIdentity().equals(roleId)
|| (role instanceof CombinedRole && ((CombinedRole) role).getRoleAppends().contains(roleId))) {
refreshUserRoleAppends(user);

View file

@ -105,5 +105,6 @@ module.exports = {
$fromNow: true,
$expired: true,
$L: true,
$isTrue: true
},
}

View file

@ -416,6 +416,13 @@ var $stopEvent = function (e) {
return false
}
/**
* 是否为 true 'true'
*/
var $isTrue = function (a) {
return a === true || a === 'true'
}
/**
* 定位到指定元素
*/

View file

@ -46,13 +46,19 @@ class RbFormModal extends React.Component {
}
componentDidMount() {
$(this._rbmodal)
const $root = $(this._rbmodal)
.modal({
show: false,
backdrop: 'static',
keyboard: false,
})
.on('hidden.bs.modal', () => $keepModalOpen())
.on('hidden.bs.modal', () => {
$keepModalOpen()
if (this.props.disposeOnHide === true) {
$root.modal('dispose')
$unmount($root.parent().parent())
}
})
this.showAfter({}, true)
}
@ -151,13 +157,20 @@ class RbFormModal extends React.Component {
/**
* @param {*} props
*/
static create(props) {
const that = this
if (that.__HOLDER) that.__HOLDER.show(props)
else
static create(props, newDlg) {
if (newDlg === true) {
renderRbcomp(<RbFormModal {...props} />)
return
}
if (this.__HOLDER) {
this.__HOLDER.show(props)
} else {
const that = this
renderRbcomp(<RbFormModal {...props} />, null, function () {
that.__HOLDER = this
})
}
}
}
@ -197,24 +210,27 @@ class RbForm extends React.Component {
renderFormAction() {
const pmodel = this.props.$$$parent.state.__formModel
const moreActions = []
if (pmodel.hadApproval)
if (pmodel.hadApproval) {
moreActions.push(
<a key="Action103" className="dropdown-item" onClick={() => this.post(103)}>
{$L('SaveAndSubmit')}
</a>
)
if (pmodel.isMain === true)
}
if (pmodel.isMain === true) {
moreActions.push(
<a key="Action102" className="dropdown-item" onClick={() => this.post(102)}>
{$L('SaveAndAddDetail')}
</a>
)
else if (pmodel.isDetail === true)
} else if (pmodel.isDetail === true) {
moreActions.push(
<a key="Action101" className="dropdown-item" onClick={() => this.post(101)}>
{$L('SaveAndAdd')}
</a>
)
}
let actionBtn = (
<button className="btn btn-primary btn-space" type="button" onClick={() => this.post()}>
@ -462,11 +478,13 @@ class RbFormElement extends React.Component {
onEditModeChanged(destroy) {
if (destroy) {
if (this.__select2) {
if ($.type(this.__select2) === 'array')
if ($.type(this.__select2) === 'array') {
$(this.__select2).each(function () {
this.select2('destroy')
})
else this.__select2.select2('destroy')
} else {
this.__select2.select2('destroy')
}
this.__select2 = null
}
}
@ -625,7 +643,7 @@ class RbFormNumber extends RbFormText {
const err = super.isValueError()
if (err) return err
if (!!this.state.value && $regex.isNumber(this.state.value) === false) return $L('SomeNotFormatWell').replace('{0}', '')
if (!!this.state.value && this.props.notNegative === 'true' && parseFloat(this.state.value) < 0) return $L('SomeNotNegative').replace('{0}', '')
if (!!this.state.value && $isTrue(this.props.notNegative) && parseFloat(this.state.value) < 0) return $L('SomeNotNegative').replace('{0}', '')
return null
}
@ -662,7 +680,7 @@ class RbFormDecimal extends RbFormNumber {
const err = super._isValueError()
if (err) return err
if (!!this.state.value && $regex.isDecimal(this.state.value) === false) return $L('SomeNotFormatWell').replace('{0}', '')
if (!!this.state.value && this.props.notNegative === 'true' && parseFloat(this.state.value) < 0) return $L('SomeNotNegative').replace('{0}', '')
if (!!this.state.value && $isTrue(this.props.notNegative) && parseFloat(this.state.value) < 0) return $L('SomeNotNegative').replace('{0}', '')
return null
}
}
@ -700,15 +718,14 @@ class RbFormTextarea extends RbFormElement {
componentDidMount() {
super.componentDidMount()
this.unmountFieldComp()
this.onEditModeChanged(true)
}
unmountFieldComp() {
if (this._textarea) $(this._textarea).perfectScrollbar()
}
mountFieldComp() {
if (this._textarea) $(this._textarea).perfectScrollbar('destroy')
onEditModeChanged(destroy) {
if (this._textarea) {
if (destroy) $(this._textarea).perfectScrollbar()
else $(this._textarea).perfectScrollbar('destroy')
}
}
}
@ -1726,7 +1743,7 @@ class DeleteConfirm extends RbAlert {
enableCascade() {
this.setState({ enableCascade: !this.state.enableCascade })
if (!this.state.cascadesEntity) {
$.get('/commons/metadata/references?entity=' + this.props.entity, (res) => {
$.get(`/commons/metadata/references?entity=${this.props.entity}&permission=D`, (res) => {
this.setState({ cascadesEntity: res.data }, () => {
this.__select2 = $(this._cascades)
.select2({
@ -1747,7 +1764,7 @@ class DeleteConfirm extends RbAlert {
const cascades = this.__select2 ? this.__select2.val().join(',') : ''
const btns = $(this._btns).find('.btn').button('loading')
$.post('/app/entity/record-delete?id=' + ids + '&cascades=' + cascades, (res) => {
$.post(`/app/entity/record-delete?id=${ids}&cascades=${cascades}`, (res) => {
if (res.error_code === 0) {
if (res.data.deleted === res.data.requests) RbHighbar.success($L('SomeSuccess', 'Delete'))
else if (res.data.deleted === 0) RbHighbar.error($L('NotDeleteTips'))