summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-10-12 01:34:18 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-10-12 01:34:18 +0000
commit2a8cbedade6d2d7e7e71e5dbb8c562a84cfe6c80 (patch)
tree1c4b2060e96fcf4a92f0ab52dbe3894d3797bebd
parent80d226853c000229cdcd3690885aea2116f8e2cc (diff)
downloadampache-2a8cbedade6d2d7e7e71e5dbb8c562a84cfe6c80.tar.gz
ampache-2a8cbedade6d2d7e7e71e5dbb8c562a84cfe6c80.tar.bz2
ampache-2a8cbedade6d2d7e7e71e5dbb8c562a84cfe6c80.zip
new rating hotness, has some bugs will continue to hash them out
-rwxr-xr-xdocs/CHANGELOG2
-rw-r--r--index.php7
-rw-r--r--lib/init.php7
-rw-r--r--lib/ui.lib.php17
-rw-r--r--server/ajax.server.php11
-rw-r--r--templates/default.css28
-rw-r--r--templates/show_album.inc7
-rw-r--r--templates/show_object_rating.inc.php29
-rw-r--r--templates/show_songs.inc3
9 files changed, 79 insertions, 32 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 67dbe86c..232b93fa 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,8 @@
--------------------------------------------------------------------------
v.3.3.3-Alpha1
+ - Added ajax support to ratings, no longer requires a refresh,
+ hello instant gratification.
- Tweaked Kajax, now accepts an array of elements to replace
from a passed xml document. allows for multiple targets
on a single ajax request
diff --git a/index.php b/index.php
index 8688fffa..4a3cb667 100644
--- a/index.php
+++ b/index.php
@@ -44,12 +44,7 @@ if (conf('refresh_limit') > 5) {
require_once(conf('prefix') . '/templates/javascript_refresh.inc.php');
}
?>
-<script language="javascript" type="text/javascript">
-<!--
-var np_refresh = new Array(1);
-np_refresh[0] = "np_data";
--->
-</script>
+<?php show_ajax_js('np_refresh',array('np_data')); ?>
<div id="np_data">
<?php show_now_playing(); ?>
</div> <!-- Close Now Playing Div -->
diff --git a/lib/init.php b/lib/init.php
index f76f3eb6..e88da245 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -255,6 +255,13 @@ else {
$user = new user();
}
+
+/* Add in some variables for ajax done here because we need the user */
+$ajax_info['ajax_url'] = $results['web_path'] . '/server/ajax.server.php';
+$ajax_info['ajax_info'] = '&user_id=' . $user->id . '&sessid=' . session_id();
+conf($ajax_info);
+unset($ajax_info);
+
// Load gettext mojo
load_gettext();
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index 47b6cff9..1834dc35 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -1353,6 +1353,23 @@ function xml_from_array($array) {
} // xml_from_array
+/**
+ * show_ajax_js
+ * This displays the javascript array definition needed
+ * For ajax to know what it should be replacing
+ */
+function show_ajax_js($name,$array) {
+
+ $elements = count($array);
+
+ echo "<script type=\"text/javascript\" language=\"javascript\">\n";
+ echo "<!--\n";
+ echo "var $name = new Array($elements);\n";
+ foreach ($array as $key=>$value) {
+ echo $name . "[$key] = \"$value\";\n";
+ }
+ echo "-->\n</script>\n";
+} // show_ajax_js
?>
diff --git a/server/ajax.server.php b/server/ajax.server.php
index 76e78102..65fbc6dd 100644
--- a/server/ajax.server.php
+++ b/server/ajax.server.php
@@ -97,6 +97,17 @@ switch ($action) {
$xml_doc = xml_from_array($results);
echo $xml_doc;
break;
+ case 'set_rating':
+ ob_start();
+ $rating = new Rating($_REQUEST['object_id'],$_REQUEST['rating_type']);
+ $rating->set_rating($_REQUEST['rating']);
+ show_rating($_REQUEST['object_id'],$_REQUEST['rating_type']);
+ $key = "rating_" . $_REQUEST['object_id'] . "_" . $_REQUEST['rating_type'];
+ $results[$key] = ob_get_contents();
+ ob_end_clean();
+ $xml_doc = xml_from_array($results);
+ echo $xml_doc;
+ break;
default:
echo "Default Action";
break;
diff --git a/templates/default.css b/templates/default.css
index 12506f70..9594a02d 100644
--- a/templates/default.css
+++ b/templates/default.css
@@ -445,7 +445,7 @@ margin-right:5em;
margin:0px;
float: right;
}
-.star-rating li a{
+.star-rating li span{
display:block;
width:16px;
height: 15px;
@@ -455,51 +455,51 @@ margin-right:5em;
position: absolute;
padding: 0px;
}
-.star-rating li a:hover{
+.star-rating li span:hover{
background: url(../images/ratings/star_rating.gif) left center;
z-index: 2;
left: 0px;
}
-li.zero-stars a:hover {
+li.zero-stars span:hover {
background: url(../images/ratings/x.gif);
height: 15px;
left: 80px;
display: block;
}
-a.zero-stars {
+span.zero-stars {
background: url(../images/ratings/x_off.gif);
height: 15px;
left: 80px;
display: block;
}
-a.one-stars{
+span.one-stars{
left: 0px;
}
-a.one-stars:hover{
+span.one-stars:hover{
width:16px;
}
-a.two-stars{
+span.two-stars{
left:16px;
}
-a.two-stars:hover{
+span.two-stars:hover{
width: 32px;
}
-a.three-stars{
+span.three-stars{
left: 32px;
}
-a.three-stars:hover{
+span.three-stars:hover{
width: 48px;
}
-a.four-stars{
+span.four-stars{
left: 48px;
}
-a.four-stars:hover{
+span.four-stars:hover{
width: 64px;
}
-a.five-stars{
+span.five-stars{
left: 64px;
}
-a.five-stars:hover{
+span.five-stars:hover{
width: 80px;
}
li.current-rating{
diff --git a/templates/show_album.inc b/templates/show_album.inc
index e2ef6838..5fc28300 100644
--- a/templates/show_album.inc
+++ b/templates/show_album.inc
@@ -27,7 +27,6 @@ $web_path = conf('web_path');
// Build array of the table classes we are using
$row_classes = array('even','odd');
-// Generate variables for the flash ratings
//FIXME:
$album_id = $album->id;
$artist_id = $album->artist_id;
@@ -47,7 +46,11 @@ $title = scrub_out($album->name) . ' -- ' . $album->f_artist;
</div>
<div style="display:table-cell;vertical-align:top;">
<?php
- if (conf('ratings')) { show_rating($album->id, 'album');} // end if ratings
+ if (conf('ratings')) {
+ show_ajax_js("r_" . $album->id . "_album",array("rating_" . $album->id . "_album"));
+ echo "<span style=\"display:inline;\" id=\"rating_" . $album->id . "_album\">";
+ show_rating($album->id, 'album');} // end if ratings
+ echo "</span>";
echo "<br />\n";
?>
<strong><?php echo _('Actions'); ?>:</strong><br />
diff --git a/templates/show_object_rating.inc.php b/templates/show_object_rating.inc.php
index 1a0cfb8e..afd6d056 100644
--- a/templates/show_object_rating.inc.php
+++ b/templates/show_object_rating.inc.php
@@ -21,17 +21,18 @@
/* Create some variables we are going to need */
$web_path = conf('web_path');
-$base_url = $web_path . '/ratings.php?action=set_rating&amp;mode=' . conf('flash') . '&amp;rating_type=' . $rating->type . '&amp;object_id=' . $rating->id . '&amp;username=' . $GLOBALS['user']->username;
+$base_url = conf('ajax_url') . '?action=set_rating&rating_type=' . $rating->type . '&object_id=' . $rating->id . conf('ajax_info');
+
//set the background to no stars
echo "<ul class=\"star-rating\">\n";
/* Handle the "Not rated" possibility */
if ($rating->rating == '-1') {
- echo "<li class=\"zero-stars\"><a href=\"" . $base_url . "&amp;rating=-1\" title=\"don't play\" class=\"zero-stars\">-1</a></li>\n";
+ echo "<li class=\"zero-stars\"><span onclick=\"ajaxPut('" . $base_url . "&rating=-1',r_" . $rating->id . "_" . $rating->type . ");return true;\" title=\"don't play\" class=\"zero-stars\"></span></li>\n";
}
else {
- echo "<li class=\"zero-stars\"><a href=\"" . $base_url . "&amp;rating=-1\" title=\"remove rating\" class=\"zero-stars\">-1</a></li>\n";
+ echo "<li class=\"zero-stars\"><span onclick=\"ajaxPut('" . $base_url . "&rating=-1',r_" . $rating->id . "_" . $rating->type . ");return true;\" title=\"remove rating\" class=\"zero-stars\"></span></li>\n";
}
// decide width of rating. image is 16 px wide
$width = $rating->rating*16;
@@ -45,11 +46,21 @@ if ($rating->rating <= 0) {
else echo "$rating->rating of 5</li>\n";
//it did not like my "1-star", "2-star" ... css styles, and I changed it to this after I realized star1... would have worked :\
-echo "<li> <a href=\"" . $base_url . "&amp;rating=1\" class=\"one-stars\" title=\"1 out of 5\">$score</a></li>\n";
-echo "<li> <a href=\"" . $base_url . "&amp;rating=2\" class=\"two-stars\" title=\"2 out of 5\">$score</a></li>\n";
-echo "<li> <a href=\"" . $base_url . "&amp;rating=3\" class=\"three-stars\" title=\"3 out of 5\">$score</a></li>\n";
-echo "<li> <a href=\"" . $base_url . "&amp;rating=4\" class=\"four-stars\" title=\"4 out of 5\">$score</a></li>\n";
-echo "<li> <a href=\"" . $base_url . "&amp;rating=5\" class=\"five-stars\" title=\"5 out of 5\">$score</a></li>\n";
-echo "</ul>";
?>
+<li>
+ <span onclick="ajaxPut('<?php echo $base_url; ?>&rating=1',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="one-stars" title="1 <?php echo _('out of'); ?> 5"></span>
+</li>
+<li>
+ <span onclick="ajaxPut('<?php echo $base_url; ?>&rating=2',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="two-stars" title="2 <?php echo _('out of'); ?> 5"></span>
+</li>
+<li>
+ <span onclick="ajaxPut('<?php echo $base_url; ?>&rating=3',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="three-stars" title="3 <?php echo _('out of'); ?> 5"></span>
+</li>
+<li>
+ <span onclick="ajaxPut('<?php echo $base_url; ?>&rating=4',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="four-stars" title="4 <?php echo _('out of'); ?> 5"></span>
+</li>
+<li>
+ <span onclick="ajaxPut('<?php echo $base_url; ?>&rating=5',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="five-stars" title="5 <?php echo _('out of'); ?> 5"></span>
+</li>
+</ul>
diff --git a/templates/show_songs.inc b/templates/show_songs.inc
index c8dbcc7c..be8f179c 100644
--- a/templates/show_songs.inc
+++ b/templates/show_songs.inc
@@ -145,7 +145,8 @@ foreach ($song_ids as $song_id) {
<?php } ?>
</td>
<?php if(conf('ratings')) { ?>
- <td>
+ <td id="rating_<?php echo $song->id; ?>_song">
+ <?php show_ajax_js("r_" . $song->id . "_song",array("rating_" . $song->id . "_song")); ?>
<?php show_rating($song->id,'song'); ?>
</td>
<?php } ?>