* support to save blocks layout in dashboard.
This commit is contained in:
@@ -304,4 +304,21 @@ class block extends control
|
||||
|
||||
return $this->send(array('result' => 'success'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改当前用户仪表盘区块的布局。
|
||||
* Change dashboard layout.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function layout()
|
||||
{
|
||||
if(!$_POST) return $this->send(array('result' => 'fail', 'message' => $this->lang->error->noData));
|
||||
|
||||
$blocksLayout = $this->post->block;
|
||||
$this->block->updateLayout($blocksLayout);
|
||||
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,38 @@ function resetBlocks(dashboard, data, block)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle layout change and save to server.
|
||||
*
|
||||
* @param {object} layout
|
||||
*/
|
||||
window.handleLayoutChange = function(layout)
|
||||
{
|
||||
const form = new FormData();
|
||||
Object.keys(layout).forEach(key =>
|
||||
{
|
||||
const block = layout[key];
|
||||
form.append(`block[${key}][left]`, block.left);
|
||||
form.append(`block[${key}][top]`, block.top);
|
||||
});
|
||||
const dashboard = $('#dashboard').data('dashboard');
|
||||
$.ajaxSubmit(
|
||||
{
|
||||
url: $.createLink('block', 'layout'),
|
||||
data: form,
|
||||
onSuccess: (result) =>
|
||||
{
|
||||
console.log('> handleLayoutChange.result', result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle block menu click.
|
||||
*
|
||||
* @param {object} info
|
||||
* @param {object} block
|
||||
*/
|
||||
window.handleClickBlockMenu = function(info, block)
|
||||
{
|
||||
const data = info.item.data;
|
||||
|
||||
@@ -278,4 +278,27 @@ class blockModel extends model
|
||||
if(!$top) $top = 0;
|
||||
return $top;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新区块布局(保存每个区块的坐标信息)。
|
||||
* Update block layout.
|
||||
*
|
||||
* @param array $layout
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function updateLayout(array $layout): bool
|
||||
{
|
||||
foreach($layout as $blockID => $block)
|
||||
{
|
||||
$this->dao->update(TABLE_BLOCK)
|
||||
->set('left')->eq($block['left'])
|
||||
->set('top')->eq($block['top'])
|
||||
->where('id')->eq($blockID)
|
||||
->exec();
|
||||
|
||||
if(dao::isError()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ dashboard
|
||||
(
|
||||
set::blocks(array_values($blocks)),
|
||||
set::blockMenu(array('items' => $blockMenuItems)),
|
||||
set::onClickMenu(jsRaw('handleClickBlockMenu'))
|
||||
set::onClickMenu(jsRaw('handleClickBlockMenu')),
|
||||
set::onLayoutChange(jsRaw('handleLayoutChange'))
|
||||
);
|
||||
|
||||
render();
|
||||
|
||||
Reference in New Issue
Block a user