Commit 4ef75593 authored by Yuliya Bozhko's avatar Yuliya Bozhko Committed by Aaron Wells
Browse files

Generate SVG image preview for page layouts (Bug #1392096)



Change-Id: I32faf161d9ef7c9cd020134a08998ce48acc7060
Signed-off-by: default avatarYuliya Bozhko <yuliya.bozhko@totaralms.com>
parent b5b899b1
......@@ -2817,7 +2817,7 @@ table.templateresults td.right input.submit {
#viewlayout .layoutthumb {
display: block;
}
#viewlayout .layoutthumb img {
#viewlayout .layoutthumb svg {
margin-top: 5px;
background: #FFFFFF;
border: 1px solid #CCCCCC;
......@@ -2906,6 +2906,14 @@ table.templateresults td.right input.submit {
border: 1px solid #CCCCCC;
padding: 5px;
}
#viewlayout .layoutthumb rect.layout1,
#custompreview rect.layout1 {
fill: #666666;
}
#viewlayout .layoutthumb rect.layout0,
#custompreview rect.layout0 {
fill: #4d4d4d;
}
#addlayout {
margin: 0;
}
......
......@@ -15,7 +15,6 @@ define('NOCHECKREQUIREDFIELDS', 1);
require('init.php');
require_once('file.php');
require_once('user.php');
require_once('layoutpreviewimage.php');
$type = param_alpha('type');
......@@ -162,43 +161,6 @@ switch ($type) {
readfile_exit($path);
}
readfile_exit($THEME->get_path('images/no_thumbnail.png'));
case 'viewlayout':
header('Content-type: image/png');
$vl = param_integer('vl');
$rows = get_records_sql_assoc('
SELECT vlrc.row, vlc.widths
FROM {view_layout_rows_columns} vlrc
INNER JOIN {view_layout_columns} vlc ON (vlrc.columns = vlc.id)
WHERE vlrc.viewlayout = ?
ORDER BY vlrc.row ASC',
array($vl));
if ($rows) {
$filename = 'vl-';
foreach ($rows as $key => $row) {
$filename .= str_replace(',', '-', $row->widths);
$filename .= ($key == count($rows))? '.png' : '_';
}
if (($path = get_config('dataroot') . LayoutPreviewImage::$destinationfolder . '/' . $filename)
&& (is_readable($path))) {
readfile_exit($path);
}
// look in theme folder for default layout thumbs, or dataroot folder for custom layout thumbs
else if (($path = $THEME->get_path('images/' . $filename))
&& (is_readable($path))) {
readfile_exit($path);
}
}
readfile_exit($THEME->get_path('images/no_thumbnail.png'));
case 'customviewlayout':
header('Content-type: image/png');
$cvl = param_variable('cvl');
// dataroot folder for custom layout thumbs
if (($path = get_config('dataroot') . LayoutPreviewImage::$destinationfolder . '/' . $cvl . '.png')
&& (is_readable($path))) {
readfile_exit($path);
}
readfile_exit($THEME->get_path('images/no_thumbnail.png'));
}
function readfile_exit($path) {
......
......@@ -60,17 +60,15 @@ $maxrows = 3;
foreach ($layoutrows as $key => $layout) {
$maxrows = (count($layout) > $maxrows)? count($layout) : $maxrows;
$layoutoptions[$key]['rows'] = count($layout);
$layoutoptions[$key]['text'] = '';
for ($r=0; $r<count($layout); $r++) {
// store multi-row column widths for each option - used as img titles in layout.tpl
if ($r==0) {
$layoutoptions[$key]['columns'] = get_string($layoutcolumns[$layout[$r+1]]->widths, 'view');
}
else {
$layoutoptions[$key]['columns'] .= ' / ' . get_string($layoutcolumns[$layout[$r+1]]->widths, 'view');
}
$structure = array();
for ($r = 1; $r <= count($layout); $r++) {
$structure['layout']['row' . $r] = get_string($layoutcolumns[$layout[$r]]->widths, 'view');
}
$structure['text'] = implode(' / ', $structure['layout']);
$l = new LayoutPreviewImage($structure);
$layoutoptions[$key]['layout'] = $l->create_preview();
$layoutoptions[$key]['columns'] = $structure['text'];
}
foreach ($basicoptionids as $id) {
......@@ -97,6 +95,11 @@ $defaultlayout = get_record('view_layout_columns', 'columns', $defaultcustomlayo
$clnumcolumnsdefault = $defaultlayout->columns;
$clwidths = $defaultlayout->widths;
// Ready custom layout preview.
$defaultlayoutpreviewdata['layout']['row1'] = get_string($defaultcustomlayout[1]->widths, 'view');
$defaultlayoutpreviewdata['text'] = get_string($defaultcustomlayout[1]->widths, 'view');
$defaultlayoutpreview = new LayoutPreviewImage($defaultlayoutpreviewdata);
$inlinejavascript = <<<JAVASCRIPT
function get_max_custom_rows() {
......@@ -141,7 +144,8 @@ $templatedata = array(
'clnumcolumnsoptions' => $clnumcolumnsoptions,
'clnumcolumnsdefault' => $clnumcolumnsdefault,
'columnlayoutoptions' => $columnlayoutoptions,
'customlayout' => $defaultlayout->id,
'customlayoutid' => $defaultlayout->id,
'customlayout' => $defaultlayoutpreview->create_preview(),
'clwidths' => $clwidths,
'maxrows' => $maxrows
);
......@@ -160,7 +164,7 @@ $layoutform = pieform($layoutform);
$javascript = array('jquery','js/jquery/jquery-ui/js/jquery-ui-1.10.2.min.js', 'js/customlayout.js','js/jquery/modernizr.custom.js');
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css') . '">';
$smarty = smarty($javascript, $stylesheets, array('view' => array('Row', 'removethisrow', 'rownr', 'nrrows', 'generatingpreview')), array('sidebars' => false));
$smarty = smarty($javascript, $stylesheets, array('view' => array('Row', 'removethisrow', 'rownr', 'nrrows')), array('sidebars' => false));
$smarty->assign('INLINEJAVASCRIPT', $inlinejavascript);
$smarty->assign('form', $layoutform);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment