From 27ed67331ed2b8aec56e08299e18a6a4f1adc6ea Mon Sep 17 00:00:00 2001 From: Catouse Date: Wed, 13 Apr 2016 17:42:21 +0800 Subject: [PATCH] * improve dashboard UI. --- module/block/control.php | 75 ++++++++++++----------- module/block/css/dashboard.css | 80 +++++++++++++++++++++++-- module/block/js/admin.js | 8 ++- module/block/js/dashboard.js | 31 ++++------ module/block/model.php | 17 +++--- module/block/view/admin.html.php | 6 +- module/block/view/dashboard.html.php | 17 +++--- module/block/view/productblock.html.php | 4 +- module/block/view/projectblock.html.php | 2 +- module/block/view/publicform.html.php | 2 +- module/block/view/set.html.php | 2 +- module/block/view/setmodule.html.php | 3 +- module/my/view/blockprojects.html.php | 2 +- module/my/view/index.html.php | 64 +------------------- module/project/view/index.html.php | 2 + 15 files changed, 162 insertions(+), 153 deletions(-) diff --git a/module/block/control.php b/module/block/control.php index c8a61334cd..9cee29243f 100644 --- a/module/block/control.php +++ b/module/block/control.php @@ -27,18 +27,16 @@ class block extends control /** * Block admin. * - * @param int $index + * @param int $id * @param string $module * @access public * @return void */ - public function admin($index = 0, $module = 'my') + public function admin($id = 0, $module = 'my') { $this->session->set('blockModule', $module); - $title = $index == 0 ? $this->lang->block->createBlock : $this->lang->block->editBlock; - - if(!$index) $index = $this->block->getLastKey($module) + 1; + $title = $id == 0 ? $this->lang->block->createBlock : $this->lang->block->editBlock; if($module == 'my') { @@ -61,11 +59,11 @@ class block extends control elseif(isset($this->lang->block->moduleList[$module])) { $this->get->set('mode', 'getblocklist'); - $this->view->blocks = $this->fetch('block', 'main', "module=$module&index=$index"); + $this->view->blocks = $this->fetch('block', 'main', "module=$module&id=$id"); } - $this->view->block = $this->block->getBlock($index); - $this->view->index = $index; + $this->view->block = $this->block->getBlock($id); + $this->view->blockID = $id; $this->view->title = $title; $this->display(); } @@ -73,22 +71,22 @@ class block extends control /** * Set params when type is rss or html. * - * @param int $index + * @param int $id * @param string $type * @access public * @return void */ - public function set($index, $type, $source = '') + public function set($id, $type, $source = '') { if($_POST) { $source = isset($this->lang->block->moduleList[$source]) ? $source : ''; - $this->block->save($index, $source, $type, $this->session->blockModule); + $this->block->save($id, $source, $type, $this->session->blockModule); if(dao::isError()) die(js::error(dao::geterror())); die(js::reload('parent')); } - $block = $this->block->getBlock($index); + $block = $this->block->getBlock($id); if($block) $type = $block->block; if(isset($this->lang->block->moduleList[$source])) @@ -100,7 +98,7 @@ class block extends control $this->view->source = $source; $this->view->type = $type; - $this->view->index = $index; + $this->view->id = $id; $this->view->block = ($block) ? $block : array(); $this->display(); } @@ -108,21 +106,21 @@ class block extends control /** * Delete block * - * @param int $index + * @param int $id * @param string $sys * @param string $type * @access public * @return void */ - public function delete($index, $module = 'my', $type = 'delete') + public function delete($id, $module = 'my', $type = 'delete') { if($type == 'hidden') { - $this->dao->update(TABLE_BLOCK)->set('hidden')->eq(1)->where('`order`')->eq($index)->andWhere('account')->eq($this->app->user->account)->andWhere('module')->eq($module)->exec(); + $this->dao->update(TABLE_BLOCK)->set('hidden')->eq(1)->where('`id`')->eq($id)->andWhere('account')->eq($this->app->user->account)->andWhere('module')->eq($module)->exec(); } else { - $this->dao->delete()->from(TABLE_BLOCK)->where('`order`')->eq($index)->andWhere('account')->eq($this->app->user->account)->andWhere('module')->eq($module)->exec(); + $this->dao->delete()->from(TABLE_BLOCK)->where('`id`')->eq($id)->andWhere('account')->eq($this->app->user->account)->andWhere('module')->eq($module)->exec(); } if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->send(array('result' => 'success')); @@ -137,18 +135,17 @@ class block extends control * @access public * @return void */ - public function sort($oldOrder, $newOrder, $module = 'my') + public function sort($orders, $module = 'my') { - $oldOrder = explode(',', $oldOrder); - $newOrder = explode(',', $newOrder); - $orderList = $this->block->getBlockList($module); - - foreach($oldOrder as $key => $oldIndex) + $orders = explode(',', $orders); + $blockList = $this->block->getBlockList($module); + + foreach ($orders as $order => $blockID) { - if(!isset($orderList[$oldIndex])) continue; - $order = $orderList[$oldIndex]; - $order->order = $newOrder[$key]; - $this->dao->replace(TABLE_BLOCK)->data($order)->exec(); + $block = $blockList[$blockID]; + if(!isset($block)) continue; + $block->order = $order; + $this->dao->replace(TABLE_BLOCK)->data($block)->exec(); } if(dao::isError()) $this->send(array('result' => 'fail')); @@ -175,20 +172,26 @@ class block extends control foreach($blocks as $block) { - $params = json_decode($block->params); + $block->params = json_decode($block->params); $blockID = $block->block; - $block->blockLink = $this->createLink('block', 'printBlock', "index=$block->order&module=$block->module"); + $block->blockLink = $this->createLink('block', 'printBlock', "id=$block->id&module=$block->module"); $block->moreLink = ''; if(isset($this->lang->block->modules[$module]->moreLinkList->{$blockID})) { - list($moduleName, $method, $vars) = explode('|', sprintf($this->lang->block->modules[$module]->moreLinkList->{$blockID}, $params->type)); + list($moduleName, $method, $vars) = explode('|', sprintf($this->lang->block->modules[$module]->moreLinkList->{$blockID}, $block->params->type)); $block->moreLink = $this->createLink($moduleName, $method, $vars); } } $this->view->blocks = $blocks; $this->view->module = $module; + + if($this->app->getViewType() == 'json') + { + die(json_encode($blocks)); + } + $this->display(); } @@ -208,13 +211,13 @@ class block extends control /** * Print block. * - * @param int $index + * @param int $id * @access public * @return void */ - public function printBlock($index, $module = 'my') + public function printBlock($id, $module = 'my') { - $block = $this->block->getBlock($index, $module); + $block = $this->block->getBlock($id, $module); if(empty($block)) return false; @@ -230,7 +233,7 @@ class block extends control $this->get->set('source', $block->source); $this->get->set('blockid', $block->block); $this->get->set('param',base64_encode(json_encode($block->params))); - $html = $this->fetch('block', 'main', "module={$block->source}&index=$index"); + $html = $this->fetch('block', 'main', "module={$block->source}&id=$id"); } elseif($block->block == 'dynamic') { @@ -246,7 +249,7 @@ class block extends control * @access public * @return void */ - public function main($module = '', $index = 0) + public function main($module = '', $id = 0) { if(!$this->selfCall) { @@ -269,7 +272,7 @@ class block extends control $blocks = json_decode($blocks, true); $blockPairs = array('' => '') + $blocks; - $block = $this->block->getBlock($index); + $block = $this->block->getBlock($id); echo "{$this->lang->block->lblBlock}"; echo '' . html::select('moduleBlock', $blockPairs, ($block and $block->source != '') ? $block->block : '', "class='form-control' onchange='getBlockParams(this.value, \"$module\")'") . ''; diff --git a/module/block/css/dashboard.css b/module/block/css/dashboard.css index efad65eeb1..410b29640f 100644 --- a/module/block/css/dashboard.css +++ b/module/block/css/dashboard.css @@ -2,10 +2,82 @@ body {background: #fafafa;} .page-content {margin-top: -19px; border-top: 1px solid #3280fc;} -.dashboard {position: relative; padding-top: 25px; z-index: 1030} +.dashboard {position: relative;} .dashboard .row {margin: 0 auto;} .dashboard .panel-actions {margin-top: 0; margin-right: 0;} -.dashboard-actions {position: absolute; top: -35px; right: 100px} -.dashboard-actions .btn {padding: 5px 12px} .dashboard .table tr[data-url] td {cursor: pointer;} -.dashboard .panel-heading {height: 30px} +.dashboard .panel-heading {line-height: 17px; height: 30px; position: relative;} +.dashboard .panel-actions {position: absolute; top: 0; right: 0; height: 30px;} +.dashboard .panel-action {display: block; float: left; height: 30px; width: 26px; text-align: center; line-height: 30px;} +.dashboard .panel-action:hover, .dashboard .panel-actions > .dropdown > a:hover {color: #333; background-color: #ddd; background-color: rgba(0,0,0,0.1)} +.dashboard .panel-title {font-size: 13px; color: #333} +.dashboard a.panel-title:hover {color: #1a53ff} +.dashboard .panel {box-shadow: none} + +.outer > .dashboard {margin-left: -10px; margin-right: -10px;} + +/* panel style */ +.panel-block .table th {background-color: #fafafa} +.panel-primary {border-color: transparent;!important;} +.panel-success > .panel-heading, +.panel-warning > .panel-heading, +.panel-primary > .panel-heading, +.panel-info > .panel-heading, +.panel-danger > .panel-heading {color: #333; border: none; border-bottom: 1px solid rgba(0,0,0,.04);} +.panel-success > .panel-body, +.panel-warning > .panel-body, +.panel-primary > .panel-body, +.panel-info > .panel-body, +.panel-danger > .panel-body {box-shadow: inset 0 1px 100px rgba(255,255,255,.6);} +.panel-success {background: #d1fecb!important; border-color: #b0e4ac!important} +.panel-success > .panel-heading {background: #c5f7c1!important; } +.panel-warning {background: #fdfdc7!important; border-color: #e1e09a!important} +.panel-warning > .panel-heading {background: #f8f7b6!important;} +.panel-primary {background: #d8f2fa!important; border-color: #badfeb!important} +.panel-primary > .panel-heading {background: #c9ecf8!important; color: #333!important; border:none!important;} +.panel-info {background: #dcd8fe!important; border-color: #d0c9ee!important} +.panel-info > .panel-heading {background: #d4cdf3!important;} +.panel-danger {background: #f5d0f5!important; border-color: #e9b9e9!important} +.panel-danger > .panel-heading {background: #f1c3f1!important;} +.panel-success .table td, .panel-success .table th, +.panel-warning .table td, .panel-warning .table th, +.panel-primary .table td, .panel-primary .table th, +.panel-info .table td, .panel-info .table th, +.panel-danger .table td, .panel-danger .table th {border: none; background-color: transparent} +.panel-success .table tr:nth-child(even) > td, .panel-success .table th, +.panel-warning .table tr:nth-child(even) > td, .panel-warning .table th, +.panel-primary .table tr:nth-child(even) > td, .panel-primary .table th, +.panel-info .table tr:nth-child(even) > td, .panel-info .table th, +.panel-danger .table tr:nth-child(even) > td, .panel-danger .table th {background: rgba(255,255,255,.25);} +.panel-success .table tr:nth-child(odd) > td, +.panel-warning .table tr:nth-child(odd) > td, +.panel-primary .table tr:nth-child(odd) > td, +.panel-info .table tr:nth-child(odd) > td, +.panel-danger .table tr:nth-child(odd) > td {background: rgba(0,0,0,.03);} +.panel-success .table tr:last-child > td, +.panel-warning .table tr:last-child > td, +.panel-primary .table tr:last-child > td, +.panel-info .table tr:last-child > td +.panel-danger .table tr:last-child > td {border-bottom: 1px solid rgba(0,0,0,0.05)} +.panel-success .table tr:hover > th, +.panel-warning .table tr:hover > th, +.panel-primary .table tr:hover > th, +.panel-info .table tr:hover > th, +.panel-danger .table tr:hover > th {background: none;} +.panel-success .table.table-hover tr:hover > td, +.panel-warning .table.table-hover tr:hover > td, +.panel-primary .table.table-hover tr:hover > td, +.panel-info .table.table-hover tr:hover > td, +.panel-danger .table.table-hover tr:hover > td {background: rgba(255,255,255,.4);} + +.block.input-group-btn .btn-success {background: #d1fecb; color: #333; text-shadow: none; border-color: #ccc} +.block.input-group-btn .btn-warning {background: #fdfdc7; color: #333; text-shadow: none; border-color: #ccc} +.block.input-group-btn .btn-info {background: #dcd8fe; color: #333; text-shadow: none; border-color: #ccc} +.block.input-group-btn .btn-danger {background: #f5d0f5; color: #333; text-shadow: none; border-color: #ccc} +.block.input-group-btn .btn-primary, .block.input-group-btn .btn-primary:focus {background: #d8f2fa; color: #333; text-shadow: none; border-color: #ccc} +.block.input-group-btn .btn-success:hover {border-color: #aaa} +.block.input-group-btn .btn-warning:hover {border-color: #aaa} +.block.input-group-btn .btn-primary:hover {border-color: #aaa} +.block.input-group-btn .btn-info:hover {border-color: #aaa} +.block.input-group-btn .btn-danger:hover {border-color: #aaa} +.block.input-group-btn .btn-primary .caret, .block.input-group-btn .btn-success .caret, .block.input-group-btn .btn-warning .caret, .block.input-group-btn .btn-danger .caret, .block.input-group-btn .btn-info .caret {border-top-color: #333} diff --git a/module/block/js/admin.js b/module/block/js/admin.js index 44fe224e70..e5a2576723 100644 --- a/module/block/js/admin.js +++ b/module/block/js/admin.js @@ -7,6 +7,7 @@ */ function getBlocks(moduleID) { + console.log('getBlocks', moduleID); var moduleBlock = $('#modules').parent().parent().next(); $(moduleBlock).hide(); @@ -24,8 +25,9 @@ function getBlocks(moduleID) return true; } - $.get(createLink('block', 'main', 'module=' + moduleID + '&index=' + index), {mode:'getblocklist'}, function(data) + $.get(createLink('block', 'main', 'module=' + moduleID + '&id=' + blockID), {mode:'getblocklist'}, function(data) { + console.log('GET BLOCKS', moduleID, data); $(moduleBlock).html(data); $(moduleBlock).show(); }) @@ -40,7 +42,7 @@ function getBlocks(moduleID) */ function getRssAndHtmlParams(type) { - $.get(createLink('block', 'set', 'index=' + index + '&type=' + type), function(data) + $.get(createLink('block', 'set', 'id=' + blockID + '&type=' + type), function(data) { $('#blockParam').html(data); }); @@ -57,7 +59,7 @@ function getRssAndHtmlParams(type) function getBlockParams(type, moduleID) { $('#blockParam').empty(); - $.get(createLink('block', 'set', 'index=' + index + '&type=' + type + '&source=' + moduleID), function(data) + $.get(createLink('block', 'set', 'id=' + blockID + '&type=' + type + '&source=' + moduleID), function(data) { $('#blockParam').html(data); }); diff --git a/module/block/js/dashboard.js b/module/block/js/dashboard.js index 7ead30decb..a461cd6b02 100644 --- a/module/block/js/dashboard.js +++ b/module/block/js/dashboard.js @@ -1,6 +1,6 @@ $(function() { - $('#dashboard').dashboard( + var $dashboard = $('#dashboard').dashboard( { height : 240, draggable : true, @@ -10,6 +10,8 @@ $(function() sensitive : true, panelRemovingTip : config.confirmRemoveBlock }); + + $dashboard.find('ul.dashboard-actions').addClass('hide').children('li').addClass('right').appendTo($('#modulemenu > .nav')); }); /** @@ -40,27 +42,14 @@ function deleteBlock(index) */ function sortBlocks(orders) { - var oldOrder = new Array(); - var newOrder = new Array(); - for(i in orders) - { - oldOrder.push(i.replace('block', '')); - newOrder.push(orders[i]); - } - $.getJSON(createLink('block', 'sort', 'oldOrder=' + oldOrder.join(',') + '&newOrder=' + newOrder.join(',') + '&module=' + module), function(data) + var ordersMap = []; + $.each(orders, function(blockId, order) {ordersMap.push({id: blockId, order: order});}); + ordersMap.sort(function(a, b) {return a.order - b.order;}); + var newOrders = $.map(ordersMap, function(order, idx) {return order.id}); + + $.getJSON(createLink('block', 'sort', 'orders=' + newOrders.join(',') + '&module=' + module), function(data) { - - if(data.result != 'success') return false; - - $('#dashboard .panel').each(function() - { - var index = $(this).data('order'); - /* Update new index for block id edit and delete. */ - $(this).attr('id', 'block' + index).attr('data-id', index).data('url', createLink('block', 'printBlock', 'index=' + index)); - $(this).find('.panel-actions .edit-block').attr('href', createLink('block', 'admin', 'index=' + index)); - }); - - $.zui.messager.success(config.ordersSaved); + if(data.result == 'success') $.zui.messager.success(config.ordersSaved); }); } diff --git a/module/block/model.php b/module/block/model.php index 13f62e3a73..395fef831b 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -21,11 +21,12 @@ class blockModel extends model * @access public * @return void */ - public function save($index, $source, $type, $module = 'my') + public function save($id, $source, $type, $module = 'my') { $data = fixer::input('post') ->add('account', $this->app->user->account) - ->add('order', $index) + ->setIF($id, 'id', $id) + ->setIF(!$id, 'order', $this->getLastKey($module) + 1) ->add('module', $module) ->add('hidden', 0) ->setDefault('grid', '4') @@ -60,14 +61,14 @@ class blockModel extends model /** * Get saved block config. * - * @param int $index + * @param int $id * @access public * @return object */ - public function getBlock($index, $module = 'my') + public function getBlock($id, $module = 'my') { $block = $this->dao->select('*')->from(TABLE_BLOCK) - ->where('`order`')->eq($index) + ->where('`id`')->eq($id) ->andWhere('account')->eq($this->app->user->account) ->andWhere('module')->eq($module) ->fetch(); @@ -87,13 +88,13 @@ class blockModel extends model */ public function getLastKey($module = 'my') { - $index = $this->dao->select('`order`')->from(TABLE_BLOCK) + $order = $this->dao->select('`order`')->from(TABLE_BLOCK) ->where('module')->eq($module) ->andWhere('account')->eq($this->app->user->account) ->orderBy('order desc') ->limit(1) ->fetch('order'); - return $index ? $index : 0; + return $order ? $order : 0; } /** @@ -109,7 +110,7 @@ class blockModel extends model ->andWhere('module')->eq($module) ->andWhere('hidden')->eq(0) ->orderBy('`order`') - ->fetchAll('order'); + ->fetchAll('id'); return $blocks; } diff --git a/module/block/view/admin.html.php b/module/block/view/admin.html.php index 6346630fe1..775623f6f9 100644 --- a/module/block/view/admin.html.php +++ b/module/block/view/admin.html.php @@ -10,7 +10,7 @@ * @link http://www.ranzhico.com */ ?> - + @@ -26,5 +26,5 @@
- - + + diff --git a/module/block/view/dashboard.html.php b/module/block/view/dashboard.html.php index 18a3cedd3d..20a3f21ae1 100644 --- a/module/block/view/dashboard.html.php +++ b/module/block/view/dashboard.html.php @@ -16,30 +16,33 @@ $themeRoot = $webRoot . "theme/"; if(isset($pageCSS)) css::internal($pageCSS); ?>
+
$block):?>
-
params->color;?>' id='block' data-id='' data-name='title?>' data-url='blockLink?>'> +
params->color;?>' id='blockid?>' data-id='id?>' data-name='title?>' data-url='blockLink?>'>
- title;?> + moreLink)):?> + moreLink, $block->title . " ", null, "class='panel-title drag-disabled' title='$lang->more'"); ?> + + title;?> +
-
- -
-
- - -
-
- -
-
-
-
- -
- user->role and strpos('qa|qd', $app->user->role) !== false):?> -
- -
-
- -
- user->role and strpos('po|pd', $app->user->role) !== false):?> -
- -
-
- -
- -
- -
-
- -
- -
+fetch('block', 'dashboard', 'module=my');?> diff --git a/module/project/view/index.html.php b/module/project/view/index.html.php index b2d9b3ed94..542c95265e 100644 --- a/module/project/view/index.html.php +++ b/module/project/view/index.html.php @@ -10,4 +10,6 @@ */ ?> +fetch('block', 'dashboard', 'module=project');?> +