diff --git a/src/main/java/com/rebuild/web/base/SimpleSearch.java b/src/main/java/com/rebuild/web/base/SimpleSearch.java index 84cff767d..352e23a07 100644 --- a/src/main/java/com/rebuild/web/base/SimpleSearch.java +++ b/src/main/java/com/rebuild/web/base/SimpleSearch.java @@ -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); diff --git a/src/main/webapp/assets/css/rb-page.css b/src/main/webapp/assets/css/rb-page.css index 66eae547f..419a59411 100644 --- a/src/main/webapp/assets/css/rb-page.css +++ b/src/main/webapp/assets/css/rb-page.css @@ -175,6 +175,10 @@ body.dialog .main-content .footer, padding: 3px 6px } +.select2.select2-container { + width: 100%; +} + textarea.row2x { height: 52px !important; resize: none; diff --git a/src/main/webapp/assets/js/assign-share.js b/src/main/webapp/assets/js/assign-share.js index 3901e2c69..521757db8 100644 --- a/src/main/webapp/assets/js/assign-share.js +++ b/src/main/webapp/assets/js/assign-share.js @@ -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() }) }); \ No newline at end of file diff --git a/src/main/webapp/assets/js/assign-share.jsx b/src/main/webapp/assets/js/assign-share.jsx new file mode 100644 index 000000000..9bb722b7e --- /dev/null +++ b/src/main/webapp/assets/js/assign-share.jsx @@ -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 ( +
+
+
+
+
+

{this.opType}

+ +
+
+
+
+ +
+
{'选中的记录 (' + this.state.ids.split(',').length + '条)'}
+
+
+
+ +
+ + {(this.state.cascadesEntity || []).map((item) => { + return + })} + +
+
+
+
+ + this.hide()}>取消 +
+
+
+
+
+
+
+
+ ) + } + 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() +} +// props = { entity, id } +rb.ShareDialog = function(props){ + props = { ...props, type: 'share' } + return renderRbcomp() +} \ No newline at end of file diff --git a/src/main/webapp/assets/js/rb-forms.jsx b/src/main/webapp/assets/js/rb-forms.jsx index d53ed443f..e4d9794db 100644 --- a/src/main/webapp/assets/js/rb-forms.jsx +++ b/src/main/webapp/assets/js/rb-forms.jsx @@ -580,7 +580,7 @@ class RbFormReference extends RbFormElement { } renderElement() { return ( - ) } 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 } } } diff --git a/src/main/webapp/assets/js/rb-list.jsx b/src/main/webapp/assets/js/rb-list.jsx index 634e88821..da263cf33 100644 --- a/src/main/webapp/assets/js/rb-list.jsx +++ b/src/main/webapp/assets/js/rb-list.jsx @@ -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() } } diff --git a/src/main/webapp/assets/js/rb-view.jsx b/src/main/webapp/assets/js/rb-view.jsx index e2c95610d..2f56abd77 100644 --- a/src/main/webapp/assets/js/rb-view.jsx +++ b/src/main/webapp/assets/js/rb-view.jsx @@ -43,4 +43,25 @@ var rb = rb || {} // props = { entity, recordId } rb.RbViewForm = function(props, target){ return renderRbcomp(, 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 }) + }) + } } \ No newline at end of file diff --git a/src/main/webapp/general-entity/record-list.jsp b/src/main/webapp/general-entity/record-list.jsp index a256c2027..2805e4e22 100644 --- a/src/main/webapp/general-entity/record-list.jsp +++ b/src/main/webapp/general-entity/record-list.jsp @@ -42,8 +42,8 @@