From 2a97c21c0cc16d3a6b2dce9620897751be80dc82 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 17 Feb 2022 14:54:57 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E5=9F=BA=E4=BA=8EPHP7.1=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=BD=BF=E7=94=A8Catch=E5=A4=9A=E4=B8=AA=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/library/traits/Backend.php | 36 ++++---------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/application/admin/library/traits/Backend.php b/application/admin/library/traits/Backend.php index f81f62fe..37b73085 100755 --- a/application/admin/library/traits/Backend.php +++ b/application/admin/library/traits/Backend.php @@ -110,13 +110,7 @@ trait Backend } $result = $this->model->allowField(true)->save($params); Db::commit(); - } catch (ValidateException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { + } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -161,13 +155,7 @@ trait Backend } $result = $row->allowField(true)->save($params); Db::commit(); - } catch (ValidateException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { + } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -207,10 +195,7 @@ trait Backend $count += $v->delete(); } Db::commit(); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { + } catch (PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -248,10 +233,7 @@ trait Backend $count += $v->delete(true); } Db::commit(); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { + } catch (PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -288,10 +270,7 @@ trait Backend $count += $item->restore(); } Db::commit(); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { + } catch (PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -327,10 +306,7 @@ trait Backend $count += $item->allowField(true)->isUpdate(true)->save($values); } Db::commit(); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { + } catch (PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } From ff51380686b68b56fc3847e0ccc1fe6af4b93c36 Mon Sep 17 00:00:00 2001 From: "aa820t@126.com" Date: Wed, 30 Mar 2022 08:21:20 +0000 Subject: [PATCH 02/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20think=20=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E5=BC=95=E5=AF=BC=E6=96=87=E4=BB=B6=20=E4=B8=BA?= =?UTF-8?q?=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=20=E5=9C=A8=E9=9D=9E?= =?UTF-8?q?=E6=9C=AC=E9=A1=B9=E7=9B=AE=E6=A0=B9=E7=9B=AE=E5=BD=95=E4=B8=8B?= =?UTF-8?q?,=20=E6=89=A7=E8=A1=8Cphp=20think=20=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?,=20=E4=BD=BF=E7=94=A8=E5=BC=95=E7=94=A8=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E5=90=8E=E7=BB=AD=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=89=A7=E8=A1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- think | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/think b/think index 8afa938a..8eeb81b5 100755 --- a/think +++ b/think @@ -14,4 +14,4 @@ define('APP_PATH', __DIR__ . '/application/'); // 加载框架引导文件 -require './thinkphp/console.php'; \ No newline at end of file +require __DIR__ . '/thinkphp/console.php'; \ No newline at end of file From e67f9a20c54b0a67a0290ced7ee18c03a9a7d63c Mon Sep 17 00:00:00 2001 From: F4nniu Date: Thu, 31 Mar 2022 23:28:16 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E4=B8=8D=E6=94=AF=E6=8C=81=200=20?= =?UTF-8?q?=E5=BC=80=E5=A4=B4=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/view/user/profile.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/index/view/user/profile.html b/application/index/view/user/profile.html index 62e6b05b..43a17168 100644 --- a/application/index/view/user/profile.html +++ b/application/index/view/user/profile.html @@ -155,7 +155,7 @@
- + 获取验证码 From a4617c7f286cfb60f5ecd63ad27d07d2b2702125 Mon Sep 17 00:00:00 2001 From: F4nniu Date: Fri, 1 Apr 2022 09:58:43 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E4=B8=8D=E6=94=AF=E6=8C=81=200=20=E5=BC=80=E5=A4=B4?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/view/common/captcha.html | 4 ++-- application/index/view/user/login.html | 2 +- application/index/view/user/profile.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/application/index/view/common/captcha.html b/application/index/view/common/captcha.html index 8db2df91..d424e70f 100644 --- a/application/index/view/common/captcha.html +++ b/application/index/view/common/captcha.html @@ -1,11 +1,11 @@ {if "[type]" == 'email'} - + 发送验证码 {elseif "[type]" == 'mobile'/} - + 发送验证码 diff --git a/application/index/view/user/login.html b/application/index/view/user/login.html index eb3ecfb7..f75237b8 100755 --- a/application/index/view/user/login.html +++ b/application/index/view/user/login.html @@ -69,7 +69,7 @@
- + {:__('Send verification code')} diff --git a/application/index/view/user/profile.html b/application/index/view/user/profile.html index 43a17168..e0b57b37 100644 --- a/application/index/view/user/profile.html +++ b/application/index/view/user/profile.html @@ -121,7 +121,7 @@
- + 获取验证码 From 036c2dcc25c588aa86d1bc94eceb2bdc5f67bfd5 Mon Sep 17 00:00:00 2001 From: qhyan Date: Tue, 19 Apr 2022 20:29:47 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/lang/zh-cn/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/api/lang/zh-cn/user.php b/application/api/lang/zh-cn/user.php index eb40897f..e98e4cd0 100644 --- a/application/api/lang/zh-cn/user.php +++ b/application/api/lang/zh-cn/user.php @@ -7,7 +7,7 @@ return [ 'Sign up successful' => '注册成功', 'Username can not be empty' => '用户名不能为空', 'Username must be 3 to 30 characters' => '用户名必须3-30个字符', - 'Username must be 6 to 30 characters' => '用户名必须3-30个字符', + 'Username must be 6 to 30 characters' => '用户名必须6-30个字符', 'Password can not be empty' => '密码不能为空', 'Password must be 6 to 30 characters' => '密码必须6-30个字符', 'Mobile is incorrect' => '手机格式不正确', From 5022da9cea64e5497cd7374d296e72a59a0d274d Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 25 Apr 2022 15:26:41 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9C=A8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Table=E7=BB=84=E4=BB=B6=E6=97=B6=EF=BC=8C=E4=BC=A0?= =?UTF-8?q?=E9=80=92pageSize=E5=8F=82=E6=95=B0=E7=A1=AE=E8=A2=AB=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=85=A8=E5=B1=80=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=BC=80=E6=94=BE=E5=85=A8=E5=B1=80=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=B0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/require-table.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index 61359431..ef6d7b3e 100644 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -190,12 +190,6 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table table.on('refresh.bs.table', function (e, settings, data) { $(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin"); }); - //当表格分页变更时 - table.on('page-change.bs.table', function (e, page, pagesize) { - if (!isNaN(pagesize)) { - localStorage.setItem("pagesize", pagesize); - } - }); //当执行搜索时 table.on('search.bs.table common-search.bs.table', function (e, settings, data) { table.trigger("uncheckbox"); @@ -540,6 +534,12 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table Table.list[id] = table; return table; }, + // 设置全局分页的单页显示数 + pageSize: function (pageSize) { + if (!isNaN(pageSize)) { + localStorage.setItem('pagesize', pageSize); + } + }, // 批量操作请求 multi: function (action, ids, table, element) { var options = table.bootstrapTable('getOptions'); From 940d4f0410a0b2e3c3e0fd0c3a8fec6edb89a8db Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 4 May 2022 11:49:25 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/library/traits/Backend.php | 395 ++++++++++--------- 1 file changed, 209 insertions(+), 186 deletions(-) diff --git a/application/admin/library/traits/Backend.php b/application/admin/library/traits/Backend.php index 37b73085..b91a5629 100755 --- a/application/admin/library/traits/Backend.php +++ b/application/admin/library/traits/Backend.php @@ -9,12 +9,16 @@ use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xls; use PhpOffice\PhpSpreadsheet\Reader\Csv; use think\Db; +use think\db\exception\BindParamException; +use think\db\exception\DataNotFoundException; +use think\db\exception\ModelNotFoundException; +use think\exception\DbException; use think\exception\PDOException; use think\exception\ValidateException; +use think\response\Json; trait Backend { - /** * 排除前台提交过来的字段 * @param $params @@ -24,109 +28,114 @@ trait Backend { if (is_array($this->excludeFields)) { foreach ($this->excludeFields as $field) { - if (key_exists($field, $params)) { + if (array_key_exists($field, $params)) { unset($params[$field]); } } - } else { - if (key_exists($this->excludeFields, $params)) { - unset($params[$this->excludeFields]); - } + } else if (array_key_exists($this->excludeFields, $params)) { + unset($params[$this->excludeFields]); } return $params; } - /** * 查看 + * + * @return string|Json + * @throws \think\Exception + * @throws DbException */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); - if ($this->request->isAjax()) { - //如果发送的来源是Selectpage,则转发到Selectpage - if ($this->request->request('keyField')) { - return $this->selectpage(); - } - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); - - $list = $this->model - ->where($where) - ->order($sort, $order) - ->paginate($limit); - - $result = array("total" => $list->total(), "rows" => $list->items()); - - return json($result); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); } - return $this->view->fetch(); + //如果发送的来源是 Selectpage,则转发到 Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); } /** * 回收站 + * + * @return string|Json + * @throws \think\Exception */ public function recyclebin() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); - if ($this->request->isAjax()) { - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); - - $list = $this->model - ->onlyTrashed() - ->where($where) - ->order($sort, $order) - ->paginate($limit); - - $result = array("total" => $list->total(), "rows" => $list->items()); - - return json($result); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); } - return $this->view->fetch(); + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->onlyTrashed() + ->where($where) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); } /** * 添加 + * + * @return string + * @throws \think\Exception */ public function add() { - if ($this->request->isPost()) { - $params = $this->request->post("row/a"); - if ($params) { - $params = $this->preExcludeFields($params); - - if ($this->dataLimit && $this->dataLimitFieldAutoFill) { - $params[$this->dataLimitField] = $this->auth->id; - } - $result = false; - Db::startTrans(); - try { - //是否采用模型验证 - if ($this->modelValidate) { - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; - $this->model->validateFailException(true)->validate($validate); - } - $result = $this->model->allowField(true)->save($params); - Db::commit(); - } catch (ValidateException|PDOException|Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($result !== false) { - $this->success(); - } else { - $this->error(__('No rows were inserted')); - } - } + if (false === $this->request->isPost()) { + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } - return $this->view->fetch(); + $params = $this->preExcludeFields($params); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException()->validate($validate); + } + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); } /** * 编辑 + * + * @param $ids + * @return string + * @throws DbException + * @throws \think\Exception */ public function edit($ids = null) { @@ -135,102 +144,69 @@ trait Backend $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); - if (is_array($adminIds)) { - if (!in_array($row[$this->dataLimitField], $adminIds)) { - $this->error(__('You have no permission')); - } + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); } - if ($this->request->isPost()) { - $params = $this->request->post("row/a"); - if ($params) { - $params = $this->preExcludeFields($params); - $result = false; - Db::startTrans(); - try { - //是否采用模型验证 - if ($this->modelValidate) { - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; - $row->validateFailException(true)->validate($validate); - } - $result = $row->allowField(true)->save($params); - Db::commit(); - } catch (ValidateException|PDOException|Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($result !== false) { - $this->success(); - } else { - $this->error(__('No rows were updated')); - } - } + if (false === $this->request->isPost()) { + $this->view->assign('row', $row); + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } - $this->view->assign("row", $row); - return $this->view->fetch(); + $params = $this->preExcludeFields($params); + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException()->validate($validate); + } + $result = $row->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if (false === $result) { + $this->error(__('No rows were updated')); + } + $this->success(); } /** * 删除 + * + * @param $ids + * @return void + * @throws DbException + * @throws DataNotFoundException + * @throws ModelNotFoundException */ - public function del($ids = "") + public function del($ids = null) { - if (!$this->request->isPost()) { + if (false === $this->request->isPost()) { $this->error(__("Invalid parameters")); } - $ids = $ids ? $ids : $this->request->post("ids"); - if ($ids) { - $pk = $this->model->getPk(); - $adminIds = $this->getDataLimitAdminIds(); - if (is_array($adminIds)) { - $this->model->where($this->dataLimitField, 'in', $adminIds); - } - $list = $this->model->where($pk, 'in', $ids)->select(); - - $count = 0; - Db::startTrans(); - try { - foreach ($list as $k => $v) { - $count += $v->delete(); - } - Db::commit(); - } catch (PDOException|Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($count) { - $this->success(); - } else { - $this->error(__('No rows were deleted')); - } + $ids = $ids ?: $this->request->post("ids"); + if (empty($ids)) { + $this->error(__('Parameter %s can not be empty', 'ids')); } - $this->error(__('Parameter %s can not be empty', 'ids')); - } - - /** - * 真实删除 - */ - public function destroy($ids = "") - { - if (!$this->request->isPost()) { - $this->error(__("Invalid parameters")); - } - $ids = $ids ? $ids : $this->request->post("ids"); $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } - if ($ids) { - $this->model->where($pk, 'in', $ids); - } + $list = $this->model->where($pk, 'in', $ids)->select(); + $count = 0; Db::startTrans(); try { - $list = $this->model->onlyTrashed()->select(); - foreach ($list as $k => $v) { - $count += $v->delete(true); + foreach ($list as $item) { + $count += $item->delete(); } Db::commit(); } catch (PDOException|Exception $e) { @@ -239,21 +215,61 @@ trait Backend } if ($count) { $this->success(); - } else { - $this->error(__('No rows were deleted')); } - $this->error(__('Parameter %s can not be empty', 'ids')); + $this->error(__('No rows were deleted')); + } + + /** + * 真实删除 + * + * @param $ids + * @return void + */ + public function destroy($ids = null) + { + if (false === $this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $ids ?: $this->request->post('ids'); + if (empty($ids)) { + $this->error(__('Parameter %s can not be empty', 'ids')); + } + $pk = $this->model->getPk(); + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + $this->model->where($this->dataLimitField, 'in', $adminIds); + } + $this->model->where($pk, 'in', $ids); + $count = 0; + Db::startTrans(); + try { + $list = $this->model->onlyTrashed()->select(); + foreach ($list as $item) { + $count += $item->delete(true); + } + Db::commit(); + } catch (PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($count) { + $this->success(); + } + $this->error(__('No rows were deleted')); } /** * 还原 + * + * @param $ids + * @return void */ - public function restore($ids = "") + public function restore($ids = null) { - if (!$this->request->isPost()) { - $this->error(__("Invalid parameters")); + if (false === $this->request->isPost()) { + $this->error(__('Invalid parameters')); } - $ids = $ids ? $ids : $this->request->post("ids"); + $ids = $ids ?: $this->request->post('ids'); $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { @@ -266,7 +282,7 @@ trait Backend Db::startTrans(); try { $list = $this->model->onlyTrashed()->select(); - foreach ($list as $index => $item) { + foreach ($list as $item) { $count += $item->restore(); } Db::commit(); @@ -282,49 +298,56 @@ trait Backend /** * 批量更新 + * + * @param $ids + * @return void */ - public function multi($ids = "") + public function multi($ids = null) { - if (!$this->request->isPost()) { - $this->error(__("Invalid parameters")); + if (false === $this->request->isPost()) { + $this->error(__('Invalid parameters')); } - $ids = $ids ? $ids : $this->request->post("ids"); - if ($ids) { - if ($this->request->has('params')) { - parse_str($this->request->post("params"), $values); - $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields))); - if ($values) { - $adminIds = $this->getDataLimitAdminIds(); - if (is_array($adminIds)) { - $this->model->where($this->dataLimitField, 'in', $adminIds); - } - $count = 0; - Db::startTrans(); - try { - $list = $this->model->where($this->model->getPk(), 'in', $ids)->select(); - foreach ($list as $index => $item) { - $count += $item->allowField(true)->isUpdate(true)->save($values); - } - Db::commit(); - } catch (PDOException|Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($count) { - $this->success(); - } else { - $this->error(__('No rows were updated')); - } - } else { - $this->error(__('You have no permission')); - } + $ids = $ids ?: $this->request->post('ids'); + if (empty($ids)) { + $this->error(__('Parameter %s can not be empty', 'ids')); + } + + if (false === $this->request->has('params')) { + $this->error(__('No rows were updated')); + } + parse_str($this->request->post('params'), $values); + $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields))); + if (empty($values)) { + $this->error(__('You have no permission')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + $this->model->where($this->dataLimitField, 'in', $adminIds); + } + $count = 0; + Db::startTrans(); + try { + $list = $this->model->where($this->model->getPk(), 'in', $ids)->select(); + foreach ($list as $item) { + $count += $item->allowField(true)->isUpdate(true)->save($values); } + Db::commit(); + } catch (PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } - $this->error(__('Parameter %s can not be empty', 'ids')); + if ($count) { + $this->success(); + } + $this->error(__('No rows were updated')); } /** * 导入 + * + * @return void + * @throws PDOException + * @throws BindParamException */ protected function import() { @@ -344,12 +367,12 @@ trait Backend if ($ext === 'csv') { $file = fopen($filePath, 'r'); $filePath = tempnam(sys_get_temp_dir(), 'import_csv'); - $fp = fopen($filePath, "w"); + $fp = fopen($filePath, 'w'); $n = 0; while ($line = fgets($file)) { $line = rtrim($line, "\n\r\0"); $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']); - if ($encoding != 'utf-8') { + if ($encoding !== 'utf-8') { $line = mb_convert_encoding($line, 'utf-8', $encoding); } if ($n == 0 || preg_match('/^".*"$/', $line)) { From 9eeb35a79b566aea0213d1a768c39b199c010655 Mon Sep 17 00:00:00 2001 From: F4nniu Date: Sat, 7 May 2022 23:43:44 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20framework=20git=20?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bacfc9d4..fa0375cc 100755 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "repositories": [ { "type": "git", - "url": "https://gitee.com/karson/framework" + "url": "https://gitee.com/fastadminnet/framework.git" } ] } From f4795e90dadb3dc42ff6cb7ac3e003fd3a642b94 Mon Sep 17 00:00:00 2001 From: F4nniu Date: Sun, 8 May 2022 09:50:15 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E4=B8=BA=E9=80=82=E5=BA=94=E7=8E=B0?= =?UTF-8?q?=E4=BB=A3=E7=BC=96=E8=BE=91=E5=99=A8=20VSCODE=20=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/fast/Form.php | 78 ++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/extend/fast/Form.php b/extend/fast/Form.php index faf7d1db..92f343dc 100644 --- a/extend/fast/Form.php +++ b/extend/fast/Form.php @@ -8,45 +8,45 @@ use ArrayAccess; * 表单元素生成 * @class Form * @package fast - * @method string token() static 生成Token - * @method string label(string $name, string $value = null, array $options = []) static label标签 - * @method string input($type, $name, string $value = null, array $options = []) static 按类型生成文本框 - * @method string text(string $name, string $value = null, array $options = []) static 普通文本框 - * @method string password(string $name, array $options = []) static 密码文本框 - * @method string hidden(string $name, string $value = null, array $options = []) static 隐藏文本框 - * @method string email(string $name, string $value = null, array $options = []) static Email文本框 - * @method string url(string $name, string $value = null, array $options = []) static URL文本框 - * @method string file(string $name, array $options = []) static 文件上传组件 - * @method string textarea(string $name, string $value = null, array $options = []) static 多行文本框 - * @method string editor(string $name, string $value = null, array $options = []) static 富文本编辑器 - * @method string select(string $name, array $list = [], string $selected = null, array $options = []) static 下拉列表组件 - * @method string selects(string $name, array $list = [], string $selected = null, array $options = []) static 下拉列表组件(多选) - * @method string selectpicker(string $name, array $list = [], string $selected = null, array $options = []) static 下拉列表组件(友好) - * @method string selectpickers(string $name, array $list = [], string $selected = null, array $options = []) static 下拉列表组件(友好)(多选) - * @method string selectpage(string $name, string $value, string $url, string $field = null, string $primaryKey = null, array $options = []) static 动态下拉列表组件 - * @method string selectpages(string $name, string $value, string $url, string $field = null, string $primaryKey = null, array $options = []) static 动态下拉列表组件(多选) - * @method string citypicker(string $name, string $value, array $options = []) static 城市选择组件 - * @method string switcher(string $name, string $value, array $options = []) static 切换组件 - * @method string datepicker(string $name, string $value, array $options = []) static 日期选择组件 - * @method string timepicker(string $name, string $value, array $options = []) static 时间选择组件 - * @method string datetimepicker(string $name, string $value, array $options = []) static 日期时间选择组件 - * @method string daterange(string $name, string $value, array $options = []) static 日期区间组件 - * @method string timerange(string $name, string $value, array $options = []) static 时间区间组件 - * @method string datetimerange(string $name, string $value, array $options = []) static 日期时间区间组件 - * @method string fieldlist(string $name, string $value, string $title = null, string $template = null, array $options = []) static 字段列表组件 - * @method string cxselect(string $url, array $names = [], array $values = [], array $options = []) static 联动组件 - * @method string selectRange(string $name, string $begin, string $end, string $selected = null, array $options = []) static 选择数字区间 - * @method string selectYear(string $name, string $begin, string $end, string $selected = null, array $options = []) static 选择年 - * @method string selectMonth(string $name, string $selected = null, array $options = [], string $format = '%m') static 选择月 - * @method string checkbox(string $name, string $value = '1', string $checked = null, array $options = []) static 单个复选框 - * @method string checkboxs(string $name, array $list = [], string $checked = null, array $options = []) static 一组复选框 - * @method string radio(string $name, string $value = null, string $checked = null, array $options = [])) static 单个单选框 - * @method string radios(string $name, array $list = [], string $checked = null, array $options = [])) static 一组单选框 - * @method string image(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) static 上传图片组件 - * @method string images(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) static 上传图片组件(多图)) - * @method string upload(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) static 上传文件组件 - * @method string uploads(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) static 上传文件组件(多文件)) - * @method string button(string $value = null, array $options = []) static 表单button + * @method static string token() 生成Token + * @method static string label(string $name, string $value = null, array $options = []) label标签 + * @method static string input($type, $name, string $value = null, array $options = []) 按类型生成文本框 + * @method static string text(string $name, string $value = null, array $options = []) 普通文本框 + * @method static string password(string $name, array $options = []) 密码文本框 + * @method static string hidden(string $name, string $value = null, array $options = []) 隐藏文本框 + * @method static string email(string $name, string $value = null, array $options = []) Email文本框 + * @method static string url(string $name, string $value = null, array $options = []) URL文本框 + * @method static string file(string $name, array $options = []) 文件上传组件 + * @method static string textarea(string $name, string $value = null, array $options = []) 多行文本框 + * @method static string editor(string $name, string $value = null, array $options = []) 富文本编辑器 + * @method static string select(string $name, array $list = [], string $selected = null, array $options = []) 下拉列表组件 + * @method static string selects(string $name, array $list = [], string $selected = null, array $options = []) 下拉列表组件(多选) + * @method static string selectpicker(string $name, array $list = [], string $selected = null, array $options = []) 下拉列表组件(友好) + * @method static string selectpickers(string $name, array $list = [], string $selected = null, array $options = []) 下拉列表组件(友好)(多选) + * @method static string selectpage(string $name, string $value, string $url, string $field = null, string $primaryKey = null, array $options = []) 动态下拉列表组件 + * @method static string selectpages(string $name, string $value, string $url, string $field = null, string $primaryKey = null, array $options = []) 动态下拉列表组件(多选) + * @method static string citypicker(string $name, string $value, array $options = []) 城市选择组件 + * @method static string switcher(string $name, string $value, array $options = []) 切换组件 + * @method static string datepicker(string $name, string $value, array $options = []) 日期选择组件 + * @method static string timepicker(string $name, string $value, array $options = []) 时间选择组件 + * @method static string datetimepicker(string $name, string $value, array $options = []) 日期时间选择组件 + * @method static string daterange(string $name, string $value, array $options = []) 日期区间组件 + * @method static string timerange(string $name, string $value, array $options = []) 时间区间组件 + * @method static string datetimerange(string $name, string $value, array $options = []) 日期时间区间组件 + * @method static string fieldlist(string $name, string $value, string $title = null, string $template = null, array $options = []) 字段列表组件 + * @method static string cxselect(string $url, array $names = [], array $values = [], array $options = []) 联动组件 + * @method static string selectRange(string $name, string $begin, string $end, string $selected = null, array $options = []) 选择数字区间 + * @method static string selectYear(string $name, string $begin, string $end, string $selected = null, array $options = []) 选择年 + * @method static string selectMonth(string $name, string $selected = null, array $options = [], string $format = '%m') 选择月 + * @method static string checkbox(string $name, string $value = '1', string $checked = null, array $options = []) 单个复选框 + * @method static string checkboxs(string $name, array $list = [], string $checked = null, array $options = []) 一组复选框 + * @method static string radio(string $name, string $value = null, string $checked = null, array $options = [])) 单个单选框 + * @method static string radios(string $name, array $list = [], string $checked = null, array $options = [])) 一组单选框 + * @method static string image(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) 上传图片组件 + * @method static string images(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) 上传图片组件(多图)) + * @method static string upload(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) 上传文件组件 + * @method static string uploads(string $name = null, string $value, array $inputAttr = [], array $uploadAttr = [], array $chooseAttr = [], array $previewAttr = []) 上传文件组件(多文件)) + * @method static string button(string $value = null, array $options = []) 表单button */ class Form { From e59d2df64151a8cba43364d9aa733d346fe2f0a5 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 9 May 2022 09:26:04 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=B0=86=E6=8F=92=E4=BB=B6=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E8=A1=A8=E6=A0=BC=E7=9A=84=E8=AE=BE=E7=BD=AE=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=95=B0=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E7=BB=9F=E4=B8=80=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/backend/addon.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/public/assets/js/backend/addon.js b/public/assets/js/backend/addon.js index 123bffc5..d48ace3a 100644 --- a/public/assets/js/backend/addon.js +++ b/public/assets/js/backend/addon.js @@ -68,13 +68,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function }); }); - //当表格分页变更时 - table.on('page-change.bs.table', function (e, page, pagesize) { - if (!isNaN(pagesize)) { - localStorage.setItem("pagesize-addon", pagesize); - } - }); - Template.helper("Moment", Moment); Template.helper("addons", Config['addons']); @@ -90,6 +83,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, + pageSize: 50, queryParams: function (params) { var userinfo = Controller.api.userinfo.get(); $.extend(params, { @@ -181,7 +175,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function commonSearch: true, searchFormVisible: true, searchFormTemplate: 'searchformtpl', - pageSize: localStorage.getItem('pagesize-addon') || 50, }); // 为表格绑定事件 From 1898e481e0c8785521c6d4fe980230cd0c4d0f6e Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 9 May 2022 09:26:29 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E5=8E=8B=E7=BC=A9=E6=89=93=E5=8C=85=20ba?= =?UTF-8?q?ckend=E3=80=81frontend=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/require-backend.min.js | 1252 +++++++++++----------- public/assets/js/require-frontend.min.js | 776 +++++++------- public/assets/js/require-table.js | 4 +- 3 files changed, 1016 insertions(+), 1016 deletions(-) diff --git a/public/assets/js/require-backend.min.js b/public/assets/js/require-backend.min.js index 948574fa..d3b07575 100644 --- a/public/assets/js/require-backend.min.js +++ b/public/assets/js/require-backend.min.js @@ -11752,7 +11752,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr }, ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列 }, - pageSize: localStorage.getItem("pagesize") || 10, + pageSize: localStorage.getItem('page-size') || 10, pageList: [10, 15, 20, 25, 50, 'All'], pagination: true, clickToSelect: true, //是否启用点击选中 @@ -11916,12 +11916,6 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr table.on('refresh.bs.table', function (e, settings, data) { $(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin"); }); - //当表格分页变更时 - table.on('page-change.bs.table', function (e, page, pagesize) { - if (!isNaN(pagesize)) { - localStorage.setItem("pagesize", pagesize); - } - }); //当执行搜索时 table.on('search.bs.table common-search.bs.table', function (e, settings, data) { table.trigger("uncheckbox"); @@ -12266,6 +12260,12 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr Table.list[id] = table; return table; }, + // 设置全局分页的单页显示数 + pageSize: function (pageSize) { + if (!isNaN(pageSize)) { + localStorage.setItem('page-size', pageSize); + } + }, // 批量操作请求 multi: function (action, ids, table, element) { var options = table.bootstrapTable('getOptions'); @@ -12708,387 +12708,387 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr return Table; }); -// jQuery List DragSort v0.5.2 -// Website: http://dragsort.codeplex.com/ -// License: http://dragsort.codeplex.com/license - -(function($) { - - $.fn.dragsort = function(options) { - if (options == "destroy") { - $(this.selector).trigger("dragsort-uninit"); - return; - } - - var opts = $.extend({}, $.fn.dragsort.defaults, options); - var lists = []; - var list = null, lastPos = null; - - this.each(function(i, cont) { - - //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected - if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody")) - cont = $(cont).children().get(0); - - var newList = { - draggedItem: null, - placeHolderItem: null, - pos: null, - offset: null, - offsetLimit: null, - scroll: null, - container: cont, - - init: function() { - //set options to default values if not set - opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName; - if (opts.itemSelector == "") - opts.itemSelector = opts.tagName; - if (opts.dragSelector == "") - opts.dragSelector = opts.tagName; - if (opts.placeHolderTemplate == "") - opts.placeHolderTemplate = "<" + opts.tagName + "> "; - - //listidx allows reference back to correct list variable instance - $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit); - this.styleDragHandlers(true); - }, - - uninit: function() { - var list = lists[$(this).attr("data-listidx")]; - $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit"); - list.styleDragHandlers(false); - }, - - getItems: function() { - return $(this.container).children(opts.itemSelector); - }, - - styleDragHandlers: function(cursor) { - this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : ""); - }, - - grabItem: function(e) { - var list = lists[$(this).attr("data-listidx")]; - var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0); - var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0; - - //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return - if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem) - return; - - //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved, - //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude - //e.preventDefault(); - - //change cursor to move while dragging - var dragHandle = e.target; - while (!$(dragHandle).is(opts.dragSelector)) { - if (dragHandle == this) return; - dragHandle = dragHandle.parentNode; - } - $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor")); - $(dragHandle).css("cursor", "move"); - - //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work - var listElem = this; - var trigger = function() { - list.dragStart.call(listElem, e); - $(list.container).unbind("mousemove", trigger); - }; - $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); }); - }, - - dragStart: function(e) { - if (list != null && list.draggedItem != null) - list.dropItem(); - - list = lists[$(this).attr("data-listidx")]; - list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName) - - //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items - list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem)); - - //calculate mouse offset relative to draggedItem - var mt = parseInt(list.draggedItem.css("marginTop")); - var ml = parseInt(list.draggedItem.css("marginLeft")); - list.offset = list.draggedItem.offset(); - list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1; - list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1; - - //calculate box the dragged item can't be dragged outside of - if (!opts.dragBetween) { - var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight(); - list.offsetLimit = $(list.container).offset(); - list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth(); - list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight(); - } - - //create placeholder item - var h = list.draggedItem.height(); - var w = list.draggedItem.width(); - if (opts.tagName == "tr") { - list.draggedItem.children().each(function() { $(this).width($(this).width()); }); - list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true); - list.draggedItem.after(list.placeHolderItem); - //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); }); - list.placeHolderItem.children().each(function() { $(this).html(" "); }); - } else { - list.draggedItem.after(opts.placeHolderTemplate); - list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true); - } - - if (opts.tagName == "td") { - var listTable = list.draggedItem.closest("table").get(0); - $("
").appendTo("body").children().append(list.draggedItem); - } - - //style draggedItem while dragging - var orig = list.draggedItem.attr("style"); - list.draggedItem.attr("data-origstyle", orig ? orig : ""); - list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w }); - - //auto-scroll setup - list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() }; - list.scroll.scrollY = window.setInterval(function() { - if (opts.scrollContainer != window) { - $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY); - return; - } - var t = $(opts.scrollContainer).scrollTop(); - if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) { - $(opts.scrollContainer).scrollTop(t + list.scroll.moveY); - list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1); - } - }, 10); - list.scroll.scrollX = window.setInterval(function() { - if (opts.scrollContainer != window) { - $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX); - return; - } - var l = $(opts.scrollContainer).scrollLeft(); - if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) { - $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX); - list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1); - } - }, 10); - - //misc - $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); - list.setPos(e.pageX, e.pageY); - $(document).bind("mousemove", list.swapItems); - $(document).bind("mouseup", list.dropItem); - if (opts.scrollContainer != window) - $(window).bind("wheel", list.wheel); - }, - - //set position of draggedItem - setPos: function(x, y) { - //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner - var top = y - this.offset.top; - var left = x - this.offset.left; - - //limit top, left to within box draggedItem can't be dragged outside of - if (!opts.dragBetween) { - top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top)); - left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left)); - } - - //adjust top & left calculations to parent offset - var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin - if (parent != null) { - top -= parent.top; - left -= parent.left; - } - - //set x or y auto-scroll amount - if (opts.scrollContainer == window) { - y -= $(window).scrollTop(); - x -= $(window).scrollLeft(); - y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5); - x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5); - } else { - var cont = $(opts.scrollContainer); - var offset = cont.offset(); - y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top); - x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left); - } - - list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x); - list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y); - - //move draggedItem to new mouse cursor location - this.draggedItem.css({ top: top, left: left }); - }, - - //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over - wheel: function(e) { - if (list && opts.scrollContainer != window) { - var cont = $(opts.scrollContainer); - var offset = cont.offset(); - e = e.originalEvent; - if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) { - var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY; - cont.scrollTop(cont.scrollTop() + deltaY); - e.preventDefault(); - } - } - }, - - //build a table recording all the positions of the moveable list items - buildPositionTable: function() { - var pos = []; - this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) { - var loc = $(this).offset(); - loc.right = loc.left + $(this).outerWidth(); - loc.bottom = loc.top + $(this).outerHeight(); - loc.elm = this; - pos[i] = loc; - }); - this.pos = pos; - }, - - dropItem: function() { - if (list.draggedItem == null) - return; - - //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower - //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower) - var orig = list.draggedItem.attr("data-origstyle"); - list.draggedItem.attr("style", orig); - if (orig == "") - list.draggedItem.removeAttr("style"); - list.draggedItem.removeAttr("data-origstyle"); - - list.styleDragHandlers(true); - - list.placeHolderItem.before(list.draggedItem); - list.placeHolderItem.remove(); - - $("[data-droptarget], .dragSortItem").remove(); - - window.clearInterval(list.scroll.scrollY); - window.clearInterval(list.scroll.scrollX); - - //if position changed call dragEnd - if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem)) - if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order - var pos = list.draggedItem.attr("data-origpos").split('-'); - var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]); - if (nextItem.size() > 0) - nextItem.before(list.draggedItem); - else if (pos[1] == 0) //was the only item in list - $(lists[pos[0]].container).prepend(list.draggedItem); - else //was the last item in list - $(lists[pos[0]].container).append(list.draggedItem); - } - list.draggedItem.removeAttr("data-origpos"); - - list.draggedItem = null; - $(document).unbind("mousemove", list.swapItems); - $(document).unbind("mouseup", list.dropItem); - if (opts.scrollContainer != window) - $(window).unbind("wheel", list.wheel); - return false; - }, - - //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of - swapItems: function(e) { - if (list.draggedItem == null) - return false; - - //move draggedItem to mouse location - list.setPos(e.pageX, e.pageY); - - //retrieve list and item position mouse cursor is over - var ei = list.findPos(e.pageX, e.pageY); - var nlist = list; - for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) { - ei = lists[i].findPos(e.pageX, e.pageY); - nlist = lists[i]; - } - - //if not over another moveable list item return - if (ei == -1) - return false; - - //save fixed items locations - var children = function() { return $(nlist.container).children().not(nlist.draggedItem); }; - var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); }); - - //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after - if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left) - $(nlist.pos[ei].elm).before(list.placeHolderItem); - else - $(nlist.pos[ei].elm).after(list.placeHolderItem); - - //restore fixed items location - fixed.each(function() { - var elm = children().eq(this.idx).get(0); - if (this != elm && children().index(this) < this.idx) - $(this).insertAfter(elm); - else if (this != elm) - $(this).insertBefore(elm); - }); - - //misc - $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); - lastPos = list.draggedItem.offset(); - return false; - }, - - //returns the index of the list item the mouse is over - findPos: function(x, y) { - for (var i = 0; i < this.pos.length; i++) { - if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y) - return i; - } - return -1; - }, - - //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position - createDropTargets: function() { - if (!opts.dragBetween) - return; - - $(lists).each(function() { - var ph = $(this.container).find("[data-placeholder]"); - var dt = $(this.container).find("[data-droptarget]"); - if (ph.size() > 0 && dt.size() > 0) - dt.remove(); - else if (ph.size() == 0 && dt.size() == 0) { - if (opts.tagName == "td") - $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container); - else - //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8) - $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true)); - - list.placeHolderItem.attr("data-placeholder", true); - } - }); - } - }; - - newList.init(); - lists.push(newList); - }); - - return this; - }; - - $.fn.dragsort.defaults = { - tagName:"", - itemSelector: "", - dragSelector: "", - dragSelectorExclude: "input, textarea", - dragEnd: function() { }, - dragBetween: false, - placeHolderTemplate: "", - scrollContainer: window, - scrollSpeed: 5 - }; - -})(jQuery); +// jQuery List DragSort v0.5.2 +// Website: http://dragsort.codeplex.com/ +// License: http://dragsort.codeplex.com/license + +(function($) { + + $.fn.dragsort = function(options) { + if (options == "destroy") { + $(this.selector).trigger("dragsort-uninit"); + return; + } + + var opts = $.extend({}, $.fn.dragsort.defaults, options); + var lists = []; + var list = null, lastPos = null; + + this.each(function(i, cont) { + + //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected + if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody")) + cont = $(cont).children().get(0); + + var newList = { + draggedItem: null, + placeHolderItem: null, + pos: null, + offset: null, + offsetLimit: null, + scroll: null, + container: cont, + + init: function() { + //set options to default values if not set + opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName; + if (opts.itemSelector == "") + opts.itemSelector = opts.tagName; + if (opts.dragSelector == "") + opts.dragSelector = opts.tagName; + if (opts.placeHolderTemplate == "") + opts.placeHolderTemplate = "<" + opts.tagName + "> "; + + //listidx allows reference back to correct list variable instance + $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit); + this.styleDragHandlers(true); + }, + + uninit: function() { + var list = lists[$(this).attr("data-listidx")]; + $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit"); + list.styleDragHandlers(false); + }, + + getItems: function() { + return $(this.container).children(opts.itemSelector); + }, + + styleDragHandlers: function(cursor) { + this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : ""); + }, + + grabItem: function(e) { + var list = lists[$(this).attr("data-listidx")]; + var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0); + var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0; + + //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return + if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem) + return; + + //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved, + //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude + //e.preventDefault(); + + //change cursor to move while dragging + var dragHandle = e.target; + while (!$(dragHandle).is(opts.dragSelector)) { + if (dragHandle == this) return; + dragHandle = dragHandle.parentNode; + } + $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor")); + $(dragHandle).css("cursor", "move"); + + //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work + var listElem = this; + var trigger = function() { + list.dragStart.call(listElem, e); + $(list.container).unbind("mousemove", trigger); + }; + $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); }); + }, + + dragStart: function(e) { + if (list != null && list.draggedItem != null) + list.dropItem(); + + list = lists[$(this).attr("data-listidx")]; + list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName) + + //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items + list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem)); + + //calculate mouse offset relative to draggedItem + var mt = parseInt(list.draggedItem.css("marginTop")); + var ml = parseInt(list.draggedItem.css("marginLeft")); + list.offset = list.draggedItem.offset(); + list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1; + list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1; + + //calculate box the dragged item can't be dragged outside of + if (!opts.dragBetween) { + var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight(); + list.offsetLimit = $(list.container).offset(); + list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth(); + list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight(); + } + + //create placeholder item + var h = list.draggedItem.height(); + var w = list.draggedItem.width(); + if (opts.tagName == "tr") { + list.draggedItem.children().each(function() { $(this).width($(this).width()); }); + list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true); + list.draggedItem.after(list.placeHolderItem); + //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); }); + list.placeHolderItem.children().each(function() { $(this).html(" "); }); + } else { + list.draggedItem.after(opts.placeHolderTemplate); + list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true); + } + + if (opts.tagName == "td") { + var listTable = list.draggedItem.closest("table").get(0); + $("
").appendTo("body").children().append(list.draggedItem); + } + + //style draggedItem while dragging + var orig = list.draggedItem.attr("style"); + list.draggedItem.attr("data-origstyle", orig ? orig : ""); + list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w }); + + //auto-scroll setup + list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() }; + list.scroll.scrollY = window.setInterval(function() { + if (opts.scrollContainer != window) { + $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY); + return; + } + var t = $(opts.scrollContainer).scrollTop(); + if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) { + $(opts.scrollContainer).scrollTop(t + list.scroll.moveY); + list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1); + } + }, 10); + list.scroll.scrollX = window.setInterval(function() { + if (opts.scrollContainer != window) { + $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX); + return; + } + var l = $(opts.scrollContainer).scrollLeft(); + if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) { + $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX); + list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1); + } + }, 10); + + //misc + $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); + list.setPos(e.pageX, e.pageY); + $(document).bind("mousemove", list.swapItems); + $(document).bind("mouseup", list.dropItem); + if (opts.scrollContainer != window) + $(window).bind("wheel", list.wheel); + }, + + //set position of draggedItem + setPos: function(x, y) { + //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner + var top = y - this.offset.top; + var left = x - this.offset.left; + + //limit top, left to within box draggedItem can't be dragged outside of + if (!opts.dragBetween) { + top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top)); + left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left)); + } + + //adjust top & left calculations to parent offset + var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin + if (parent != null) { + top -= parent.top; + left -= parent.left; + } + + //set x or y auto-scroll amount + if (opts.scrollContainer == window) { + y -= $(window).scrollTop(); + x -= $(window).scrollLeft(); + y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5); + x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5); + } else { + var cont = $(opts.scrollContainer); + var offset = cont.offset(); + y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top); + x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left); + } + + list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x); + list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y); + + //move draggedItem to new mouse cursor location + this.draggedItem.css({ top: top, left: left }); + }, + + //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over + wheel: function(e) { + if (list && opts.scrollContainer != window) { + var cont = $(opts.scrollContainer); + var offset = cont.offset(); + e = e.originalEvent; + if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) { + var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY; + cont.scrollTop(cont.scrollTop() + deltaY); + e.preventDefault(); + } + } + }, + + //build a table recording all the positions of the moveable list items + buildPositionTable: function() { + var pos = []; + this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) { + var loc = $(this).offset(); + loc.right = loc.left + $(this).outerWidth(); + loc.bottom = loc.top + $(this).outerHeight(); + loc.elm = this; + pos[i] = loc; + }); + this.pos = pos; + }, + + dropItem: function() { + if (list.draggedItem == null) + return; + + //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower + //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower) + var orig = list.draggedItem.attr("data-origstyle"); + list.draggedItem.attr("style", orig); + if (orig == "") + list.draggedItem.removeAttr("style"); + list.draggedItem.removeAttr("data-origstyle"); + + list.styleDragHandlers(true); + + list.placeHolderItem.before(list.draggedItem); + list.placeHolderItem.remove(); + + $("[data-droptarget], .dragSortItem").remove(); + + window.clearInterval(list.scroll.scrollY); + window.clearInterval(list.scroll.scrollX); + + //if position changed call dragEnd + if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem)) + if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order + var pos = list.draggedItem.attr("data-origpos").split('-'); + var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]); + if (nextItem.size() > 0) + nextItem.before(list.draggedItem); + else if (pos[1] == 0) //was the only item in list + $(lists[pos[0]].container).prepend(list.draggedItem); + else //was the last item in list + $(lists[pos[0]].container).append(list.draggedItem); + } + list.draggedItem.removeAttr("data-origpos"); + + list.draggedItem = null; + $(document).unbind("mousemove", list.swapItems); + $(document).unbind("mouseup", list.dropItem); + if (opts.scrollContainer != window) + $(window).unbind("wheel", list.wheel); + return false; + }, + + //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of + swapItems: function(e) { + if (list.draggedItem == null) + return false; + + //move draggedItem to mouse location + list.setPos(e.pageX, e.pageY); + + //retrieve list and item position mouse cursor is over + var ei = list.findPos(e.pageX, e.pageY); + var nlist = list; + for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) { + ei = lists[i].findPos(e.pageX, e.pageY); + nlist = lists[i]; + } + + //if not over another moveable list item return + if (ei == -1) + return false; + + //save fixed items locations + var children = function() { return $(nlist.container).children().not(nlist.draggedItem); }; + var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); }); + + //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after + if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left) + $(nlist.pos[ei].elm).before(list.placeHolderItem); + else + $(nlist.pos[ei].elm).after(list.placeHolderItem); + + //restore fixed items location + fixed.each(function() { + var elm = children().eq(this.idx).get(0); + if (this != elm && children().index(this) < this.idx) + $(this).insertAfter(elm); + else if (this != elm) + $(this).insertBefore(elm); + }); + + //misc + $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); + lastPos = list.draggedItem.offset(); + return false; + }, + + //returns the index of the list item the mouse is over + findPos: function(x, y) { + for (var i = 0; i < this.pos.length; i++) { + if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y) + return i; + } + return -1; + }, + + //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position + createDropTargets: function() { + if (!opts.dragBetween) + return; + + $(lists).each(function() { + var ph = $(this.container).find("[data-placeholder]"); + var dt = $(this.container).find("[data-droptarget]"); + if (ph.size() > 0 && dt.size() > 0) + dt.remove(); + else if (ph.size() == 0 && dt.size() == 0) { + if (opts.tagName == "td") + $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container); + else + //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8) + $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true)); + + list.placeHolderItem.attr("data-placeholder", true); + } + }); + } + }; + + newList.init(); + lists.push(newList); + }); + + return this; + }; + + $.fn.dragsort.defaults = { + tagName:"", + itemSelector: "", + dragSelector: "", + dragSelectorExclude: "input, textarea", + dragEnd: function() { }, + dragBetween: false, + placeHolderTemplate: "", + scrollContainer: window, + scrollSpeed: 5 + }; + +})(jQuery); define("dragsort", function(){}); @@ -13108,244 +13108,244 @@ define("drag", function(){}); ;(function(d){d.fn.drop=function(i,e,h){var g=typeof i=="string"?i:"",f=d.isFunction(i)?i:d.isFunction(e)?e:null;if(g.indexOf("drop")!==0){g="drop"+g}h=(i==f?e:h)||{};return f?this.bind(g,h,f):this.trigger(g)};d.drop=function(e){e=e||{};b.multi=e.multi===true?Infinity:e.multi===false?1:!isNaN(e.multi)?e.multi:b.multi;b.delay=e.delay||b.delay;b.tolerance=d.isFunction(e.tolerance)?e.tolerance:e.tolerance===null?null:b.tolerance;b.mode=e.mode||b.mode||"intersect"};var c=d.event,a=c.special,b=d.event.special.drop={multi:1,delay:20,mode:"overlap",targets:[],datakey:"dropdata",noBubble:true,add:function(f){var e=d.data(this,b.datakey);e.related+=1},remove:function(){d.data(this,b.datakey).related-=1},setup:function(){if(d.data(this,b.datakey)){return}var e={related:0,active:[],anyactive:0,winner:0,location:{}};d.data(this,b.datakey,e);b.targets.push(this);return false},teardown:function(){var f=d.data(this,b.datakey)||{};if(f.related){return}d.removeData(this,b.datakey);var e=this;b.targets=d.grep(b.targets,function(g){return(g!==e)})},handler:function(g,e){var f,h;if(!e){return}switch(g.type){case"mousedown":case"touchstart":h=d(b.targets);if(typeof e.drop=="string"){h=h.filter(e.drop)}h.each(function(){var i=d.data(this,b.datakey);i.active=[];i.anyactive=0;i.winner=0});e.droppable=h;a.drag.hijack(g,"dropinit",e);break;case"mousemove":case"touchmove":b.event=g;if(!b.timer){b.tolerate(e)}break;case"mouseup":case"touchend":b.timer=clearTimeout(b.timer);if(e.propagates){a.drag.hijack(g,"drop",e);a.drag.hijack(g,"dropend",e)}break}},locate:function(k,h){var l=d.data(k,b.datakey),g=d(k),i=g.offset()||{},e=g.outerHeight(),j=g.outerWidth(),f={elem:k,width:j,height:e,top:i.top,left:i.left,right:i.left+j,bottom:i.top+e};if(l){l.location=f;l.index=h;l.elem=k}return f},contains:function(e,f){return((f[0]||f.left)>=e.left&&(f[0]||f.right)<=e.right&&(f[1]||f.top)>=e.top&&(f[1]||f.bottom)<=e.bottom)},modes:{intersect:function(f,e,g){return this.contains(g,[f.pageX,f.pageY])?1000000000:this.modes.overlap.apply(this,arguments)},overlap:function(f,e,g){return Math.max(0,Math.min(g.bottom,e.bottom)-Math.max(g.top,e.top))*Math.max(0,Math.min(g.right,e.right)-Math.max(g.left,e.left))},fit:function(f,e,g){return this.contains(g,e)?1:0},middle:function(f,e,g){return this.contains(g,[e.left+e.width*0.5,e.top+e.height*0.5])?1:0}},sort:function(f,e){return(e.winner-f.winner)||(f.index-e.index)},tolerate:function(q){var k,e,n,j,l,m,g,p=0,f,h=q.interactions.length,r=[b.event.pageX,b.event.pageY],o=b.tolerance||b.modes[b.mode];do{if(f=q.interactions[p]){if(!f){return}f.drop=[];l=[];m=f.droppable.length;if(o){n=b.locate(f.proxy)}k=0;do{if(g=f.droppable[k]){j=d.data(g,b.datakey);e=j.location;if(!e){continue}j.winner=o?o.call(b,b.event,n,e):b.contains(e,r)?1:0;l.push(j)}}while(++k -1 ? "&" : "?") + "ref=addtabs") : url; - try { - window.history.pushState(state, title, pushurl); - } catch (e) { - - } - } - $(this).data("pushstate", null); - _add.call(this, { - id: id, - title: $(this).attr('title') ? $(this).attr('title') : $(this).html(), - content: content, - url: url, - ajax: ajax - }); - } - }); - - navobj.on('click', '.close-tab', function () { - var id = $(this).prev("a").attr("aria-controls"); - _close(id); - return false; - }); - navobj.on('dblclick', 'li[role=presentation]', function () { - $(this).find(".close-tab").trigger("click"); - }); - navobj.on('click', 'li[role=presentation]', function () { - $("a[addtabs=" + $("a", this).attr("node-id") + "]").trigger("click"); - }); - - $(window).resize(function () { - if (typeof options.nav === 'object') { - var siblingsWidth = 0; - navobj.siblings().each(function () { - siblingsWidth += $(this).outerWidth(); - }); - navobj.width(navobj.parent().width() - siblingsWidth); - } else { - $("#nav").width($("#header").find("> .navbar").width() - $(".sidebar-toggle").outerWidth() - $(".navbar-custom-menu").outerWidth() - 20); - } - _drop(); - }); - - var _add = function (opts) { - var id, tabid, conid, url; - id = opts.id; - tabid = 'tab_' + opts.id; - conid = 'con_' + opts.id; - url = opts.url; - url += (opts.url.indexOf("?") > -1 ? "&addtabs=1" : "?addtabs=1"); - - var tabitem = $('#' + tabid, navobj); - var conitem = $('#' + conid, tabobj); - - navobj.find("[role='presentation']").removeClass('active'); - tabobj.find("[role='tabpanel']").removeClass('active'); - - //如果TAB不存在,创建一个新的TAB - if (tabitem.size() === 0) { - //创建新TAB的title - tabitem = $(''); - //是否允许关闭 - if (options.close && $("li", navobj).size() > 0) { - tabitem.append(' '); - } - if (conitem.size() === 0) { - //创建新TAB的内容 - conitem = $('
'); - //是否指定TAB内容 - if (opts.content) { - conitem.append(opts.content); - } else if (options.iframeUse && !opts.ajax) {//没有内容,使用IFRAME打开链接 - var height = options.iframeHeight; - conitem.append('
'); - } else { - $.get(url, function (data) { - conitem.append(data); - }); - } - tabobj.append(conitem); - } - //加入TABS - if ($('.tabdrop li', navobj).size() > 0) { - $('.tabdrop ul', navobj).append(tabitem); - } else { - navobj.append(tabitem); - } - } else { - //强制刷新iframe - if (options.iframeForceRefresh) { - $("#" + conid + " iframe").attr('src', function (i, val) { - return val; - }); - } else if (options.iframeForceRefreshTable) { - try { - //检测iframe中是否存在刷新按钮 - if ($("#" + conid + " iframe").contents().find(".btn-refresh:not([data-force-refresh=false])").size() > 0) { - $("#" + conid + " iframe")[0].contentWindow.$(".btn-refresh:not([data-force-refresh=false])").trigger("click"); - } - } catch (e) { - - } - } - } - localStorage.setItem("addtabs", $(this).prop('outerHTML')); - //激活TAB - tabitem.addClass('active'); - conitem.addClass("active"); - _drop(); - }; - - var _close = function (id) { - var tabid = 'tab_' + id; - var conid = 'con_' + id; - var tabitem = $('#' + tabid, navobj); - var conitem = $('#' + conid, tabobj); - //如果关闭的是当前激活的TAB,激活他的前一个TAB - if (obj.find("li.active").not('.tabdrop').attr('id') === tabid) { - var prev = tabitem.prev().not(".tabdrop"); - var next = tabitem.next().not(".tabdrop"); - if (prev.size() > 0) { - prev.find('a').trigger("click"); - } else if (next.size() > 0) { - next.find('a').trigger("click"); - } else { - $(">li:not(.tabdrop):last > a", navobj).trigger('click'); - } - } - //关闭TAB - tabitem.remove(); - conitem.remove(); - _drop(); - options.callback(); - }; - - var _drop = function () { - navobj.refreshAddtabs(); - }; - }; - //刷新Addtabs - $.fn.refreshAddtabs = function () { - var navobj = $(this); - var dropdown = $(".tabdrop", navobj); - if (dropdown.size() === 0) { - dropdown = $(''); - dropdown.prependTo(navobj); - } - - //检测是否有下拉样式 - if (navobj.parent().is('.tabs-below')) { - dropdown.addClass('dropup'); - } - - var collection = 0; - var maxwidth = navobj.width() - 65; - - var liwidth = 0; - //检查超过一行的标签页 - var litabs = navobj.append(dropdown.find('li')).find('>li').not('.tabdrop'); - var totalwidth = 0; - litabs.each(function () { - totalwidth += $(this).outerWidth(true); - }); - if (navobj.width() < totalwidth) { - litabs.each(function () { - liwidth += $(this).outerWidth(true); - if (liwidth > maxwidth) { - dropdown.find('ul').append($(this)); - collection++; - } - }); - if (collection > 0) { - dropdown.removeClass('hide'); - if (dropdown.find('.active').length === 1) { - dropdown.addClass('active'); - } else { - dropdown.removeClass('active'); - } - } - } else { - dropdown.addClass('hide'); - } - - }; -})(jQuery); +/** + * http://git.oschina.net/hbbcs/bootStrap-addTabs + * Created by joe on 2015-12-19. + * Modified by Karson + */ + +(function ($) { + + $.fn.addtabs = function (options) { + var obj = $(this); + options = $.extend({ + content: '', //直接指定所有页面TABS内容 + close: true, //是否可以关闭 + monitor: 'body', //监视的区域 + nav: '.nav-addtabs', + tab: '.tab-addtabs', + iframeUse: true, //使用iframe还是ajax + iframeHeight: $(window).height() - 50, //固定TAB中IFRAME高度,根据需要自己修改 + iframeForceRefresh: false, //点击后强制加载对应的iframe + iframeForceRefreshTable: false, //点击后强制刷新对应的iframe中的table + callback: function () { + //关闭后回调函数 + } + }, options || {}); + var navobj = $(options.nav); + var tabobj = $(options.tab); + if (history.pushState) { + //浏览器前进后退事件 + $(window).on("popstate", function (e) { + var state = e.originalEvent.state; + if (state) { + $("a[addtabs=" + state.id + "]", options.monitor).data("pushstate", true).trigger("click"); + } + }); + } + $(options.monitor).on('click', '[addtabs]', function (e) { + if ($(this).attr('url').indexOf("javascript:") !== 0) { + if ($(this).is("a")) { + e.preventDefault(); + } + var id = $(this).attr('addtabs'); + var title = $(this).attr('title') ? $(this).attr('title') : $.trim($(this).text()); + var url = $(this).attr('url'); + var content = options.content ? options.content : $(this).attr('content'); + var ajax = $(this).attr('ajax') === '1' || $(this).attr('ajax') === 'true'; + var state = ({ + url: url, title: title, id: id, content: content, ajax: ajax + }); + + document.title = title; + if (history.pushState && !$(this).data("pushstate")) { + var pushurl = url.indexOf("ref=addtabs") === -1 ? (url + (url.indexOf("?") > -1 ? "&" : "?") + "ref=addtabs") : url; + try { + window.history.pushState(state, title, pushurl); + } catch (e) { + + } + } + $(this).data("pushstate", null); + _add.call(this, { + id: id, + title: $(this).attr('title') ? $(this).attr('title') : $(this).html(), + content: content, + url: url, + ajax: ajax + }); + } + }); + + navobj.on('click', '.close-tab', function () { + var id = $(this).prev("a").attr("aria-controls"); + _close(id); + return false; + }); + navobj.on('dblclick', 'li[role=presentation]', function () { + $(this).find(".close-tab").trigger("click"); + }); + navobj.on('click', 'li[role=presentation]', function () { + $("a[addtabs=" + $("a", this).attr("node-id") + "]").trigger("click"); + }); + + $(window).resize(function () { + if (typeof options.nav === 'object') { + var siblingsWidth = 0; + navobj.siblings().each(function () { + siblingsWidth += $(this).outerWidth(); + }); + navobj.width(navobj.parent().width() - siblingsWidth); + } else { + $("#nav").width($("#header").find("> .navbar").width() - $(".sidebar-toggle").outerWidth() - $(".navbar-custom-menu").outerWidth() - 20); + } + _drop(); + }); + + var _add = function (opts) { + var id, tabid, conid, url; + id = opts.id; + tabid = 'tab_' + opts.id; + conid = 'con_' + opts.id; + url = opts.url; + url += (opts.url.indexOf("?") > -1 ? "&addtabs=1" : "?addtabs=1"); + + var tabitem = $('#' + tabid, navobj); + var conitem = $('#' + conid, tabobj); + + navobj.find("[role='presentation']").removeClass('active'); + tabobj.find("[role='tabpanel']").removeClass('active'); + + //如果TAB不存在,创建一个新的TAB + if (tabitem.size() === 0) { + //创建新TAB的title + tabitem = $(''); + //是否允许关闭 + if (options.close && $("li", navobj).size() > 0) { + tabitem.append(' '); + } + if (conitem.size() === 0) { + //创建新TAB的内容 + conitem = $('
'); + //是否指定TAB内容 + if (opts.content) { + conitem.append(opts.content); + } else if (options.iframeUse && !opts.ajax) {//没有内容,使用IFRAME打开链接 + var height = options.iframeHeight; + conitem.append('
'); + } else { + $.get(url, function (data) { + conitem.append(data); + }); + } + tabobj.append(conitem); + } + //加入TABS + if ($('.tabdrop li', navobj).size() > 0) { + $('.tabdrop ul', navobj).append(tabitem); + } else { + navobj.append(tabitem); + } + } else { + //强制刷新iframe + if (options.iframeForceRefresh) { + $("#" + conid + " iframe").attr('src', function (i, val) { + return val; + }); + } else if (options.iframeForceRefreshTable) { + try { + //检测iframe中是否存在刷新按钮 + if ($("#" + conid + " iframe").contents().find(".btn-refresh:not([data-force-refresh=false])").size() > 0) { + $("#" + conid + " iframe")[0].contentWindow.$(".btn-refresh:not([data-force-refresh=false])").trigger("click"); + } + } catch (e) { + + } + } + } + localStorage.setItem("addtabs", $(this).prop('outerHTML')); + //激活TAB + tabitem.addClass('active'); + conitem.addClass("active"); + _drop(); + }; + + var _close = function (id) { + var tabid = 'tab_' + id; + var conid = 'con_' + id; + var tabitem = $('#' + tabid, navobj); + var conitem = $('#' + conid, tabobj); + //如果关闭的是当前激活的TAB,激活他的前一个TAB + if (obj.find("li.active").not('.tabdrop').attr('id') === tabid) { + var prev = tabitem.prev().not(".tabdrop"); + var next = tabitem.next().not(".tabdrop"); + if (prev.size() > 0) { + prev.find('a').trigger("click"); + } else if (next.size() > 0) { + next.find('a').trigger("click"); + } else { + $(">li:not(.tabdrop):last > a", navobj).trigger('click'); + } + } + //关闭TAB + tabitem.remove(); + conitem.remove(); + _drop(); + options.callback(); + }; + + var _drop = function () { + navobj.refreshAddtabs(); + }; + }; + //刷新Addtabs + $.fn.refreshAddtabs = function () { + var navobj = $(this); + var dropdown = $(".tabdrop", navobj); + if (dropdown.size() === 0) { + dropdown = $(''); + dropdown.prependTo(navobj); + } + + //检测是否有下拉样式 + if (navobj.parent().is('.tabs-below')) { + dropdown.addClass('dropup'); + } + + var collection = 0; + var maxwidth = navobj.width() - 65; + + var liwidth = 0; + //检查超过一行的标签页 + var litabs = navobj.append(dropdown.find('li')).find('>li').not('.tabdrop'); + var totalwidth = 0; + litabs.each(function () { + totalwidth += $(this).outerWidth(true); + }); + if (navobj.width() < totalwidth) { + litabs.each(function () { + liwidth += $(this).outerWidth(true); + if (liwidth > maxwidth) { + dropdown.find('ul').append($(this)); + collection++; + } + }); + if (collection > 0) { + dropdown.removeClass('hide'); + if (dropdown.find('.active').length === 1) { + dropdown.addClass('active'); + } else { + dropdown.removeClass('active'); + } + } + } else { + dropdown.addClass('hide'); + } + + }; +})(jQuery); define("addtabs", function(){}); diff --git a/public/assets/js/require-frontend.min.js b/public/assets/js/require-frontend.min.js index bc801724..8c5c2181 100644 --- a/public/assets/js/require-frontend.min.js +++ b/public/assets/js/require-frontend.min.js @@ -11601,7 +11601,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr }, ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列 }, - pageSize: localStorage.getItem("pagesize") || 10, + pageSize: localStorage.getItem('page-size') || 10, pageList: [10, 15, 20, 25, 50, 'All'], pagination: true, clickToSelect: true, //是否启用点击选中 @@ -11765,12 +11765,6 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr table.on('refresh.bs.table', function (e, settings, data) { $(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin"); }); - //当表格分页变更时 - table.on('page-change.bs.table', function (e, page, pagesize) { - if (!isNaN(pagesize)) { - localStorage.setItem("pagesize", pagesize); - } - }); //当执行搜索时 table.on('search.bs.table common-search.bs.table', function (e, settings, data) { table.trigger("uncheckbox"); @@ -12115,6 +12109,12 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr Table.list[id] = table; return table; }, + // 设置全局分页的单页显示数 + pageSize: function (pageSize) { + if (!isNaN(pageSize)) { + localStorage.setItem('page-size', pageSize); + } + }, // 批量操作请求 multi: function (action, ids, table, element) { var options = table.bootstrapTable('getOptions'); @@ -12557,387 +12557,387 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr return Table; }); -// jQuery List DragSort v0.5.2 -// Website: http://dragsort.codeplex.com/ -// License: http://dragsort.codeplex.com/license - -(function($) { - - $.fn.dragsort = function(options) { - if (options == "destroy") { - $(this.selector).trigger("dragsort-uninit"); - return; - } - - var opts = $.extend({}, $.fn.dragsort.defaults, options); - var lists = []; - var list = null, lastPos = null; - - this.each(function(i, cont) { - - //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected - if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody")) - cont = $(cont).children().get(0); - - var newList = { - draggedItem: null, - placeHolderItem: null, - pos: null, - offset: null, - offsetLimit: null, - scroll: null, - container: cont, - - init: function() { - //set options to default values if not set - opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName; - if (opts.itemSelector == "") - opts.itemSelector = opts.tagName; - if (opts.dragSelector == "") - opts.dragSelector = opts.tagName; - if (opts.placeHolderTemplate == "") - opts.placeHolderTemplate = "<" + opts.tagName + "> "; - - //listidx allows reference back to correct list variable instance - $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit); - this.styleDragHandlers(true); - }, - - uninit: function() { - var list = lists[$(this).attr("data-listidx")]; - $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit"); - list.styleDragHandlers(false); - }, - - getItems: function() { - return $(this.container).children(opts.itemSelector); - }, - - styleDragHandlers: function(cursor) { - this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : ""); - }, - - grabItem: function(e) { - var list = lists[$(this).attr("data-listidx")]; - var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0); - var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0; - - //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return - if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem) - return; - - //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved, - //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude - //e.preventDefault(); - - //change cursor to move while dragging - var dragHandle = e.target; - while (!$(dragHandle).is(opts.dragSelector)) { - if (dragHandle == this) return; - dragHandle = dragHandle.parentNode; - } - $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor")); - $(dragHandle).css("cursor", "move"); - - //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work - var listElem = this; - var trigger = function() { - list.dragStart.call(listElem, e); - $(list.container).unbind("mousemove", trigger); - }; - $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); }); - }, - - dragStart: function(e) { - if (list != null && list.draggedItem != null) - list.dropItem(); - - list = lists[$(this).attr("data-listidx")]; - list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName) - - //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items - list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem)); - - //calculate mouse offset relative to draggedItem - var mt = parseInt(list.draggedItem.css("marginTop")); - var ml = parseInt(list.draggedItem.css("marginLeft")); - list.offset = list.draggedItem.offset(); - list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1; - list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1; - - //calculate box the dragged item can't be dragged outside of - if (!opts.dragBetween) { - var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight(); - list.offsetLimit = $(list.container).offset(); - list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth(); - list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight(); - } - - //create placeholder item - var h = list.draggedItem.height(); - var w = list.draggedItem.width(); - if (opts.tagName == "tr") { - list.draggedItem.children().each(function() { $(this).width($(this).width()); }); - list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true); - list.draggedItem.after(list.placeHolderItem); - //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); }); - list.placeHolderItem.children().each(function() { $(this).html(" "); }); - } else { - list.draggedItem.after(opts.placeHolderTemplate); - list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true); - } - - if (opts.tagName == "td") { - var listTable = list.draggedItem.closest("table").get(0); - $("
").appendTo("body").children().append(list.draggedItem); - } - - //style draggedItem while dragging - var orig = list.draggedItem.attr("style"); - list.draggedItem.attr("data-origstyle", orig ? orig : ""); - list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w }); - - //auto-scroll setup - list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() }; - list.scroll.scrollY = window.setInterval(function() { - if (opts.scrollContainer != window) { - $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY); - return; - } - var t = $(opts.scrollContainer).scrollTop(); - if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) { - $(opts.scrollContainer).scrollTop(t + list.scroll.moveY); - list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1); - } - }, 10); - list.scroll.scrollX = window.setInterval(function() { - if (opts.scrollContainer != window) { - $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX); - return; - } - var l = $(opts.scrollContainer).scrollLeft(); - if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) { - $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX); - list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1); - } - }, 10); - - //misc - $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); - list.setPos(e.pageX, e.pageY); - $(document).bind("mousemove", list.swapItems); - $(document).bind("mouseup", list.dropItem); - if (opts.scrollContainer != window) - $(window).bind("wheel", list.wheel); - }, - - //set position of draggedItem - setPos: function(x, y) { - //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner - var top = y - this.offset.top; - var left = x - this.offset.left; - - //limit top, left to within box draggedItem can't be dragged outside of - if (!opts.dragBetween) { - top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top)); - left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left)); - } - - //adjust top & left calculations to parent offset - var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin - if (parent != null) { - top -= parent.top; - left -= parent.left; - } - - //set x or y auto-scroll amount - if (opts.scrollContainer == window) { - y -= $(window).scrollTop(); - x -= $(window).scrollLeft(); - y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5); - x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5); - } else { - var cont = $(opts.scrollContainer); - var offset = cont.offset(); - y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top); - x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left); - } - - list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x); - list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y); - - //move draggedItem to new mouse cursor location - this.draggedItem.css({ top: top, left: left }); - }, - - //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over - wheel: function(e) { - if (list && opts.scrollContainer != window) { - var cont = $(opts.scrollContainer); - var offset = cont.offset(); - e = e.originalEvent; - if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) { - var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY; - cont.scrollTop(cont.scrollTop() + deltaY); - e.preventDefault(); - } - } - }, - - //build a table recording all the positions of the moveable list items - buildPositionTable: function() { - var pos = []; - this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) { - var loc = $(this).offset(); - loc.right = loc.left + $(this).outerWidth(); - loc.bottom = loc.top + $(this).outerHeight(); - loc.elm = this; - pos[i] = loc; - }); - this.pos = pos; - }, - - dropItem: function() { - if (list.draggedItem == null) - return; - - //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower - //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower) - var orig = list.draggedItem.attr("data-origstyle"); - list.draggedItem.attr("style", orig); - if (orig == "") - list.draggedItem.removeAttr("style"); - list.draggedItem.removeAttr("data-origstyle"); - - list.styleDragHandlers(true); - - list.placeHolderItem.before(list.draggedItem); - list.placeHolderItem.remove(); - - $("[data-droptarget], .dragSortItem").remove(); - - window.clearInterval(list.scroll.scrollY); - window.clearInterval(list.scroll.scrollX); - - //if position changed call dragEnd - if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem)) - if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order - var pos = list.draggedItem.attr("data-origpos").split('-'); - var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]); - if (nextItem.size() > 0) - nextItem.before(list.draggedItem); - else if (pos[1] == 0) //was the only item in list - $(lists[pos[0]].container).prepend(list.draggedItem); - else //was the last item in list - $(lists[pos[0]].container).append(list.draggedItem); - } - list.draggedItem.removeAttr("data-origpos"); - - list.draggedItem = null; - $(document).unbind("mousemove", list.swapItems); - $(document).unbind("mouseup", list.dropItem); - if (opts.scrollContainer != window) - $(window).unbind("wheel", list.wheel); - return false; - }, - - //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of - swapItems: function(e) { - if (list.draggedItem == null) - return false; - - //move draggedItem to mouse location - list.setPos(e.pageX, e.pageY); - - //retrieve list and item position mouse cursor is over - var ei = list.findPos(e.pageX, e.pageY); - var nlist = list; - for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) { - ei = lists[i].findPos(e.pageX, e.pageY); - nlist = lists[i]; - } - - //if not over another moveable list item return - if (ei == -1) - return false; - - //save fixed items locations - var children = function() { return $(nlist.container).children().not(nlist.draggedItem); }; - var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); }); - - //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after - if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left) - $(nlist.pos[ei].elm).before(list.placeHolderItem); - else - $(nlist.pos[ei].elm).after(list.placeHolderItem); - - //restore fixed items location - fixed.each(function() { - var elm = children().eq(this.idx).get(0); - if (this != elm && children().index(this) < this.idx) - $(this).insertAfter(elm); - else if (this != elm) - $(this).insertBefore(elm); - }); - - //misc - $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); - lastPos = list.draggedItem.offset(); - return false; - }, - - //returns the index of the list item the mouse is over - findPos: function(x, y) { - for (var i = 0; i < this.pos.length; i++) { - if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y) - return i; - } - return -1; - }, - - //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position - createDropTargets: function() { - if (!opts.dragBetween) - return; - - $(lists).each(function() { - var ph = $(this.container).find("[data-placeholder]"); - var dt = $(this.container).find("[data-droptarget]"); - if (ph.size() > 0 && dt.size() > 0) - dt.remove(); - else if (ph.size() == 0 && dt.size() == 0) { - if (opts.tagName == "td") - $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container); - else - //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8) - $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true)); - - list.placeHolderItem.attr("data-placeholder", true); - } - }); - } - }; - - newList.init(); - lists.push(newList); - }); - - return this; - }; - - $.fn.dragsort.defaults = { - tagName:"", - itemSelector: "", - dragSelector: "", - dragSelectorExclude: "input, textarea", - dragEnd: function() { }, - dragBetween: false, - placeHolderTemplate: "", - scrollContainer: window, - scrollSpeed: 5 - }; - -})(jQuery); +// jQuery List DragSort v0.5.2 +// Website: http://dragsort.codeplex.com/ +// License: http://dragsort.codeplex.com/license + +(function($) { + + $.fn.dragsort = function(options) { + if (options == "destroy") { + $(this.selector).trigger("dragsort-uninit"); + return; + } + + var opts = $.extend({}, $.fn.dragsort.defaults, options); + var lists = []; + var list = null, lastPos = null; + + this.each(function(i, cont) { + + //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected + if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody")) + cont = $(cont).children().get(0); + + var newList = { + draggedItem: null, + placeHolderItem: null, + pos: null, + offset: null, + offsetLimit: null, + scroll: null, + container: cont, + + init: function() { + //set options to default values if not set + opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName; + if (opts.itemSelector == "") + opts.itemSelector = opts.tagName; + if (opts.dragSelector == "") + opts.dragSelector = opts.tagName; + if (opts.placeHolderTemplate == "") + opts.placeHolderTemplate = "<" + opts.tagName + "> "; + + //listidx allows reference back to correct list variable instance + $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit); + this.styleDragHandlers(true); + }, + + uninit: function() { + var list = lists[$(this).attr("data-listidx")]; + $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit"); + list.styleDragHandlers(false); + }, + + getItems: function() { + return $(this.container).children(opts.itemSelector); + }, + + styleDragHandlers: function(cursor) { + this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : ""); + }, + + grabItem: function(e) { + var list = lists[$(this).attr("data-listidx")]; + var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0); + var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0; + + //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return + if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem) + return; + + //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved, + //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude + //e.preventDefault(); + + //change cursor to move while dragging + var dragHandle = e.target; + while (!$(dragHandle).is(opts.dragSelector)) { + if (dragHandle == this) return; + dragHandle = dragHandle.parentNode; + } + $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor")); + $(dragHandle).css("cursor", "move"); + + //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work + var listElem = this; + var trigger = function() { + list.dragStart.call(listElem, e); + $(list.container).unbind("mousemove", trigger); + }; + $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); }); + }, + + dragStart: function(e) { + if (list != null && list.draggedItem != null) + list.dropItem(); + + list = lists[$(this).attr("data-listidx")]; + list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName) + + //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items + list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem)); + + //calculate mouse offset relative to draggedItem + var mt = parseInt(list.draggedItem.css("marginTop")); + var ml = parseInt(list.draggedItem.css("marginLeft")); + list.offset = list.draggedItem.offset(); + list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1; + list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1; + + //calculate box the dragged item can't be dragged outside of + if (!opts.dragBetween) { + var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight(); + list.offsetLimit = $(list.container).offset(); + list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth(); + list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight(); + } + + //create placeholder item + var h = list.draggedItem.height(); + var w = list.draggedItem.width(); + if (opts.tagName == "tr") { + list.draggedItem.children().each(function() { $(this).width($(this).width()); }); + list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true); + list.draggedItem.after(list.placeHolderItem); + //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); }); + list.placeHolderItem.children().each(function() { $(this).html(" "); }); + } else { + list.draggedItem.after(opts.placeHolderTemplate); + list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true); + } + + if (opts.tagName == "td") { + var listTable = list.draggedItem.closest("table").get(0); + $("
").appendTo("body").children().append(list.draggedItem); + } + + //style draggedItem while dragging + var orig = list.draggedItem.attr("style"); + list.draggedItem.attr("data-origstyle", orig ? orig : ""); + list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w }); + + //auto-scroll setup + list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() }; + list.scroll.scrollY = window.setInterval(function() { + if (opts.scrollContainer != window) { + $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY); + return; + } + var t = $(opts.scrollContainer).scrollTop(); + if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) { + $(opts.scrollContainer).scrollTop(t + list.scroll.moveY); + list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1); + } + }, 10); + list.scroll.scrollX = window.setInterval(function() { + if (opts.scrollContainer != window) { + $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX); + return; + } + var l = $(opts.scrollContainer).scrollLeft(); + if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) { + $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX); + list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1); + } + }, 10); + + //misc + $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); + list.setPos(e.pageX, e.pageY); + $(document).bind("mousemove", list.swapItems); + $(document).bind("mouseup", list.dropItem); + if (opts.scrollContainer != window) + $(window).bind("wheel", list.wheel); + }, + + //set position of draggedItem + setPos: function(x, y) { + //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner + var top = y - this.offset.top; + var left = x - this.offset.left; + + //limit top, left to within box draggedItem can't be dragged outside of + if (!opts.dragBetween) { + top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top)); + left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left)); + } + + //adjust top & left calculations to parent offset + var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin + if (parent != null) { + top -= parent.top; + left -= parent.left; + } + + //set x or y auto-scroll amount + if (opts.scrollContainer == window) { + y -= $(window).scrollTop(); + x -= $(window).scrollLeft(); + y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5); + x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5); + } else { + var cont = $(opts.scrollContainer); + var offset = cont.offset(); + y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top); + x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left); + } + + list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x); + list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y); + + //move draggedItem to new mouse cursor location + this.draggedItem.css({ top: top, left: left }); + }, + + //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over + wheel: function(e) { + if (list && opts.scrollContainer != window) { + var cont = $(opts.scrollContainer); + var offset = cont.offset(); + e = e.originalEvent; + if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) { + var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY; + cont.scrollTop(cont.scrollTop() + deltaY); + e.preventDefault(); + } + } + }, + + //build a table recording all the positions of the moveable list items + buildPositionTable: function() { + var pos = []; + this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) { + var loc = $(this).offset(); + loc.right = loc.left + $(this).outerWidth(); + loc.bottom = loc.top + $(this).outerHeight(); + loc.elm = this; + pos[i] = loc; + }); + this.pos = pos; + }, + + dropItem: function() { + if (list.draggedItem == null) + return; + + //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower + //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower) + var orig = list.draggedItem.attr("data-origstyle"); + list.draggedItem.attr("style", orig); + if (orig == "") + list.draggedItem.removeAttr("style"); + list.draggedItem.removeAttr("data-origstyle"); + + list.styleDragHandlers(true); + + list.placeHolderItem.before(list.draggedItem); + list.placeHolderItem.remove(); + + $("[data-droptarget], .dragSortItem").remove(); + + window.clearInterval(list.scroll.scrollY); + window.clearInterval(list.scroll.scrollX); + + //if position changed call dragEnd + if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem)) + if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order + var pos = list.draggedItem.attr("data-origpos").split('-'); + var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]); + if (nextItem.size() > 0) + nextItem.before(list.draggedItem); + else if (pos[1] == 0) //was the only item in list + $(lists[pos[0]].container).prepend(list.draggedItem); + else //was the last item in list + $(lists[pos[0]].container).append(list.draggedItem); + } + list.draggedItem.removeAttr("data-origpos"); + + list.draggedItem = null; + $(document).unbind("mousemove", list.swapItems); + $(document).unbind("mouseup", list.dropItem); + if (opts.scrollContainer != window) + $(window).unbind("wheel", list.wheel); + return false; + }, + + //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of + swapItems: function(e) { + if (list.draggedItem == null) + return false; + + //move draggedItem to mouse location + list.setPos(e.pageX, e.pageY); + + //retrieve list and item position mouse cursor is over + var ei = list.findPos(e.pageX, e.pageY); + var nlist = list; + for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) { + ei = lists[i].findPos(e.pageX, e.pageY); + nlist = lists[i]; + } + + //if not over another moveable list item return + if (ei == -1) + return false; + + //save fixed items locations + var children = function() { return $(nlist.container).children().not(nlist.draggedItem); }; + var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); }); + + //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after + if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left) + $(nlist.pos[ei].elm).before(list.placeHolderItem); + else + $(nlist.pos[ei].elm).after(list.placeHolderItem); + + //restore fixed items location + fixed.each(function() { + var elm = children().eq(this.idx).get(0); + if (this != elm && children().index(this) < this.idx) + $(this).insertAfter(elm); + else if (this != elm) + $(this).insertBefore(elm); + }); + + //misc + $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); }); + lastPos = list.draggedItem.offset(); + return false; + }, + + //returns the index of the list item the mouse is over + findPos: function(x, y) { + for (var i = 0; i < this.pos.length; i++) { + if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y) + return i; + } + return -1; + }, + + //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position + createDropTargets: function() { + if (!opts.dragBetween) + return; + + $(lists).each(function() { + var ph = $(this.container).find("[data-placeholder]"); + var dt = $(this.container).find("[data-droptarget]"); + if (ph.size() > 0 && dt.size() > 0) + dt.remove(); + else if (ph.size() == 0 && dt.size() == 0) { + if (opts.tagName == "td") + $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container); + else + //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8) + $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true)); + + list.placeHolderItem.attr("data-placeholder", true); + } + }); + } + }; + + newList.init(); + lists.push(newList); + }); + + return this; + }; + + $.fn.dragsort.defaults = { + tagName:"", + itemSelector: "", + dragSelector: "", + dragSelectorExclude: "input, textarea", + dragEnd: function() { }, + dragBetween: false, + placeHolderTemplate: "", + scrollContainer: window, + scrollSpeed: 5 + }; + +})(jQuery); define("dragsort", function(){}); diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index ef6d7b3e..7a665a83 100644 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -26,7 +26,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table }, ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列 }, - pageSize: localStorage.getItem("pagesize") || 10, + pageSize: localStorage.getItem('page-size') || 10, pageList: [10, 15, 20, 25, 50, 'All'], pagination: true, clickToSelect: true, //是否启用点击选中 @@ -537,7 +537,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table // 设置全局分页的单页显示数 pageSize: function (pageSize) { if (!isNaN(pageSize)) { - localStorage.setItem('pagesize', pageSize); + localStorage.setItem('page-size', pageSize); } }, // 批量操作请求