Skip to content

Commit

Permalink
Added Jquery ajax pagination and a loader for settings page. I'm also…
Browse files Browse the repository at this point in the history
… caching tag clouds.

Signed-off-by: Joachim Nyqvist <Joachim@JNyqvist.se>
  • Loading branch information
CalvinMcGee committed Nov 26, 2010
1 parent caa5602 commit c9acb97
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 20 deletions.
6 changes: 5 additions & 1 deletion app/controllers/items_controller.php
Expand Up @@ -6,7 +6,7 @@
class ItemsController extends AppController {

var $name = 'Items';
var $helpers = array('Text', 'Image');
var $helpers = array('Text', 'Image', 'Js');
var $components = array('RequestHandler');

var $paginate = array(
Expand All @@ -17,6 +17,7 @@ class ItemsController extends AppController {
);

function index($category = null, $name = null) {
$this->layout = 'items';

switch ($category) {

Expand Down Expand Up @@ -67,6 +68,9 @@ function index($category = null, $name = null) {
'tags' => $this->Item->find('all', array('fields' => 'Item.genre')),
'title' => $title
));
if ($this->RequestHandler->isAjax()) {
$this->autoLayout = false;
}
}

function cloud($category = null, $name = null) {
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/settings_controller.php
Expand Up @@ -6,8 +6,8 @@
class SettingsController extends AppController {

var $name = 'Settings';
var $components = array('Security', 'Session', 'Cookie');
var $helpers = array('Time');
var $components = array('Security', 'Session', 'Cookie', 'RequestHandler');
var $helpers = array('Time', 'Js');

function beforeFilter() {
$this->view = 'Theme';
Expand Down
15 changes: 10 additions & 5 deletions app/views/themed/default/items/cloud.ctp
Expand Up @@ -2,22 +2,27 @@
<?php
echo $this->Html->div('tagcloud',
$this->Html->tag('h2', __('Genres', true), array('escape' => true)).
$this->element('tagcloud', array('data' => $genres, 'escape' => true))
$this->element('tagcloud', array('data' => $genres, 'escape' => true),
array('cache' => '+1 hour'))
)."\n";
echo $this->Html->div('tagcloud',
$this->Html->tag('h2', __('Directors', true), array('escape' => true)).
$this->element('tagcloud', array('data' => $directors, 'escape' => true))
$this->element('tagcloud', array('data' => $directors, 'escape' => true),
array('cache' => '+1 hour'))
)."\n";
echo $this->Html->div('tagcloud',
$this->Html->tag('h2', __('Actors', true), array('escape' => true)).
$this->element('tagcloud', array('data' => $actors, 'escape' => true))
$this->element('tagcloud', array('data' => $actors, 'escape' => true),
array('cache' => '+1 hour'))
)."\n";
echo $this->Html->div('tagcloud',
$this->Html->tag('h2', __('Countries', true), array('escape' => true)).
$this->element('tagcloud', array('data' => $countries, 'escape' => true))
$this->element('tagcloud', array('data' => $countries, 'escape' => true),
array('cache' => '+1 hour'))
)."\n";
echo $this->Html->div('tagcloud',
$this->Html->tag('h2', __('Years of publication', true), array('escape' => true)).
$this->element('tagcloud', array('data' => $years, 'escape' => true))
$this->element('tagcloud', array('data' => $years, 'escape' => true),
array('cache' => '+1 hour'))
)."\n";
?>
25 changes: 15 additions & 10 deletions app/views/themed/default/items/index.ctp
@@ -1,13 +1,18 @@
<h2><?php echo $title; ?></h2>
<?php
echo $this->Html->div('tagcloud', $this->element('tagcloud', array('data' => $tags, 'escape' => true)))."\n";
echo $this->Html->div('tagcloud', $this->element('tagcloud', array('data' => $tags, 'escape' => true), array('cache' => '+1 hour')))."\n";

$paginator->options(array(
'update' => '#ajax',
'evalScripts' => true
));

echo $this->Html->div('paginationlinks', $paginator->numbers()."<br />\n".
$paginator->prev('<< '.__('Previous', true).' ')."\n".
$paginator->next(' '.__('Next', true).' >>')."<br />\n".
$paginator->counter(array('format' => '<span>'.__('Page %page% of %pages%', true).'</span>'))."\n"
)."\n";

)."\n";?>
<?php
foreach ($data as $post) {
echo "<div class=\"item clearfix\">\n";

Expand Down Expand Up @@ -40,7 +45,7 @@ else
$content .= ", \n";
$i++;
}
echo $this->Html->tableCells(array(__('Actors:', true), $content))."\n";
echo $this->Html->tableCells(array(languageField($field).':', $content))."\n";
}
elseif ($field == 'genre') {
$g = preg_split("/[\s]*[,][\s]*/", trim($post['Item'][$field]));
Expand All @@ -55,7 +60,7 @@ else
$content .= ", \n";
$i++;
}
echo $this->Html->tableCells(array(__('Genre:', true), $content))."\n";
echo $this->Html->tableCells(array(languageField($field).':', $content))."\n";
}
elseif ($field == 'director') {
$g = preg_split("/[\s]*[,][\s]*/", trim($post['Item'][$field]));
Expand All @@ -70,7 +75,7 @@ else
$content .= ", \n";
$i++;
}
echo $this->Html->tableCells(array(__('Director:', true), $content))."\n";
echo $this->Html->tableCells(array(languageField($field).':', $content))."\n";
}
elseif ($field == 'webpage') {
echo $this->Html->tableCells(array('',
Expand All @@ -80,15 +85,15 @@ else
))."\n";
}
else
echo $this->Html->tableCells(array($field.':', trim($post['Item'][$field])))."\n";
echo $this->Html->tableCells(array(languageField($field).':', trim($post['Item'][$field])))."\n";
}
echo "</table>\n</div>\n";
echo "</div>\n";
}

}?>
<?php
echo $this->Html->div('paginationlinks', $paginator->numbers()."<br />\n".
$paginator->prev('<< '.__('Previous', true).' ')."\n".
$paginator->next(' '.__('Next', true).' >>')."<br />\n".
$paginator->counter(array('format' => '<span>'.__('Page %page% of %pages%', true).'</span>'))."\n"
)."\n";
?>
?>
4 changes: 3 additions & 1 deletion app/views/themed/default/layouts/default.ctp
Expand Up @@ -14,6 +14,7 @@
), array('type' => 'rss'));

echo $this->Html->css(array('reset', '960', 'style'));
echo $this->Html->script('jquery');

echo $scripts_for_layout;
?>
Expand All @@ -37,7 +38,7 @@
))."\n";
?>
</div>
<div class="grid_10 omega">
<div id="ajax" class="grid_10 omega">
<?php echo $this->Session->flash(); ?>

<?php echo $content_for_layout; ?>
Expand All @@ -49,5 +50,6 @@
</div>
<div class="clear"></div>
</div>
<?php echo $this->Js->writeBuffer(); ?>
</body>
</html>
49 changes: 49 additions & 0 deletions app/views/themed/default/layouts/items.ctp
@@ -0,0 +1,49 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $this->Html->charset(); ?>
<title>
<?php echo $title_for_layout; ?>
</title>
<?php
echo $this->Html->meta('icon');

echo $this->Html->meta(__('Most Recent Items', true), array(
'controller' => 'items',
'action' => 'feed'.'.rss'
), array('type' => 'rss'));

echo $this->Html->css(array('reset', '960', 'style'));
echo $this->Html->script('jquery');

echo $scripts_for_layout;
?>
</head>
<body>
<div class="container_12">
<div id="header" class="grid_12">
<h1><?php echo Configure::read('Visual.title') ?></h1>
</div>
<div class="clear"></div>
<div id="content" class="grid_12">
<div class="grid_2 alpha">
<?php
echo $paginator->sort(__('Sort by added', true), 'Item.added')."\n";
echo $paginator->sort(__('Sort by year of publication', true), 'Item.date')."\n";
?>
</div>
<div id="ajax" class="grid_10 omega">
<?php echo $this->Session->flash(); ?>

<?php echo $content_for_layout; ?>
</div>

</div>
<div class="clear"></div>
<div id="footer" class="grid_12">
</div>
<div class="clear"></div>
</div>
<?php echo $this->Js->writeBuffer(); ?>
</body>
</html>
9 changes: 8 additions & 1 deletion app/views/themed/default/settings/index.ctp
@@ -1,6 +1,13 @@
<div id="busy-indicator" style="display: none;">
<?php echo $this->Html->image('ajax.gif');?>
</div>
<h2><?php echo $title; ?></h2>
<?php
echo $this->Html->link(__('Update database', true), array('action' => 'xml'));
echo $this->Js->link(__('Update database', true), array('action' => 'xml'), array(
'update' => '#ajax',
'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
'success' => $this->Js->get('#busy-indicator')->effect('fadeOut', array('buffer' => false)),
'complete' => $this->Js->redirect(array('action' => 'index'))));
foreach ($languages as $language)
$options[$language] = languageCodes($language);

Expand Down
Binary file added app/views/themed/default/webroot/img/ajax.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c9acb97

Please sign in to comment.