This commit is contained in:
FangfangZhao 2018-10-20 00:09:13 +08:00
parent d5eec8fee4
commit 858227e3c9
9 changed files with 213 additions and 38 deletions

View file

@ -53,7 +53,7 @@ public class SimpleSearch extends BaseControll {
public void search(HttpServletRequest request, HttpServletResponse response) throws IOException {
String entity = getParameterNotNull(request, "entity");
String qfields = getParameterNotNull(request, "qfields");
String q = getParameter(request, "q");
String q = getParameter(request, "qtext");
if (StringUtils.isBlank(q)) {
writeSuccess(response, ArrayUtils.EMPTY_STRING_ARRAY);

View file

@ -175,6 +175,10 @@ body.dialog .main-content .footer,
padding: 3px 6px
}
.select2.select2-container {
width: 100%;
}
textarea.row2x {
height: 52px !important;
resize: none;

View file

@ -1,7 +1,6 @@
var opType = opType || ['assign', '分派']
$(document).ready(function(){
let selected = parent.RbListPage._RbList.getSelectedRows()
const ids = selected.map((item) => { return item[0] })
const ids = $urlp('id').split(',')
const entity = $urlp('entity')
$('#records').text('选中的记录 (' + ids.length + '条)')
@ -31,7 +30,8 @@ $(document).ready(function(){
$('.J_click-cass a').click(function(){
$('.J_click-cass').remove();
$('.J_cass').removeClass('hide');
parent.RbListPage._ModalShare.resize()
(parent.RbListPage || parent.RbViewPage).resizeModal()
$.get(rb.baseUrl + '/commons/metadata/references?entity=' + entity, function(res){
$(res.data).each(function(){
@ -53,10 +53,11 @@ $(document).ready(function(){
$.post(url, function(res) {
if (res.error_code == 0){
rb.notice('已成功' + opType[1] + ' ' + (res.data.assigned || res.data.shared) + ' 条记录', 'success')
if (parent.RbListPage) {
if (parent.RbListPage._RbList) parent.RbListPage._RbList.reload()
$('.J_cancel').trigger('click')
}
$('.J_cancel').trigger('click')
if (parent.RbListPage) parent.RbListPage._RbList.reload()
if (parent.RbViewPage) parent.location.reload()
} else {
rb.notice(res.error_msg || (opType[1] + '失败,请稍后重试'), 'danger')
}
@ -64,9 +65,6 @@ $(document).ready(function(){
})
$('.J_cancel').click(function(){
if (parent.RbListPage) {
if (parent.RbListPage._ModalAssign) parent.RbListPage._ModalAssign.hide()
if (parent.RbListPage._ModalShare) parent.RbListPage._ModalShare.hide()
}
(parent.RbListPage || parent.RbViewPage).closeModal()
})
});

View file

@ -0,0 +1,145 @@
class TheBothDialog extends React.Component {
constructor(props) {
super(props)
this.state = { ...props, cascadesSpec: false }
this.opType = props.type == 'assign' ? '分派' : '共享'
}
render() {
return (
<div className="modal-warpper">
<div className="modal rbmodal colored-header colored-header-primary" ref="rbmodal">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header modal-header-colored">
<h3 className="modal-title">{this.opType}</h3>
<button className="close md-close" type="button" onClick={()=>this.hide()}><span className="zmdi zmdi-close"></span></button>
</div>
<div className='modal-body'>
<form>
<div className="form-group row">
<label className="col-sm-3 col-form-label text-sm-right">{this.opType + '哪些记录'}</label>
<div className="col-sm-7">
<div className="form-control-plaintext" id="records">{'选中的记录 (' + this.state.ids.split(',').length + '条)'}</div>
</div>
</div>
<div className="form-group row">
<label className="col-sm-3 col-form-label text-sm-right">{this.opType + '给谁'}</label>
<div className="col-sm-7">
<select className="form-control form-control-sm" ref="toUser" multiple="multiple" />
</div>
</div>
<div className={'form-group row ' + (this.state.cascadesSpec == false ? '' : 'hide')}>
<div className="col-sm-7 offset-sm-3"><a href="javascript:;" onClick={()=>this.showCascades()}>{'同时' + this.opType + '关联记录'}</a></div>
</div>
<div className={'form-group row ' + (this.state.cascadesSpec == false ? 'hide' : '')}>
<label className="col-sm-3 col-form-label text-sm-right">{'同时' + this.opType + '关联记录'}</label>
<div className="col-sm-7">
<select className="form-control form-control-sm" ref="cascades" multiple="multiple">
{(this.state.cascadesEntity || []).map((item) => {
return <option value={item[0]}>{item[1]}</option>
})}
</select>
</div>
</div>
<div className="form-group row footer">
<div className="col-sm-7 offset-sm-3" ref="actions">
<button className="btn btn-primary" type="button" data-loading-text="请稍后" onClick={()=>this.post()}>确定</button>
<a className="btn btn-link" onClick={()=>this.hide()}>取消</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
)
}
componentDidMount() {
let that = this
let select2 = $(this.refs['toUser']).select2({
language: 'zh-CN',
placeholder: '选择用户',
width: '100%',
minimumInputLength: 1,
maximumSelectionLength: 1,
ajax: {
url: rb.baseUrl + '/commons/search',
delay: 300,
data: function(params) {
let query = {
entity: 'User',
qfields: 'loginName,fullName,email',
qtext: params.term,
}
return query
},
processResults: function(data){
let rs = data.data.map((item) => { return item })
return { results: rs }
}
}
}).on('change.select2', function(e){
})
this.show()
}
componentWillUnmount() {
$(this.refs['toUser']).select2('destroy')
$(this.refs['cascades']).select2('destroy')
}
showCascades() {
let that = this
$.get(rb.baseUrl + '/commons/metadata/references?entity=' + this.props.entity, function(res){
that.setState({ cascadesSpec: true, cascadesEntity: res.data }, function(){
$(that.refs['cascades']).select2({
language: 'zh-CN',
placeholder: '选择关联实体 (可选)',
})
})
})
}
show(callback) {
$(this.refs['rbmodal']).modal({ show: true, backdrop: 'static' })
typeof callback == 'function' && callback(this)
}
hide() {
$(this.refs['rbmodal']).modal('hide')
}
post() {
let to = $(this.refs['toUser']).val()
if (!to || to.length < 1) { rb.notice('请选择' + this.opType + '给谁'); return }
let cas = $(this.refs['cascades']).val() || []
let that = this
let btns = $(this.refs['actions']).find('.btn').button('loading')
$.post(`${rb.baseUrl}/app/entity/record-${this.state.type}?id=${this.state.ids.join(',')}&cascades=${cas.join(',')}&to=${to.join(',')}`, function(res){
if (res.error_code == 0){
that.hide()
rb.notice('已成功' + that.opType + ' ' + (res.data.assigned || res.data.shared) + ' 条记录', 'success')
if (RbListPage) RbListPage._RbList.reload()
if (RbViewPage) location.reload()
} else {
rb.notice(res.error_msg || ('操作失败,请稍后重试'), 'danger')
}
btns.button('reset')
})
}
}
var rb = rb || {}
// props = { entity, id }
rb.AssignDialog = function(props){
props = { ...props, type: 'assign' }
return renderRbcomp(<TheBothDialog { ...props} />)
}
// props = { entity, id }
rb.ShareDialog = function(props){
props = { ...props, type: 'share' }
return renderRbcomp(<TheBothDialog { ...props} />)
}

View file

@ -580,7 +580,7 @@ class RbFormReference extends RbFormElement {
}
renderElement() {
return (
<select ref="field-value" className="form-control form-control-sm" onChange={this.handleChange} multiple="multiple" style={{width:'100%'}} />
<select ref="field-value" className="form-control form-control-sm" onChange={this.handleChange} multiple="multiple" />
)
}
renderViewElement() {
@ -593,8 +593,10 @@ class RbFormReference extends RbFormElement {
let select2 = $(this.refs['field-value']).select2({
language: 'zh-CN',
placeholder: '选择' + that.props.label,
width: '100%',
allowClear: true,
minimumInputLength: 1,
maximumSelectionLength: 1,
ajax: {
url: rb.baseUrl + '/app/entity/ref-search',
delay: 300,
@ -607,9 +609,7 @@ class RbFormReference extends RbFormElement {
return query
},
processResults: function(data){
let rs = data.data.map((item) => {
return item
})
let rs = data.data.map((item) => { return item })
return { results: rs }
}
}

View file

@ -233,6 +233,12 @@ class RbList extends React.Component {
return this.__selectedRows
}
getSelectedIds() {
if (!this.__selectedRows || this.__selectedRows.length < 1) { rb.notice('未选中任何记录'); return [] }
let ids = this.__selectedRows.map((item) => { return item[0] })
return ids
}
search(filter) {
this.fetchList(filter)
}
@ -328,9 +334,7 @@ rb.RbListPagination = function(props, target) {
//
const RbListPage = {
_RbList: null,
_ModalSColumns: null,
_ModalAssign: null,
_ModalShare: null,
_ModalColumns: null,
// @config - List config
// @entity - [Label, Name, Icon]
@ -386,19 +390,19 @@ const RbListPage = {
})
$('.J_assign').click(function(){
if (that._RbList.getSelectedRows().length < 1) { rb.notice('请选择要分派的记录'); return}
if (that._ModalAssign) that._ModalAssign.show()
else that._ModalAssign = rb.modal(`${rb.baseUrl}/page/general-entity/assign?entity=${entity[1]}`, '分派记录')
let ids = that._RbList.getSelectedIds()
if (ids.length < 1) return
rb.AssignDialog({ entity: entity[1], ids: ids })
})
$('.J_share').click(function(){
if (that._RbList.getSelectedRows().length < 1) { rb.notice('请选择要共享的记录'); return}
if (that._ModalShare) that._ModalShare.show()
else that._ModalShare = rb.modal(`${rb.baseUrl}/page/general-entity/share?entity=${entity[1]}`, '共享记录')
let ids = that._RbList.getSelectedIds()
if (ids.length < 1) return
rb.ShareDialog({ entity: entity[1], ids: ids })
})
$('.J_columns').click(function(){
if (that._ModalSColumns) that._ModalSColumns.show()
else that._ModalSColumns = rb.modal(`${rb.baseUrl}/page/general-entity/show-columns?entity=${entity[1]}`, '设置列显示')
if (that._ModalColumns) that._ModalColumns.show()
else that._ModalColumns = rb.modal(`${rb.baseUrl}/page/general-entity/show-columns?entity=${entity[1]}`, '设置列显示')
})
// Privileges
@ -412,6 +416,13 @@ const RbListPage = {
let divi = $('.J_actions .dropdown-menu').children().first()
if (divi.hasClass('dropdown-divider')) divi.remove()
}
},
closeModal() {
if (this._ModalColumns) this._ModalColumns.hide()
},
resizeModal() {
if (this._ModalColumns) this._ModalColumns.resize()
}
}

View file

@ -43,4 +43,25 @@ var rb = rb || {}
// props = { entity, recordId }
rb.RbViewForm = function(props, target){
return renderRbcomp(<RbViewForm {...props} />, target || 'tab-rbview')
}
const RbViewPage = {
_RbViewForm: null,
init(id, entity) {
this._RbViewForm = rb.RbViewForm({ entity: entity[1], id: id })
$('.J_edit').click(function(){
rb.RbFormModal({ id: id, title: `编辑${entity[0]}`, entity: entity[1], icon: entity[2] })
})
let that = this
$('.J_assign').click(function(){
rb.AssignDialog({ entity: entity[1], ids: id })
})
$('.J_share').click(function(){
rb.ShareDialog({ entity: entity[1], ids: id })
})
}
}

View file

@ -42,8 +42,8 @@
<div class="btn-group btn-space J_actions">
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown">更多 <i class="icon zmdi zmdi-more-vert"></i></button>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item J_share"><i class="icon zmdi zmdi-slideshare"></i> 共享</a>
<a class="dropdown-item J_assign"><i class="icon zmdi zmdi-mail-reply-all"></i> 分派</a>
<a class="dropdown-item J_share"><i class="icon zmdi zmdi-slideshare"></i> 共享</a>
<!--
<div class="dropdown-divider"></div>
<a class="dropdown-item J_exports"><i class="icon zmdi zmdi-download"></i> 导出</a>
@ -74,6 +74,7 @@
<script src="${baseUrl}/assets/js/rb-list.jsx" type="text/babel"></script>
<script src="${baseUrl}/assets/js/rb-forms.jsx" type="text/babel"></script>
<script src="${baseUrl}/assets/js/rb-advfilter.jsx" type="text/babel"></script>
<script src="${baseUrl}/assets/js/assign-share.jsx" type="text/babel"></script>
<script type="text/babel">
$(document).ready(function(){
RbListPage.init(

View file

@ -30,11 +30,11 @@
<div class="col-sm-2">
<div class="view-oper">
<div class="btns">
<button class="btn btn-secondary J_edit" type="button">编辑</button>
<button class="btn btn-secondary J_edit" type="button"><i class="icon zmdi zmdi-border-color"></i> 编辑</button>
</div>
<div class="btns">
<button class="btn btn-secondary J_assgin" type="button">分配</button>
<button class="btn btn-secondary J_share" type="button">共享</button>
<button class="btn btn-secondary J_assign" type="button"><i class="icon zmdi zmdi-mail-reply-all"></i> 分派</button>
<button class="btn btn-secondary J_share" type="button"><i class="icon zmdi zmdi-slideshare"></i> 共享</button>
</div>
</div>
</div>
@ -43,15 +43,10 @@
<%@ include file="/_include/Foot.jsp"%>
<script src="${baseUrl}/assets/js/rb-forms.jsx" type="text/babel"></script>
<script src="${baseUrl}/assets/js/rb-view.jsx" type="text/babel"></script>
<script src="${baseUrl}/assets/js/assign-share.jsx" type="text/babel"></script>
<script type="text/babel">
var rbFromView
$(document).ready(function(){
const recordId = '${id}'
rbFromView = rb.RbViewForm({ entity:'${entityName}', id:recordId })
$('.J_edit').click(function(){
rb.RbFormModal({ id:recordId, title:'编辑${entityLabel}',entity:'${entityName}', icon:'${entityIcon}' })
});
RbViewPage.init('${id}', [ '${entityLabel}', '${entityName}', '${entityIcon}'])
});
</script>
</body>