From 6fd7d0943dcbbe959325c2a9bf0316d0ce2b3550 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 19 Jul 2023 13:34:56 +0800 Subject: [PATCH] * Rewrite for batch edit user page. --- module/company/config/table.php | 7 +++- module/company/js/browse.ui.js | 12 +++++++ module/company/ui/browse.html.php | 13 +++---- module/personnel/config.php | 2 +- module/user/config/form.php | 22 ++++++++++++ module/user/control.php | 17 ++++----- module/user/js/common.ui.js | 2 +- module/user/model.php | 6 ++-- module/user/ui/batchcreate.html.php | 2 +- module/user/ui/batchedit.html.php | 55 +++++++++++++++++++++++++++++ 10 files changed, 114 insertions(+), 24 deletions(-) create mode 100644 module/company/js/browse.ui.js create mode 100644 module/user/ui/batchedit.html.php diff --git a/module/company/config/table.php b/module/company/config/table.php index 8237d1a96e..89b559a7f7 100644 --- a/module/company/config/table.php +++ b/module/company/config/table.php @@ -29,9 +29,12 @@ $config->company->user->actionList['delete']['data-toggle'] = 'modal'; $config->company->user->dtable = new stdclass(); $config->company->user->dtable->fieldList['id']['name'] = 'id'; $config->company->user->dtable->fieldList['id']['title'] = $lang->idAB; -$config->company->user->dtable->fieldList['id']['type'] = 'id'; +$config->company->user->dtable->fieldList['id']['type'] = 'checkID'; $config->company->user->dtable->fieldList['id']['fixed'] = 'left'; $config->company->user->dtable->fieldList['id']['sortType'] = true; +$config->company->user->dtable->fieldList['id']['checkbox'] = true; +$config->company->user->dtable->fieldList['id']['show'] = true; +$config->company->user->dtable->fieldList['id']['group'] = 1; $config->company->user->dtable->fieldList['realname']['name'] = 'realname'; $config->company->user->dtable->fieldList['realname']['title'] = $lang->user->realname; @@ -39,6 +42,7 @@ $config->company->user->dtable->fieldList['realname']['type'] = 'text'; $config->company->user->dtable->fieldList['realname']['group'] = '1'; $config->company->user->dtable->fieldList['realname']['fixed'] = 'left'; $config->company->user->dtable->fieldList['realname']['sortType'] = true; +$config->company->user->dtable->fieldList['realname']['group'] = '1'; $config->company->user->dtable->fieldList['account']['name'] = 'account'; $config->company->user->dtable->fieldList['account']['title'] = $lang->user->account; @@ -86,6 +90,7 @@ else $config->company->user->dtable->fieldList['email']['name'] = 'email'; $config->company->user->dtable->fieldList['email']['title'] = $lang->user->email; $config->company->user->dtable->fieldList['email']['type'] = 'text'; +$config->company->user->dtable->fieldList['email']['width'] = 200; $config->company->user->dtable->fieldList['email']['sortType'] = true; $config->company->user->dtable->fieldList['email']['group'] = '4'; diff --git a/module/company/js/browse.ui.js b/module/company/js/browse.ui.js new file mode 100644 index 0000000000..f26bedc88a --- /dev/null +++ b/module/company/js/browse.ui.js @@ -0,0 +1,12 @@ +$(document).off('click', '.batch-btn').on('click', '.batch-btn', function() +{ + const $this = $(this); + const dtable = zui.DTable.query($('#userList')); + const checkedList = dtable.$.getChecks(); + if(!checkedList.length) return; + + const postData = new FormData(); + checkedList.forEach((id) => postData.append('users[]', id)); + + postAndLoadPage($this.data('url'), postData); +}); diff --git a/module/company/ui/browse.html.php b/module/company/ui/browse.html.php index 870f9d7538..b6cb15bcbe 100644 --- a/module/company/ui/browse.html.php +++ b/module/company/ui/browse.html.php @@ -53,24 +53,25 @@ sidebar 'modules' => $deptTree, 'activeKey' => $type == 'bydept' ? $param : 0, 'settingLink' => $settingLink, - 'closeLink' => $closeLink + 'closeLink' => $closeLink, + 'showDisplay' => false, + 'settingText' => $lang->dept->manage, ))) ); $footToolbar = common::hasPriv('user', 'batchEdit') ? array( - 'items' => array - ( - array('text' => $lang->edit, 'className' => 'secondary batch-btn', 'data-url' => createLink('user', 'batchEdit')), - ), + 'items' => array(array('text' => $lang->edit, 'className' => 'secondary batch-btn', 'data-url' => createLink('user', 'batchEdit'))), 'btnProps' => array('size' => 'sm', 'btnType' => 'secondary') -) : ''; +) : null; if(common::hasPriv('user', 'batchEdit')) $this->config->company->user->dtable->fieldList['id']['type'] = 'checkID'; $tableData = initTableData($users, $this->config->company->user->dtable->fieldList, $this->loadModel('user')); dtable ( + setID('userList'), set::cols($this->config->company->user->dtable->fieldList), set::data($tableData), + set::checkable(common::hasPriv('user', 'batchEdit')), set::fixedLeftWidth('0.2'), set::footToolbar($footToolbar), set::footPager(usePager()), diff --git a/module/personnel/config.php b/module/personnel/config.php index 59ff6d566e..f62aabe31d 100644 --- a/module/personnel/config.php +++ b/module/personnel/config.php @@ -1,7 +1,7 @@ personnel->accessible = new stdClass(); -$config->personnel->accessible->search['module'] = 'accessible'; +$config->personnel->accessible->search['module'] = 'personnel'; $config->personnel->accessible->search['fields']['realname'] = $lang->personnel->realName; $config->personnel->accessible->search['fields']['role'] = $lang->personnel->job; $config->personnel->accessible->search['fields']['account'] = $lang->personnel->userName; diff --git a/module/user/config/form.php b/module/user/config/form.php index 906aad1d23..e19c778880 100644 --- a/module/user/config/form.php +++ b/module/user/config/form.php @@ -1,4 +1,5 @@ user->form = new stdclass(); $config->user->form->batchCreate = common::formConfig('user', 'batchCreate'); $config->user->form->batchCreate['dept'] = array('required' => false, 'type' => 'int', 'default' => 0); @@ -14,3 +15,24 @@ $config->user->form->batchCreate['email'] = array('required' => false, 'type' $config->user->form->batchCreate['gender'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->user->form->batchCreate['password'] = array('required' => true, 'type' => 'string', 'default' => ''); $config->user->form->batchCreate['join'] = array('required' => false, 'type' => 'date', 'default' => null); + +$config->user->form->batchEdit = array(); +$config->user->form->batchEdit['dept'] = array('required' => false, 'type' => 'int', 'width' => '200px', 'name' => 'dept', 'label' => $lang->user->dept, 'control' => 'picker', 'default' => 0, 'ditto' => true); +$config->user->form->batchEdit['account'] = array('required' => true, 'type' => 'string', 'width' => '160px', 'name' => 'account', 'label' => $lang->user->account, 'control' => 'text', 'default' => '', 'filter' => 'trim', 'base' => true); +$config->user->form->batchEdit['realname'] = array('required' => true, 'type' => 'string', 'width' => '150px', 'name' => 'realname', 'label' => $lang->user->realname, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['visions'] = array('required' => true, 'type' => 'string', 'width' => '200px', 'name' => 'visions', 'label' => $lang->user->visions, 'control' => 'picker', 'default' => $config->vision, 'multiple' => true, 'filter' => 'join'); +$config->user->form->batchEdit['role'] = array('required' => false, 'type' => 'string', 'width' => '200px', 'name' => 'role', 'label' => $lang->user->role, 'control' => 'picker', 'default' => '', 'ditto' => true, 'items' => $lang->user->roleList); +$config->user->form->batchEdit['type'] = array('required' => false, 'type' => 'string', 'width' => '200px', 'name' => 'type', 'label' => $lang->user->type, 'control' => 'picker', 'default' => 'inside', 'items' => $lang->user->typeList); +$config->user->form->batchEdit['commiter'] = array('required' => false, 'type' => 'string', 'width' => '160px', 'name' => 'commiter', 'label' => $lang->user->commiter, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['email'] = array('required' => false, 'type' => 'string', 'width' => '160px', 'name' => 'email', 'label' => $lang->user->email, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['join'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'join', 'label' => $lang->user->join, 'control' => 'date', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['skype'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'skype', 'label' => $lang->user->skype, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['qq'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'qq', 'label' => $lang->user->qq, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['dingding'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'dingding', 'label' => $lang->user->dingding, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['weixin'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'weixin', 'label' => $lang->user->weixin, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['mobile'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'mobile', 'label' => $lang->user->mobile, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['slack'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'slack', 'label' => $lang->user->slack, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['whatsapp'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'whatsapp', 'label' => $lang->user->whatsapp, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['phone'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'phone', 'label' => $lang->user->phone, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['address'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'address', 'label' => $lang->user->address, 'control' => 'text', 'default' => '', 'filter' => 'trim'); +$config->user->form->batchEdit['zipcode'] = array('required' => false, 'type' => 'date', 'width' => '160px', 'name' => 'zipcode', 'label' => $lang->user->zipcode, 'control' => 'text', 'default' => '', 'filter' => 'trim'); diff --git a/module/user/control.php b/module/user/control.php index ad54e0b10d..d7be74f743 100755 --- a/module/user/control.php +++ b/module/user/control.php @@ -660,19 +660,14 @@ class user extends control */ public function batchEdit($deptID = 0) { - if(isset($_POST['users'])) + if(empty($_POST)) return $this->send(array('result' => 'success', 'load' => $this->session->userList ? $this->session->userList : $this->createLink('company', 'browse', "deptID=$deptID"))); + if(!empty($_POST['account'])) { - $this->view->users = $this->dao->select('*')->from(TABLE_USER)->where('id')->in($this->post->users)->orderBy('id')->fetchAll('id'); - } - elseif($_POST) - { - if($this->post->account) $this->user->batchEdit(); - return print(js::locate($this->session->userList ? $this->session->userList : $this->createLink('company', 'browse', "deptID=$deptID"), 'parent')); - } - else - { - return print(js::locate($this->session->userList ? $this->session->userList : $this->createLink('company', 'browse', "deptID=$deptID"), 'parent')); + $this->user->batchEdit(); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $this->session->userList ? $this->session->userList : $this->createLink('company', 'browse', "deptID=$deptID"))); } + if(isset($_POST['users'])) $this->view->users = $this->dao->select('*')->from(TABLE_USER)->where('id')->in($this->post->users)->orderBy('id')->fetchAll('id'); $this->lang->user->menu = $this->lang->company->menu; $this->lang->user->menuOrder = $this->lang->company->menuOrder; diff --git a/module/user/js/common.ui.js b/module/user/js/common.ui.js index d9e9ecee7a..f15bcac530 100644 --- a/module/user/js/common.ui.js +++ b/module/user/js/common.ui.js @@ -62,7 +62,7 @@ $(document).ready(function() $('#verifyPassword').closest('form').find('button[type="submit"]').on('click', function() { var password = $('input#verifyPassword').val().trim(); - var rand = $('input#verifyRand').val(); + var rand = $('input[name=verifyRand]').val(); if(!verifyEncrypted && password) $('input#verifyPassword').val(md5(md5(password) + rand)); verifyEncrypted = true; }); diff --git a/module/user/model.php b/module/user/model.php index a567d5356e..da390e043d 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -685,10 +685,10 @@ class userModel extends model public function batchEdit() { $data = fixer::input('post')->get(); - if(empty($_POST['verifyPassword']) or $this->post->verifyPassword != md5($this->app->user->password . $this->session->rand)) helper::end(js::alert($this->lang->user->error->verifyPassword)); + if(empty($_POST['verifyPassword']) or $this->post->verifyPassword != md5($this->app->user->password . $this->session->rand)) return dao::$errors['verifyPassword'] = $this->lang->user->error->verifyPassword; - $oldUsers = $this->dao->select('id, account, email')->from(TABLE_USER)->where('id')->in(array_keys($data->account))->fetchAll('id'); - $accountGroup = $this->dao->select('id, account')->from(TABLE_USER)->where('account')->in($data->account)->fetchGroup('account', 'id'); + $oldUsers = $this->dao->select('id,account,email')->from(TABLE_USER)->where('id')->in(array_keys($data->account))->fetchAll('id'); + $accountGroup = $this->dao->select('id,account')->from(TABLE_USER)->where('account')->in($data->account)->fetchGroup('account', 'id'); $accounts = array(); foreach($data->account as $id => $account) diff --git a/module/user/ui/batchcreate.html.php b/module/user/ui/batchcreate.html.php index be97312c1d..b07cf980ad 100644 --- a/module/user/ui/batchcreate.html.php +++ b/module/user/ui/batchcreate.html.php @@ -27,7 +27,7 @@ foreach(explode(',', $config->user->create->requiredFields) as $field) formBatchPanel ( - import('/js/md5.js', 'js'), + h::import($config->webRoot . 'js/md5.js', 'js'), set::headingClass('user-batchcreate-heading'), set::title($lang->user->batchCreate), on::change('[data-name="new"]', 'toggleNew'), diff --git a/module/user/ui/batchedit.html.php b/module/user/ui/batchedit.html.php new file mode 100644 index 0000000000..38465dd5a6 --- /dev/null +++ b/module/user/ui/batchedit.html.php @@ -0,0 +1,55 @@ + + * @package user + * @link https://www.zentao.net + */ +namespace zin; + +$items = array(); +$items['id'] = array('name' => 'id', 'label' => $lang->idAB, 'control' => 'index', 'width' => '60px'); +$items = array_merge($items, $config->user->form->batchEdit); +$items['dept']['items'] = $depts; +$items['visions']['items'] = $visionList; + +$fnGenerateCustomizedFields = function() use ($showFields, $customFields) +{ + global $config; + $showFields = ",{$showFields},"; + $fields = array(); + $defaultFields = explode(',', $config->user->custom->batchEditFields); + foreach($customFields as $name => $text) $fields[] = array('name' => $name, 'text' => $text, 'show' => str_contains($showFields, ",$name,"), 'default' => in_array($name, $defaultFields)); + return $fields; +}; + +formBatchPanel +( + h::import($config->webRoot . 'js/md5.js', 'js'), + set::customFields(array('items' => $fnGenerateCustomizedFields(), 'urlParams' => 'module=user§ion=custom&key=batchEditFields')), + set::title($lang->user->batchEdit), + set::mode('edit'), + set::items($items), + set::data(array_values($users)), + div + ( + setClass('form-grid'), + formGroup + ( + setClass('flex verify-box'), + set::width('400px'), + set::label($lang->user->verifyPassword), + set::labelClass('w-10 mr-2'), + set::control('password'), + set::name('verifyPassword'), + set::value(''), + set::required(true), + ), + ), +); +formHidden('verifyRand', $rand); + +render();