Fixed play count dialog

This commit is contained in:
Fergal Moran
2013-06-17 19:44:47 +01:00
parent 24f2dab9a7
commit 3add1fa00f
8 changed files with 85 additions and 41 deletions

View File

@@ -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

View File

@@ -27,6 +27,7 @@ urlpatterns = patterns(
'',
url(r'^$', 'spa.views.app', name='home'),
url(r'^tpl/(?P<template_name>\w+)/$', 'spa.templates.get_template'),
url(r'^dlg/(?P<dialog_name>\w+)/$', 'spa.templates.get_dialog'),
url(r'^js/(?P<template_name>\w+)/$', 'spa.templates.get_javascript'),
url(r'^tplex/(?P<template_name>\w+)/$', 'spa.templates.get_template_ex'),
url(r'^podcast\.xml', 'spa.podcast.get_default_podcast'),

View File

@@ -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

View File

@@ -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);

View File

@@ -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) ->
$("<div class=\"modal hide fade\">" + data + "</div>").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

View File

@@ -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 $("<div class=\"modal hide fade\">" + data + "</div>").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);
}
};
});

View File

@@ -1,14 +1,14 @@
{% extends 'views/dlg/_DialogBase.html' %}
{% load account %}
{% load socialaccount %}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
{% block header %}
<h3>Hey There!!</h3>
</div>
<div class="modal-body">
{% endblock %}
{% block content %}
We've noticed you've been playing a few mixes now.<br/>
This is cool and we're happy you're enjoying the site but we would love it<br/>
if you would consider logging in.<br/>
This will let you comment on mixes and even download them
</div>
{% endblock %}
{% block primarybutton %}Okies...{% endblock %}

View File

@@ -0,0 +1,15 @@
<div class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
{% block header %}
{% endblock %}
</div>
<div class="modal-body">
{% block content %}
{% endblock %}
</div>
<div class="modal-footer">
{% block extrabuttons %}{% endblock %}
<a href="#" data-dismiss="modal" aria-hidden="true" class="btn btn-primary">{% block primarybutton %}{% endblock %}</a>
</div>
</div>