From 212b32e6fe039bab6080cbede42aa4d542e357c5 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 1 Nov 2010 08:55:10 +0200 Subject: [PATCH] Updating alpha controller --- configs/widgets.yaml | 5 +++ controllers/api/songs_api_controller.py | 36 +++++++++++++++++ main.py | 3 +- static/css/alpha/index.css | 5 +++ static/css/widgets/footer/add_song.css | 15 +++++++ static/js/player/player.js | 37 ++++++++--------- static/js/widgets/footer/add_song.js | 47 ++++++++++++++++++++++ templates/_widgets/footer/add_song.tpl | 17 ++++++++ templates/_widgets/header/logged.tpl | 4 ++ templates/alpha/index.tpl | 53 +++++++++++++++++++++++-- widgets/footer.py | 6 +++ widgets/header.py | 3 +- 12 files changed, 208 insertions(+), 23 deletions(-) create mode 100644 controllers/api/songs_api_controller.py create mode 100644 static/css/alpha/index.css create mode 100644 static/css/widgets/footer/add_song.css create mode 100644 static/js/widgets/footer/add_song.js create mode 100644 templates/_widgets/footer/add_song.tpl create mode 100644 templates/_widgets/header/logged.tpl create mode 100644 widgets/footer.py diff --git a/configs/widgets.yaml b/configs/widgets.yaml index 6d36281..ea97b57 100644 --- a/configs/widgets.yaml +++ b/configs/widgets.yaml @@ -7,3 +7,8 @@ header: acl: - auth: guest +footer: + - name: add_song + acl: + - auth: user + diff --git a/controllers/api/songs_api_controller.py b/controllers/api/songs_api_controller.py new file mode 100644 index 0000000..518ecb2 --- /dev/null +++ b/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"}') \ No newline at end of file diff --git a/main.py b/main.py index e47299b..33c6e89 100755 --- a/main.py +++ b/main.py @@ -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): @@ -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), diff --git a/static/css/alpha/index.css b/static/css/alpha/index.css new file mode 100644 index 0000000..f07db3c --- /dev/null +++ b/static/css/alpha/index.css @@ -0,0 +1,5 @@ + +.bold { + font-weight:bold; +} + diff --git a/static/css/widgets/footer/add_song.css b/static/css/widgets/footer/add_song.css new file mode 100644 index 0000000..7cacecd --- /dev/null +++ b/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; +} + diff --git a/static/js/player/player.js b/static/js/player/player.js index 05e719a..f245f78 100644 --- a/static/js/player/player.js +++ b/static/js/player/player.js @@ -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; @@ -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'); @@ -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) { @@ -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]) { @@ -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'); @@ -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; @@ -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'; } }); @@ -173,7 +174,7 @@ Player._formatName = function(song, includeDownload) { temp += song.name; temp += ' (' + song.albumName + ')'; - if (undefined != includeDownload) { + /*if (undefined != includeDownload) { temp += ''; temp += '' temp += ''; - } + }*/ return temp; } diff --git a/static/js/widgets/footer/add_song.js b/static/js/widgets/footer/add_song.js new file mode 100644 index 0000000..2c3270d --- /dev/null +++ b/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'; +} diff --git a/templates/_widgets/footer/add_song.tpl b/templates/_widgets/footer/add_song.tpl new file mode 100644 index 0000000..6f6e95e --- /dev/null +++ b/templates/_widgets/footer/add_song.tpl @@ -0,0 +1,17 @@ +Add new Song +
+
+ Add Song:
+
+
+
+
+
+ Submit | + Submit and add more | + Cancel +
+
+ + + diff --git a/templates/_widgets/header/logged.tpl b/templates/_widgets/header/logged.tpl new file mode 100644 index 0000000..bcde04b --- /dev/null +++ b/templates/_widgets/header/logged.tpl @@ -0,0 +1,4 @@ +
+ Hey, {{ user }} | Logout +
+ diff --git a/templates/alpha/index.tpl b/templates/alpha/index.tpl index 6e79c93..b5dee94 100644 --- a/templates/alpha/index.tpl +++ b/templates/alpha/index.tpl @@ -1,7 +1,54 @@ -Heeey! - + + + Your music on pyDjama + + + + + + + + + + {% if widgets.header %} {% for widget in widgets.header %} {{ widget }} {% endfor %} -{% endif %} \ No newline at end of file +{% endif %} + +
+
Loading
+ +
+
+ +
+
+ + + + + +{% if widgets.footer %} + {% for widget in widgets.footer %} + {{ widget }} + {% endfor %} +{% endif %} + + \ No newline at end of file diff --git a/widgets/footer.py b/widgets/footer.py new file mode 100644 index 0000000..698eeeb --- /dev/null +++ b/widgets/footer.py @@ -0,0 +1,6 @@ + +from lib.djama import widget + +class add_song(widget): + def pre_dispatch(self): + pass diff --git a/widgets/header.py b/widgets/header.py index 4bd5416..2bd938f 100644 --- a/widgets/header.py +++ b/widgets/header.py @@ -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):