Skip to content

Commit

Permalink
Updating alpha controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick committed Nov 1, 2010
1 parent 60c4c61 commit 212b32e
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 23 deletions.
5 changes: 5 additions & 0 deletions configs/widgets.yaml
Expand Up @@ -7,3 +7,8 @@ header:
acl:
- auth: guest

footer:
- name: add_song
acl:
- auth: user

36 changes: 36 additions & 0 deletions controllers/api/songs_api_controller.py
@@ -0,0 +1,36 @@

from google.appengine.api import users

from lib.djama import action

from models.songs import Song

class add_song(action):
def get(self):
self._print('eee')
def post(self):
if not users.get_current_user():
self._print('{"status":"0", "message":"Not logged"}')

errors = False
params = {}
for field in ['song_name', 'author_name', 'album_name', 'album_year', 'song_uri']:
if self.request.params.get(field):
params[field] = self.request.params.get(field)
else:
errors = True

if not errors:
song = Song()
song.owner = users.get_current_user()
song.uri = params['song_uri']
song.name = params['song_name']
song.author = params['author_name']
song.album = params['album_name']
song.albumYear = params['album_year']
song.status = True;
song.put()

self._print('{"status":"1", "message":"Added successully"}')
else:
self._print('{"status":"0", "message":"Not all fields are filled"}')
3 changes: 2 additions & 1 deletion main.py
Expand Up @@ -24,7 +24,7 @@
from controllers import indexController

# Api controllers
from controllers.api import index_api_controller, playlist_api_controller
from controllers.api import index_api_controller, playlist_api_controller, songs_api_controller

class Json(webapp.RequestHandler):
def get(self):
Expand All @@ -40,6 +40,7 @@ def get(self):
('/add/album', indexController.addAlbumAction),
('/api/songs/main.json',index_api_controller.index),
('/api/songs/my.json',index_api_controller.my),
('/api/songs/add_song.json', songs_api_controller.add_song),
(r'/api/songs/author/(.*)\.json', index_api_controller.author),
('/api/playlist/add_to_my.json', playlist_api_controller.add),
('/api/playlist/remove_from_my.json', playlist_api_controller.remove_from_my),
Expand Down
5 changes: 5 additions & 0 deletions static/css/alpha/index.css
@@ -0,0 +1,5 @@

.bold {
font-weight:bold;
}

15 changes: 15 additions & 0 deletions static/css/widgets/footer/add_song.css
@@ -0,0 +1,15 @@

#add_song {
position:absolute;
top:50px;
left:50%;
width:500px;
margin-left:-250px;
display:none;
}

#add_song input {
border:1px solid #000;
background:#F1FFDE;
}

37 changes: 19 additions & 18 deletions static/js/player/player.js
Expand Up @@ -22,13 +22,6 @@ Player.onUpdate = function() {
//this.duration;
//this.bytesPercent;


this._p = document.getElementById("pos");
this._b = document.getElementById("bits");
var _percent = this.position / (this.duration / 100);
this._p.innerHTML = this.position + '/' + this.duration + '|' + _percent;
this._b.innerHTML = this.bytesLoaded + "/" + this.bytesTotal + " (" + this.bytesPercent + "%)";

//progressSlider.setValue(_percent);
if (this.bytesPercent == 100) {
var onePercent = this.duration/100;
Expand All @@ -37,6 +30,14 @@ Player.onUpdate = function() {
}
}

/*
this._p = document.getElementById("pos");
this._b = document.getElementById("bits");
var _percent = this.position / (this.duration / 100);
this._p.innerHTML = this.position + '/' + this.duration + '|' + _percent;
this._b.innerHTML = this.bytesLoaded + "/" + this.bytesTotal + " (" + this.bytesPercent + "%)";
// Filled bar {
if (undefined != document.getElementById('filled')) {
var filled = document.getElementById('filled');
Expand All @@ -49,13 +50,13 @@ Player.onUpdate = function() {
var dfilled = document.getElementById('downloadFilled');
dfilled.style.width = 7.5 * parseInt(this.bytesPercent);
}
// }
// }*/

if (this.isPlaying) {
/*if (this.isPlaying) {
document.getElementById('nowName').innerHTML = this._formatName(this.songs[this.nowPlaying]);
document.getElementById('downloadIt').style.display = 'inline';
document.getElementById('downloadIt').href = this.songs[this.nowPlaying].uri;
}
}*/

// IDv3 {
if (this.isPlaying) {
Expand All @@ -75,7 +76,6 @@ Player.play = function(id) {
var _uri = 'http://www.ex.ua/get/450580';

if (this.uri != '' && id == undefined) {
console.log('Resume');
id = this.nowPlaying;
} else {
if (undefined == this.songs[id]) {
Expand All @@ -93,9 +93,9 @@ Player.play = function(id) {
this.flash.SetVariable("enabled", "true");

// Setting Volume
if (undefined != volumeSlider) {
/*if (undefined != volumeSlider) {
this.setVolume(volumeSlider.value);
}
}*/

for (var d in ols) {
dojo.removeClass(ols[d],'bold');
Expand Down Expand Up @@ -126,7 +126,8 @@ Player.load = function() {
handleAs:"json",
load: function(data){
console.log('Loading complete');
var list = document.getElementById('playlist');
var list = dojo.byId('playlist');
list.innerHTML = '';
for(var i in data['songs']){
ols[i] = document.createElement('li');
ols[i].ids = i;
Expand All @@ -139,9 +140,9 @@ Player.load = function() {
}
Player.songs = data['songs'];

var loading = document.getElementById('loading');
var loading = dojo.byId('loading');
loading.style.display = 'none';
var loadingShadow = document.getElementById('loadingShadow');
var loadingShadow = dojo.byId('loading_shadow');
loadingShadow.style.display = 'none';
}
});
Expand Down Expand Up @@ -173,7 +174,7 @@ Player._formatName = function(song, includeDownload) {
temp += song.name;
temp += ' (' + song.albumName + ')';

if (undefined != includeDownload) {
/*if (undefined != includeDownload) {
temp += '<a href="' + song.uri + '" target="_blank">';
temp += '<img src="/static/images/icons/';
temp += Theme.color
Expand All @@ -185,7 +186,7 @@ Player._formatName = function(song, includeDownload) {
if (isUser && window.location.hash != '#my') {
temp += '<a href="javascript:void(0);" onclick="Player.addToMy(\'' + song.uri + '\');">'
temp += '<img src="/static/images/icons/building_go.png" /></a>';
}
}*/

return temp;
}
Expand Down
47 changes: 47 additions & 0 deletions static/js/widgets/footer/add_song.js
@@ -0,0 +1,47 @@

function add_song(action) {
var errors = false;
dojo.forEach(['song_name', 'author_name', 'album_name', 'album_year', 'song_uri'], function(item){
var _item = dojo.byId(item);

_item.style.backgroundColor = '#F1FFDE';
if (_item.value == '') {
errors = true;
_item.style.backgroundColor = '#FFDEDE';
}
});

if (!errors) {
dojo.xhrPost({
form: dojo.byId("add_song_form"),
handleAs: "json",
load: function(data) {
if (data.status == 1) {
console.log(data.message);
if (action == 'close') {
add_song_close();
} else {
dojo.byId('song_name').value = '';
dojo.byId('song_uri').value = '';
}
} else {
alert(data.message);
}
},
error: function(error) {
console.log('error, crap!');
}
});
}
}

function add_song_close() {
var add_song_window = dojo.byId('add_song');
add_song_window.style.display = 'none';
Player.load();
}

function add_song_show() {
var add_song_window = dojo.byId('add_song');
add_song_window.style.display = 'block';
}
17 changes: 17 additions & 0 deletions templates/_widgets/footer/add_song.tpl
@@ -0,0 +1,17 @@
<a href="javascript:void(0);" onclick="add_song_show();">Add new Song</a>
<div id="add_song">
<form action="/api/songs/add_song.json" method="post" id="add_song_form">
<b>Add Song:</b><br />
<label for="song_name">Song Name: </label><input type="text" id="song_name" name="song_name"><br />
<label for="author_name">Author Name: </label><input type="text" id="author_name" name="author_name"><br />
<label for="album_name">Album Name: </label><input type="text" id="album_name" name="album_name"><br />
<label for="album_yeaar">Album Year: </label><input type="text" id="album_year" name="album_year"><br />
<label for="song_uri">Song Uri: </label><input type="text" id="song_uri" name="song_uri"><br />
<a href="javascript:void(0);" onclick="add_song('close');">Submit</a> |
<a href="javascript:void(0);" onclick="add_song('another');">Submit and add more</a> |
<a href="javascript:void(0);" onclick="add_song_close();">Cancel</a>
</form>
</div>

<script type="text/javascript" src="/static/js/widgets/footer/add_song.js"></script>
<link rel="stylesheet" href="/static/css/widgets/footer/add_song.css" type="text/css" />
4 changes: 4 additions & 0 deletions templates/_widgets/header/logged.tpl
@@ -0,0 +1,4 @@
<div>
Hey, {{ user }} | <a href="{{ url }}">Logout</a>
</div>

53 changes: 50 additions & 3 deletions templates/alpha/index.tpl
@@ -1,7 +1,54 @@
Heeey!

<html>
<head>
<title>Your music on pyDjama</title>
<script type="text/javascript">
var mainJsonUri = '/api/songs/main.json';
</script>
</head>
<body>
<object
class="playerpreview"
id="myFlash"
type="application/x-shockwave-flash"
data="/static/player_mp3_js.swf"
width="1"
height="1">

<param name="movie" value="/static/player_mp3_js.swf" />
<param name="AllowScriptAccess" value="always" />
<param name="FlashVars" value="listener=Player&amp;interval=500" />

</object>
{% if widgets.header %}
{% for widget in widgets.header %}
{{ widget }}
{% endfor %}
{% endif %}
{% endif %}

<div id="loading_shadow"></div>
<div id="loading">Loading</div>

<div id="player">
<div class="controls">
<ul>
<li><a href="javascript:void(0);" onclick="Player.playPrev();">Prev</a></li>
<li><a href="javascript:void(0);" onclick="Player.play();">Play</a></li>
<li><a href="javascript:void(0);" onclick="Player.pause();">Pause</a></li>
<li><a href="javascript:void(0);" onclick="Player.playNext();">Next</a></li>
<li><a href="javascript:void(0);" onclick="Player.stop();">Stop</a></li>
</ul>
</div>
</div>
<ul id="playlist">
</ul>

<link rel="stylesheet" href="/static/css/alpha/index.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" type="text/javascript"></script>
<script src="/static/js/player/player.js" type="text/javascript"></script>
{% if widgets.footer %}
{% for widget in widgets.footer %}
{{ widget }}
{% endfor %}
{% endif %}
</body>
</html>
6 changes: 6 additions & 0 deletions widgets/footer.py
@@ -0,0 +1,6 @@

from lib.djama import widget

class add_song(widget):
def pre_dispatch(self):
pass
3 changes: 2 additions & 1 deletion widgets/header.py
Expand Up @@ -5,7 +5,8 @@

class logged(widget):
def pre_dispatch(self):
print 'jaaa'
self.template_vals['user'] = users.get_current_user()
self.template_vals['url'] = users.create_logout_url('/')


class not_logged(widget):
Expand Down

0 comments on commit 212b32e

Please sign in to comment.