Skip to content

Commit

Permalink
#20 - Add new grid overview template (and pref)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moc committed Aug 22, 2022
1 parent 85a5183 commit 41c27ce
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 48 deletions.
13 changes: 13 additions & 0 deletions admin_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ class cookbook_recipes_ui extends e_admin_ui

protected $prefs = array(

'overview_format' => array(
'title' => 'Overview format',
'type' => 'dropdown',
'data' => 'str',
'help' => 'Grid view or Datatables',
'tab' => 0,
),
'date_format' => array(
'title' => 'Date format',
'type' => 'dropdown',
Expand Down Expand Up @@ -489,6 +496,12 @@ public function init()
"relative" => "relative"
);

// Overview format: allow to choose between a Grid overview or Datatables
$this->prefs['overview_format']['writeParms'] = array(
"overview_grid" => "Grid overview",
"overview_datatable" => "Datatable overview",
);

}

// Make some adjustments before storing the new data in the database
Expand Down
10 changes: 6 additions & 4 deletions cookbook_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,25 @@ public function renderOverviewTable($recipes)
{
$text = '';

$key = e107::getPlugPref('cookbook', 'overview_format', 'overview_grid');

// Load template
$template = e107::getTemplate('cookbook');
$template = e107::getTemplate('cookbook', null, $key);
$template = array_change_key_case($template);

// Load shortcode
$sc = e107::getScBatch('cookbook', true);

$text .= e107::getParser()->parseTemplate($template['overview']['start'], true, $sc);
$text .= e107::getParser()->parseTemplate($template['start'], true, $sc);

foreach($recipes as $recipe)
{
// Pass query values onto the shortcodes
$sc->setVars($recipe);
$text .= e107::getParser()->parseTemplate($template['overview']['items'], true, $sc);
$text .= e107::getParser()->parseTemplate($template['items'], true, $sc);
}

$text .= e107::getParser()->parseTemplate($template['overview']['end'], true, $sc);
$text .= e107::getParser()->parseTemplate($template['end'], true, $sc);

return $text;
}
Expand Down
88 changes: 47 additions & 41 deletions e_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
$cookbook_page = true;
}

$key = e107::getPlugPref('cookbook', 'overview_format', 'overview_grid');

// Code is only needed on frontend cookbook pages
if(USER_AREA && varsettrue($cookbook_page))
{
// General CSS styling
e107::css('cookbook', 'cookbook_style.css');

// Raty plugin
e107::js('cookbook', 'plugins/raty/jquery.raty.js', 'jquery');

Expand All @@ -26,51 +31,52 @@
e107::js('cookbook', 'plugins/tagcloud/jqcloud-1.0.4.min.js', 'jquery');

// Datatables plugin
if(defined('BOOTSTRAP') && BOOTSTRAP === 3)
{
e107::css('cookbook', 'plugins/datatables/css/datatables-bs3.min.css');
e107::js('cookbook', 'plugins/datatables/js/datatables-bs3.min.js');
}
elseif(defined('BOOTSTRAP') && BOOTSTRAP === 4)
{
e107::css('cookbook', 'plugins/datatables/css/datatables-bs4.min.css');
e107::js('cookbook', 'plugins/datatables/js/datatables-bs4.min.js');
}
else
if($key == "overview_datatable")
{
e107::css('cookbook', 'plugins/datatables/css/datatables.min.css');
e107::js('cookbook', 'plugins/datatables/js/datatables.min.js');
}

// DataTables language files
$system_lan = e_PLUGIN."cookbook/plugins/datatables/languages/".e_LANGUAGE.".json";
$default_lan = e_PLUGIN_ABS."cookbook/plugins/datatables/languages/English.json";
$dt_lan_file = (file_exists($system_lan) ? $system_lan : $default_lan);
if(defined('BOOTSTRAP') && BOOTSTRAP === 3)
{
e107::css('cookbook', 'plugins/datatables/css/datatables-bs3.min.css');
e107::js('cookbook', 'plugins/datatables/js/datatables-bs3.min.js');
}
elseif(defined('BOOTSTRAP') && BOOTSTRAP === 4)
{
e107::css('cookbook', 'plugins/datatables/css/datatables-bs4.min.css');
e107::js('cookbook', 'plugins/datatables/js/datatables-bs4.min.js');
}
else
{
e107::css('cookbook', 'plugins/datatables/css/datatables.min.css');
e107::js('cookbook', 'plugins/datatables/js/datatables.min.js');
}

$order = "order: [[4, 'desc']],";
// DataTables language files
$system_lan = e_PLUGIN."cookbook/plugins/datatables/languages/".e_LANGUAGE.".json";
$default_lan = e_PLUGIN_ABS."cookbook/plugins/datatables/languages/English.json";
$dt_lan_file = (file_exists($system_lan) ? $system_lan : $default_lan);

if(defset('e_ROUTE') === "cookbook/recent")
{
$order = "order: [],";
}

$order = "order: [[4, 'desc']],";

e107::js('inline',
"
$(document).ready(function() {
$('table.recipes').dataTable( {
".$order."
columnDefs: [
{orderable: false, targets: 0},
{orderable: false, targets: 5},
],
language: {
url: '".$dt_lan_file."'
}
});
});
");
if(defset('e_ROUTE') === "cookbook/recent")
{
$order = "order: [],";
}


// General CSS styling
e107::css('cookbook', 'cookbook_style.css');
e107::js('inline',
"
$(document).ready(function() {
$('table.recipes').dataTable( {
".$order."
columnDefs: [
{orderable: false, targets: 0},
{orderable: false, targets: 5},
],
language: {
url: '".$dt_lan_file."'
}
});
});
");
}
}
32 changes: 29 additions & 3 deletions templates/cookbook_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,34 @@

if (!defined('e107_INIT')) { exit; }

// OVERVIEW GRID
$COOKBOOK_TEMPLATE['overview_grid']['start'] = '
<div class="row">';

$COOKBOOK_TEMPLATE['overview_grid']['items'] = '
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
{SETIMAGE: w=240}
{COOKBOOK_RECIPE_THUMB}
<div class="caption text-center">
<h3>{COOKBOOK_RECIPE_NAME}</h3>
<p>{COOKBOOK_RECIPE_SUMMARY}</p>
<ul class="list-inline text-center">
<li>{GLYPH=fa-clock} {COOKBOOK_TIME}</li>
<li>{GLYPH=fa-user} {COOKBOOK_AUTHOR}</li>
</ul>
</div>
</div>
</div>
';

$COOKBOOK_TEMPLATE['overview_grid']['end'] = '
</div>';


// OVERVIEW TABLE
$COOKBOOK_TEMPLATE['overview']['start'] = '
$COOKBOOK_TEMPLATE['overview_datatable']['start'] = '
<div align="left pull-left">
<table class="table table-bordered text-left recipes dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
Expand All @@ -27,7 +53,7 @@
<tbody>
';

$COOKBOOK_TEMPLATE['overview']['items'] = '
$COOKBOOK_TEMPLATE['overview_datatable']['items'] = '
<tr>
<td>{COOKBOOK_RECIPE_NAME}</td>
<td>{COOKBOOK_CATEGORY_NAME}</td>
Expand All @@ -38,7 +64,7 @@
</tr>
';

$COOKBOOK_TEMPLATE['overview']['end'] = '
$COOKBOOK_TEMPLATE['overview_datatable']['end'] = '
</tbody>
</table>
</div>
Expand Down

0 comments on commit 41c27ce

Please sign in to comment.