From ea0427036219c0258935732b39c1e913da48cee4 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 7 Mar 2018 14:31:26 +0800 Subject: [PATCH] * adjust for block. --- lib/front/front.class.php | 18 +++ module/block/control.php | 9 +- module/block/css/admin.css | 11 +- module/block/js/admin.js | 167 ++++++++++++++------------ module/block/model.php | 2 +- module/block/view/admin.html.php | 45 ++++--- module/block/view/publicform.html.php | 22 ++-- module/block/view/set.html.php | 22 ++-- module/block/view/setmodule.html.php | 74 +++++------- 9 files changed, 195 insertions(+), 175 deletions(-) diff --git a/lib/front/front.class.php b/lib/front/front.class.php index 8c6a881a13..99dedc8632 100644 --- a/lib/front/front.class.php +++ b/lib/front/front.class.php @@ -124,6 +124,24 @@ class html extends baseHTML /* End. */ return $string .= "\n"; } + + /** + * Create input tag that type is number. + * + * @param string $name + * @param string $value + * @param string $attrib + * @static + * @access public + * @return string + */ + static public function number($name, $value = '', $attrib = '') + { + $id = "id='$name'"; + if(strpos($attrib, 'id=') !== false) $id = ''; + $value = str_replace("'", ''', $value); + return "\n"; + } } /** diff --git a/module/block/control.php b/module/block/control.php index aa14fda530..805faf2520 100644 --- a/module/block/control.php +++ b/module/block/control.php @@ -74,7 +74,6 @@ class block extends control $this->view->title = $title; $this->view->block = $this->block->getByID($id); $this->view->blockID = $id; - $this->view->title = $title; $this->display(); } @@ -384,9 +383,11 @@ class block extends control $block = $this->block->getByID($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\")'") . ''; - if(isset($block->source)) echo ""; + echo '
'; + echo ''; + echo '
'; + echo html::select('moduleBlock', $blockPairs, ($block and $block->source != '') ? $block->block : '', "class='form-control chosen'"); + echo '
'; } elseif($mode == 'getblockform') { diff --git a/module/block/css/admin.css b/module/block/css/admin.css index 31ad83a92c..4da9ab98db 100644 --- a/module/block/css/admin.css +++ b/module/block/css/admin.css @@ -1,8 +1,3 @@ -.input-group-btn .dropdown-toggle {border-radius: 4px;} -.dropdown-menu {min-width: 120px;} -.dropdown-menu.colors {padding: 5px; width: 205px} -.dropdown-menu.buttons {padding: 5px; padding-bottom: 0; padding-right: 0;} -.dropdown-menu.buttons > li {margin-bottom: 5px; display: block; float: left; width: 33.333333%; padding-right: 5px} -.table.table-form{margin-bottom:0px;} -#blockParam{padding-right:100px;} -#blockParam .table td, #blockParam .table th{border-bottom:0px;} +#blockAdmin {min-height: 280px;} +#blockAdmin .form-actions {visibility: hidden;} +#blockAdmin.form-inited .form-actions {visibility: visible;} diff --git a/module/block/js/admin.js b/module/block/js/admin.js index b03d872274..d5e5408db9 100644 --- a/module/block/js/admin.js +++ b/module/block/js/admin.js @@ -1,85 +1,92 @@ -/** - * Get all blocks. - * - * @param string|int $moduleID - * @access public - * @return void - */ -function getBlocks(moduleID) -{ - var moduleBlock = $('#modules').parent().parent().next(); - $(moduleBlock).hide(); - - $('#blockParam').empty(); - if(moduleID == '') return false; - - if(moduleID.indexOf('hiddenBlock') != -1) - { - getNotSourceParams('html', moduleID.replace('hiddenBlock', '')); - return true; - } - if(moduleID == 'html' || moduleID == 'dynamic' || moduleID == 'flowchart' || moduleID == 'assigntome' || moduleID == 'welcome') - { - getNotSourceParams(moduleID, blockID); - return true; - } - - $.get(createLink('block', 'main', 'module=' + moduleID + '&id=' + blockID), {mode:'getblocklist'}, function(data) - { - $(moduleBlock).html(data); - $(moduleBlock).show(); - $.ajustModalPosition(); - }) -} - -/** - * Get rss and html params. - * - * @param string $type - * @access public - * @return void - */ -function getNotSourceParams(type, blockID) -{ - blockID = typeof(blockID) == 'undefined' ? 0 : blockID; - $.get(createLink('block', 'set', 'id=' + blockID + '&type=' + type), function(data) - { - $('#blockParam').html(data); - $.ajustModalPosition(); - }); -} - -/** - * Get block params. - * - * @param string $type - * @param int $moduleID - * @access public - * @return void - */ -function getBlockParams(type, moduleID) -{ - $('#blockParam').empty(); - - if(type == '') return; - - $.get(createLink('block', 'set', 'id=' + blockID + '&type=' + type + '&source=' + moduleID), function(data) - { - $('#blockParam').html(data); - $.ajustModalPosition(); - }); -} - $(function() { - $('#modules').change(function(){getBlocks($(this).val())}); - if($('#modules').size() > 0) getBlocks($('#modules').val()); + var $form = $('#blockAdminForm'); + $form.find('.chosen').chosen(); - $(document).on('click', '.dropdown-menu.buttons .btn', function() + // 用于动态加载区块列表及设置参数 + var $blocksList = $('#blocksList'); + var $blockParams = $('#blockParams'); + + var updateParams = function(data) { - var $this = $(this); - var group = $this.closest('.input-group-btn'); - group.find('.dropdown-toggle').removeClass().addClass('btn dropdown-toggle btn-' + $this.data('id')); - group.find('input[name^="params[color]"]').val($this.data('id')); + $blockParams.html(data); + $blockParams.find('.chosen').chosen(); + $.zui.ajustModalPosition(); + $form.removeClass('loading'); + $form.addClass('form-inited'); + $blockParams.find('input:first').focus(); + if($blockParams.find('#actionLink').size() > 0) $form.attr('action', $blockParams.find('#actionLink').val()); + }; + + // 获取 html 和 rss 区块参数 + var getNotSourceParams = function(type, blockID) + { + if (blockID === undefined) blockID = 0; + + $blockParams.empty(); + $form.removeClass('form-inited'); + + $.get(createLink('block', 'set', 'id=' + blockID + '&type=' + type), updateParams); + }; + + // 用于获取指定区块的设置参数 + var getBlockParams = function(type, moduleID) + { + $blockParams.empty(); + $form.removeClass('form-inited'); + + if(type == '') return; + $form.addClass('loading'); + $.get(createLink('block', 'set', 'id=' + blockID + '&type=' + type + '&source=' + moduleID), updateParams); + }; + + // 获取指定模块下所有可用的区块 + var getBlocks = function(moduleID) + { + $blocksList.data('module', moduleID).empty(); + $form.removeClass('form-inited'); + $blockParams.empty(); + if(!moduleID) return; + + $form.addClass('loading'); + + var onFinish = function() + { + $form.removeClass('loading'); + if($blocksList.find('#moduleBlock').val() != '') getBlockParams($blocksList.find('#moduleBlock').val(), $blocksList.data('module')); + }; + + if(moduleID.indexOf('hiddenBlock') != -1) + { + getNotSourceParams('html', moduleID.replace('hiddenBlock', ''), onFinish); + return true; + } + + if(moduleID == 'html' || moduleID == 'dynamic' || moduleID == 'flowchart' || moduleID == 'assigntome' || moduleID == 'welcome') + { + getNotSourceParams(moduleID, blockID, onFinish); + return true; + } + + $.get(createLink('block', 'main', 'module=' + moduleID + '&id=' + blockID), {mode:'getblocklist'}, function(data) + { + $blocksList.html(data); + $blocksList.find('.chosen').chosen(); + onFinish(); + $.zui.ajustModalPosition(); + }); + }; + + // 当模块选择变更时,刷新参数列表 + $('#modules').on('change', function() + { + getBlocks($(this).val()); }); -}) + + $blocksList.on('change', '#moduleBlock', function() + { + getBlockParams($(this).val(), $blocksList.data('module')); + }); + + if(blockID) setTimeout(function(){getBlocks($('#modules').val());}, 200); +}); diff --git a/module/block/model.php b/module/block/model.php index 6b0bf0fcc5..20054b403a 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -35,7 +35,7 @@ class blockModel extends model ->setDefault('source', $source) ->setDefault('block', $type) ->setDefault('params', array()) - ->remove('uid') + ->remove('uid,actionLink,modules,moduleBlock') ->get(); if($block) $data->height = $block->height; diff --git a/module/block/view/admin.html.php b/module/block/view/admin.html.php index 463ebbff46..9cac5bec90 100644 --- a/module/block/view/admin.html.php +++ b/module/block/view/admin.html.php @@ -10,21 +10,36 @@ * @link http://www.ranzhico.com */ ?> +app->getWebRoot(); +$jsRoot = $webRoot . "js/"; +include '../../common/view/chosen.html.php'; +?> +
+
+ +
+ source != '' ? $block->source : $block->block; + ?> + +
+
+ + +
+ + +
+ +
+
+   + +
+
+
- - - - - - source != '' ? $block->source : $block->block; - ?> - - - - -
block->lblModule; ?>
-
diff --git a/module/block/view/publicform.html.php b/module/block/view/publicform.html.php index 012526a78c..333f079bfd 100644 --- a/module/block/view/publicform.html.php +++ b/module/block/view/publicform.html.php @@ -10,17 +10,16 @@ * @link http://www.zentao.net */ ?> - - block->name?> - title : '', "class='form-control' autocomplete='off'")?> - - - block->style;?> - -
+
+ +
title : '', "class='form-control' autocomplete='off'")?>
+
+
+ +
block->grid;?> - block->gridOptions, $block ? $block->grid : 8, "class='form-control'")?> + block->gridOptions, $block ? $block->grid : 8, "class='form-control chosen'")?>
params->color) ? 'btn-' . $block->params->color : 'btn-default'?>
-
- - +
+ diff --git a/module/block/view/set.html.php b/module/block/view/set.html.php index 07bae15920..4ba840919a 100644 --- a/module/block/view/set.html.php +++ b/module/block/view/set.html.php @@ -24,20 +24,14 @@ if($type == 'html') include '../../common/view/kindeditor.html.php'; } ?> -
'> - - - - - - - - - - - -
block->lblHtml;?>params->html : '', "class='form-control' rows='10'")?>
-
+ +createLink('block', 'set', "id=$id&type=$type&source=$source"));?> + +
+ +
params->html : '', "class='form-control' rows='10'")?>
+
+