Просмотр исходного кода

correction marquage des articles en js

Marien Fressinaud 13 лет назад
Родитель
Сommit
d21c1bb138

+ 2 - 0
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');
 		}
 	}
 

+ 1 - 1
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 ();
 

+ 2 - 2
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);

+ 15 - 0
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 ('#&amp;#i', '&', $url)));

+ 15 - 0
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 ('#&amp;#i', '&', $url)));

+ 66 - 36
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);
-		}
-	});
 });

+ 6 - 2
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;
+		}
 	}
 	
 	/**