diff options
| author | 2012-10-25 15:42:06 +0200 | |
|---|---|---|
| committer | 2012-10-25 15:42:06 +0200 | |
| commit | d21c1bb13875189ab25f7bce4f05cc3fedaa4904 (patch) | |
| tree | 43bc5ca4c728756ac2fa7ede42b50885ae171300 | |
| parent | e5767a7fae6e1463727987e09f1c592a8a86577b (diff) | |
correction marquage des articles en js
| -rwxr-xr-x | app/controllers/entryController.php | 2 | ||||
| -rwxr-xr-x | app/models/Category.php | 2 | ||||
| -rw-r--r-- | app/models/Feed.php | 4 | ||||
| -rwxr-xr-x | app/views/entry/bookmark.phtml | 15 | ||||
| -rwxr-xr-x | app/views/entry/read.phtml | 15 | ||||
| -rw-r--r-- | app/views/javascript/main.phtml | 102 | ||||
| -rw-r--r-- | lib/Request.php | 8 |
7 files changed, 107 insertions, 41 deletions
diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php index f9275593f..3d9734ca9 100755 --- a/app/controllers/entryController.php +++ b/app/controllers/entryController.php @@ -11,6 +11,8 @@ class entryController extends ActionController { $ajax = Request::param ('ajax'); if (!$ajax) { Request::forward (array (), true); + } else { + Request::_param ('ajax'); } } diff --git a/app/models/Category.php b/app/models/Category.php index 1713f615c..6e2847b51 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -109,7 +109,7 @@ class CategoryDAO extends Model_pdo { } public function listCategories () { - $sql = 'SELECT * FROM category'; + $sql = 'SELECT * FROM category ORDER BY name'; $stm = $this->bd->prepare ($sql); $stm->execute (); diff --git a/app/models/Feed.php b/app/models/Feed.php index e1e8f6449..92a20eb80 100644 --- a/app/models/Feed.php +++ b/app/models/Feed.php @@ -160,7 +160,7 @@ class FeedDAO extends Model_pdo { } public function listFeeds () { - $sql = 'SELECT * FROM feed'; + $sql = 'SELECT * FROM feed ORDER BY name'; $stm = $this->bd->prepare ($sql); $stm->execute (); @@ -168,7 +168,7 @@ class FeedDAO extends Model_pdo { } public function listByCategory ($cat) { - $sql = 'SELECT * FROM feed WHERE category=?'; + $sql = 'SELECT * FROM feed WHERE category=? ORDER BY name'; $stm = $this->bd->prepare ($sql); $values = array ($cat); diff --git a/app/views/entry/bookmark.phtml b/app/views/entry/bookmark.phtml new file mode 100755 index 000000000..fe64bb2d8 --- /dev/null +++ b/app/views/entry/bookmark.phtml @@ -0,0 +1,15 @@ +<?php + +if (Request::param ('is_favorite')) { + Request::_param ('is_favorite', 0); +} else { + Request::_param ('is_favorite', 1); +} + +$url = Url::display (array ( + 'c' => Request::controllerName (), + 'a' => Request::actionName (), + 'params' => Request::params (), +)); + +echo json_encode (array ('url' => preg_replace ('#&#i', '&', $url))); diff --git a/app/views/entry/read.phtml b/app/views/entry/read.phtml new file mode 100755 index 000000000..4d0a84f45 --- /dev/null +++ b/app/views/entry/read.phtml @@ -0,0 +1,15 @@ +<?php + +if (Request::param ('is_read')) { + Request::_param ('is_read', 0); +} else { + Request::_param ('is_read', 1); +} + +$url = Url::display (array ( + 'c' => Request::controllerName (), + 'a' => Request::actionName (), + 'params' => Request::params (), +)); + +echo json_encode (array ('url' => preg_replace ('#&#i', '&', $url))); diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml index 1bdde5a8e..c801ba7d0 100644 --- a/app/views/javascript/main.phtml +++ b/app/views/javascript/main.phtml @@ -28,45 +28,85 @@ function slide (new_active, old_active) { } } +function mark_read (active) { + url = active.find ("a.read").attr ("href"); + + $.ajax ({ + type: 'POST', + url: url, + data : { ajax: true } + }).done (function (data) { + res = jQuery.parseJSON(data); + + active.find ("a.read").attr ("href", res.url); + if (active.hasClass ("not_read")) { + active.removeClass ("not_read"); + active.find ("a.read").html ("Marquer comme non lu"); + } else { + active.addClass ("not_read"); + active.find ("a.read").html ("J'ai fini de lire l'article"); + } + }); +} + +function mark_favorite (active) { + url = active.find ("a.bookmark").attr ("href"); + + $.ajax ({ + type: 'POST', + url: url, + data : { ajax: true } + }).done (function (data) { + res = jQuery.parseJSON(data); + + active.find ("a.bookmark").attr ("href", res.url); + if (active.hasClass ("favorite")) { + active.removeClass ("favorite"); + active.find ("a.bookmark").html ("Ajouter l'article à mes favoris"); + } else { + active.addClass ("favorite"); + active.find ("a.bookmark").html ("Retirer l'article de mes favoris"); + } + }); +} + $(document).ready (function () { if (hide_posts) { $(".post.flux .content").slideToggle (); } + + $(".post.flux").click (function () { + old_active = $(".post.flux.active"); + new_active = $(this); + + if (old_active[0] != new_active[0]) { + slide (new_active, old_active); + } + }); + + $(".post.flux a.read").click (function () { + active = $(this).parents (".post.flux"); + mark_read (active); + + return false; + }); + $(".post.flux a.bookmark").click (function () { + active = $(this).parents (".post.flux"); + mark_favorite (active); + + return false; + }); // Touches de manipulation shortcut.add("m", function () { // on marque comme lu ou non lu active = $(".post.flux.active"); - url = active.find ("a.read").attr ("href"); - - $.ajax ({ - type: 'POST', - url: url, - data : { ajax: true } - }).done (function () { - if (active.hasClass ("not_read")) { - active.removeClass ("not_read"); - } else { - active.addClass ("not_read"); - } - }); + mark_read (active); }); shortcut.add("f", function () { // on marque comme favori ou non favori active = $(".post.flux.active"); - url = active.find ("a.bookmark").attr ("href"); - - $.ajax ({ - type: 'POST', - url: url, - data : { ajax: true } - }).done (function () { - if (active.hasClass ("favorite")) { - active.removeClass ("favorite"); - } else { - active.addClass ("favorite"); - } - }); + mark_favorite (active); }); // Touches de navigation @@ -108,14 +148,4 @@ $(document).ready (function () { redirect (url); }); - - - $(".post.flux").click (function () { - old_active = $(".post.flux.active"); - new_active = $(this); - - if (old_active[0] != new_active[0]) { - slide (new_active, old_active); - } - }); }); diff --git a/lib/Request.php b/lib/Request.php index 75e2d33f8..4f06be1d8 100644 --- a/lib/Request.php +++ b/lib/Request.php @@ -59,8 +59,12 @@ class Request { self::$params = $params; } - public static function _param ($key, $value) { - self::$params[$key] = $value; + public static function _param ($key, $value = null) { + if (is_null ($value)) { + unset (self::$params[$key]); + } else { + self::$params[$key] = $value; + } } /** |
