Commit 19daf23a authored by dj3c1t's avatar dj3c1t

source navigation et autoplay

parent 1daceac8
......@@ -265,4 +265,8 @@ ul.derivation_sources li {
.source_xml_view pre {
margin-top: 1em;
display: none;
}
\ No newline at end of file
}
.source_navigation {
padding-bottom: 2em;
}
......@@ -38,8 +38,11 @@
resize: function(){
jap.resize_audio_players();
}
},
play: function(audio_elt) {
jap.play(audio_elt);
}
};
// -----------------------------------------------------------------------
......
......@@ -91,6 +91,31 @@
<div class="source_view_content">
{% set previousAndNext = sourceml.getPreviousAndNext(source) %}
{% if previousAndNext['previous'] is not null or previousAndNext['next'] is not null %}
<nav class="col-md-12 source_navigation">
<div class="row prev_next">
{% if previousAndNext['previous'] is not null %}
<div class="col-md-6">
<a class="btn btn-default previous_source" href="{{ sourceml.getSourceUrl(previousAndNext['previous']) }}">
<i class="glyphicon glyphicon-backward"></i>
<span class="title">{{ previousAndNext['previous'].title }}</span>
</a>
</div>
{% endif %}
{% if previousAndNext['next'] is not null %}
<div class="col-md-6{% if previousAndNext['previous'] is null %} col-md-offset-6{% endif %} text-right">
<a class="btn btn-default next_source" href="{{ sourceml.getSourceUrl(previousAndNext['next']) }}">
<span class="title">{{ previousAndNext['next'].title }}</span>
<i class="glyphicon glyphicon-forward"></i>
</a>
</div>
{% endif %}
</div>
</nav>
{% endif %}
{% if source.image is not null %}
<div class="source_view_image">
<img src="{{ source.image.url }}" />
......
......@@ -160,6 +160,28 @@ $(document).ready(
}
);
{% if sourceml.getAutoplay() %}
var players = $("audio.jap");
if(players.length > 0) {
players.each(
function() {
$(this).bind(
'ended', function() {
if($("audio.jap").length == 1) {
var next_link = $("a.next_source");
if(next_link.length > 0) {
document.location.href = next_link.attr("href");
}
}
}
);
}
);
var firstPlayer = players.first();
firstPlayer.jaudioPlayer("play", firstPlayer);
}
{% endif %}
}
);
</script>
......
......@@ -31,7 +31,7 @@ class SourceMLMenus {
public function toggleAutoPlayNextTrackButton() {
return array(
"route" => "source_toggle_auto_play_next_track",
"label" => "Enchaîner les lectures",
"label" => "Lecture automatique",
"glyphicon" => "glyphicon-ok-circle",
"class" => "toggle_auto_play_next_track",
);
......
......@@ -153,6 +153,38 @@ class SourceManager {
return null;
}
public function getPreviousAndNext($source) {
$sources = array(
"previous" => null,
"next" => null,
);
if(($composition = $source->getComposition()) === null) {
return $sources;
}
$queryParams = array(
"sourceType" => $source->getSourceType()->getName(),
"composition" => $composition->getId(),
);
$found = false;
$previous = null;
foreach($this->getSourceQuery($queryParams)->getResult() as $_source) {
if(!$found) {
if($_source->getId() == $source->getId()) {
$found = true;
if(isset($previous)) {
$sources['previous'] = $previous;
}
}
}
else {
$sources['next'] = $_source;
break;
}
$previous = $_source;
}
return $sources;
}
public function getSourceSource(SourceComposition $source) {
$source_cache = $this->container->get('sourceml.source_cache');
try {
......@@ -203,11 +235,15 @@ class SourceManager {
return $base_url.$this->container->get('router')->generate(
'source_view',
array(
"source" => $source->getId()
"source" => $source->getId(),
)
);
}
public function getAutoplay() {
return $this->container->get('session')->get('auto_play_next_track', false);
}
public function setComposition(Source $source, Source $composition = null) {
$em = $this->container->get('doctrine')->getManager();
$found = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment