From 3add1fa00f1fd208ca5f8ea798af7141bbbb43bf Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Mon, 17 Jun 2013 19:44:47 +0100 Subject: [PATCH] Fixed play count dialog --- spa/templates.py | 13 ++++--- spa/urls.py | 1 + static/js/app/lib/audioController.coffee | 8 ++-- static/js/app/lib/audioController.js | 6 +-- static/js/app/lib/utils.coffee | 31 ++++++++++----- static/js/app/lib/utils.js | 38 +++++++++++++------ .../views/{ => dlg}/PlayCountLoginAlert.html | 14 +++---- templates/views/dlg/_DialogBase.html | 15 ++++++++ 8 files changed, 85 insertions(+), 41 deletions(-) rename templates/views/{ => dlg}/PlayCountLoginAlert.html (64%) create mode 100644 templates/views/dlg/_DialogBase.html diff --git a/spa/templates.py b/spa/templates.py index 54f2dab..d0580af 100644 --- a/spa/templates.py +++ b/spa/templates.py @@ -10,12 +10,6 @@ __author__ = 'fergalm' @not_minified_response def get_template(request, template_name): - #Temporary hack here to create user profiles for zombie users - if request.user.is_authenticated() and request.user.get_profile() is None: - zm, created = UserProfile.objects.get_or_create(user=request.user) - zm.save() - print "Created user %s" % zm - return render_to_response( 'views/%s.html' % template_name, context_instance=RequestContext(request)) @@ -29,6 +23,13 @@ def get_template_ex(request, template_name): return html +@not_minified_response +def get_dialog(request, dialog_name): + return render_to_response( + 'views/dlg/%s.html' % dialog_name, + context_instance=RequestContext(request)) + + def get_javascript(request, template_name): localsettings.JS_SETTINGS.update({ 'CURRENT_USER_ID': request.user.id or -1 diff --git a/spa/urls.py b/spa/urls.py index 922e3db..a4d16fd 100644 --- a/spa/urls.py +++ b/spa/urls.py @@ -27,6 +27,7 @@ urlpatterns = patterns( '', url(r'^$', 'spa.views.app', name='home'), url(r'^tpl/(?P\w+)/$', 'spa.templates.get_template'), + url(r'^dlg/(?P\w+)/$', 'spa.templates.get_dialog'), url(r'^js/(?P\w+)/$', 'spa.templates.get_javascript'), url(r'^tplex/(?P\w+)/$', 'spa.templates.get_template_ex'), url(r'^podcast\.xml', 'spa.podcast.get_default_podcast'), diff --git a/static/js/app/lib/audioController.coffee b/static/js/app/lib/audioController.coffee index 0134537..6600ac5 100644 --- a/static/js/app/lib/audioController.coffee +++ b/static/js/app/lib/audioController.coffee @@ -1,5 +1,5 @@ -define ['app', 'marionette', 'vent'], -(App, Marionette, vent) -> +define ['app', 'marionette', 'vent', 'utils'], +(App, Marionette, vent, utils) -> class AudioController extends Marionette.Controller initialize: (options) -> @@ -16,10 +16,10 @@ define ['app', 'marionette', 'vent'], com.podnoms.player.startPlaying success: => vent.trigger("mix:play", model) - com.podnoms.utils.checkPlayCount() + utils.checkPlayCount() return error: => - com.podnoms.utils.showWarning "Ooops", "Error playing mix. If you have a flash blocker, please disable it for this site. Otherwise, do please try again." + utils.showWarning "Ooops", "Error playing mix. If you have a flash blocker, please disable it for this site. Otherwise, do please try again." return com.podnoms.storage.setItem "now_playing", id return diff --git a/static/js/app/lib/audioController.js b/static/js/app/lib/audioController.js index ff56d5e..7ea0c2c 100644 --- a/static/js/app/lib/audioController.js +++ b/static/js/app/lib/audioController.js @@ -4,7 +4,7 @@ __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - define(['app', 'marionette', 'vent'], function(App, Marionette, vent) { + define(['app', 'marionette', 'vent', 'utils'], function(App, Marionette, vent, utils) { var AudioController; AudioController = (function(_super) { @@ -32,10 +32,10 @@ com.podnoms.player.startPlaying({ success: function() { vent.trigger("mix:play", model); - com.podnoms.utils.checkPlayCount(); + utils.checkPlayCount(); }, error: function() { - com.podnoms.utils.showWarning("Ooops", "Error playing mix. If you have a flash blocker, please disable it for this site. Otherwise, do please try again."); + utils.showWarning("Ooops", "Error playing mix. If you have a flash blocker, please disable it for this site. Otherwise, do please try again."); } }); com.podnoms.storage.setItem("now_playing", id); diff --git a/static/js/app/lib/utils.coffee b/static/js/app/lib/utils.coffee index 6442878..928d2b2 100644 --- a/static/js/app/lib/utils.coffee +++ b/static/js/app/lib/utils.coffee @@ -1,19 +1,30 @@ -define ['jquery', 'bootstrap'], ($, bootstrap) -> - modal: (url) -> +define ['jquery', 'bootstrap', 'toastr'], ($, bootstrap, toastr) -> + modal: (url) -> + if url if url.indexOf("#") is 0 $(url).modal "open" else $.get(url,(data) -> - $("
" + data + "
").modal().on "hidden", -> + $(data).modal().on "hidden", -> $(this).remove() - + true ).success -> $("input:text:visible:first").focus() - true + true + true - checkPlayCount: -> - if document.cookie.indexOf("sessionId") - $.getJSON "/ajax/session_play_count", (data) -> - com.podnoms.utils.modal "tpl/PlayCountLoginAlert" if (data.play_count isnt 0) and (data.play_count % 1) is 0 - true + checkPlayCount: -> + if document.cookie.indexOf("sessionId") + $.getJSON "/ajax/session_play_count", (data) => + console.log "utils: got playcount" + @modal "dlg/PlayCountLoginAlert" if (data.play_count isnt 0) and (data.play_count % 1) is 0 + true + showError: (title, message) => + toastr.error message, title + + showWarning: (title, message) => + toastr.warning message, title + + showAlert: (title, message) => + toastr.success message, title \ No newline at end of file diff --git a/static/js/app/lib/utils.js b/static/js/app/lib/utils.js index bd75cdd..5a3759d 100644 --- a/static/js/app/lib/utils.js +++ b/static/js/app/lib/utils.js @@ -1,31 +1,47 @@ // Generated by CoffeeScript 1.3.3 (function() { - define(['jquery', 'bootstrap'], function($, bootstrap) { + define(['jquery', 'bootstrap', 'toastr'], function($, bootstrap, toastr) { + var _this = this; return { modal: function(url) { - if (url.indexOf("#") === 0) { - $(url).modal("open"); - } else { - $.get(url, function(data) { - return $("
" + data + "
").modal().on("hidden", function() { - return $(this).remove(); + if (url) { + if (url.indexOf("#") === 0) { + $(url).modal("open"); + } else { + $.get(url, function(data) { + return $(data).modal().on("hidden", function() { + $(this).remove(); + return true; + }); + }).success(function() { + $("input:text:visible:first").focus(); + return true; }); - }).success(function() { - return $("input:text:visible:first").focus(); - }); + } } return true; }, checkPlayCount: function() { + var _this = this; if (document.cookie.indexOf("sessionId")) { $.getJSON("/ajax/session_play_count", function(data) { + console.log("utils: got playcount"); if ((data.play_count !== 0) && (data.play_count % 1) === 0) { - return com.podnoms.utils.modal("tpl/PlayCountLoginAlert"); + return _this.modal("dlg/PlayCountLoginAlert"); } }); } return true; + }, + showError: function(title, message) { + return toastr.error(message, title); + }, + showWarning: function(title, message) { + return toastr.warning(message, title); + }, + showAlert: function(title, message) { + return toastr.success(message, title); } }; }); diff --git a/templates/views/PlayCountLoginAlert.html b/templates/views/dlg/PlayCountLoginAlert.html similarity index 64% rename from templates/views/PlayCountLoginAlert.html rename to templates/views/dlg/PlayCountLoginAlert.html index c6f2521..1a0b022 100644 --- a/templates/views/PlayCountLoginAlert.html +++ b/templates/views/dlg/PlayCountLoginAlert.html @@ -1,14 +1,14 @@ +{% extends 'views/dlg/_DialogBase.html' %} + {% load account %} {% load socialaccount %} - - - - +{% endblock %} +{% block primarybutton %}Okies...{% endblock %} \ No newline at end of file diff --git a/templates/views/dlg/_DialogBase.html b/templates/views/dlg/_DialogBase.html new file mode 100644 index 0000000..507ad9b --- /dev/null +++ b/templates/views/dlg/_DialogBase.html @@ -0,0 +1,15 @@ +