Skip to content

Instantly share code, notes, and snippets.

@cacheleocode
Created July 14, 2015 15:01
Show Gist options
  • Select an option

  • Save cacheleocode/84fee1d095d8e56d7bcc to your computer and use it in GitHub Desktop.

Select an option

Save cacheleocode/84fee1d095d8e56d7bcc to your computer and use it in GitHub Desktop.
raw user modal logic
var status = "";
// disabled
$(".rating_badge.disabled").on('click', function(e) {
$('#choice_modal').modal();
return false;
});
$(".rating_badge.disabled").popover({
placement : 'right',
html: true,
title: 'Nima-kai Favorites<a class="close" href="#">&times;</a>',
content: $("#nima_stars p").html(),
trigger: "manual"
})
.on("mouseenter", function() {
var _this = this;
$(this).popover("show");
$(".popover").on("mouseleave", function() {
$(_this).popover('hide');
});
}).on("mouseleave", function() {
var _this = this;
setTimeout(function() {
if (!$(".popover:hover").length) {
$(_this).popover("hide");
}
}, 300);
});
$(".rating_badge.disabled").click(function (e) {
e.stopPropagation();
});
$(document).click(function (e) {
if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
$(".rating_badge.disabled").popover('hide');
}
});
// voted
$(".rating_badge.voted").popover({
html: true,
title: 'Nima-kai Favorites<a class="close" href="#">&times;</a>',
content: $("#nima_stars p").html()
});
$(".rating_badge.voted").click(function (e) {
e.stopPropagation();
});
$(document).click(function (e) {
if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
$(".rating_badge.voted").popover('hide');
}
});
$(".rating_badge.voted").popover("show");
// all popovers
/*
$(".popover .close").on("click", function(e) {
e.preventDefault();
return false;
});
*/
/*
$(".rating_badge.voted").popover({
placement : 'right',
html: true,
content: $("#nima_stars").html(),
trigger: "manual",
title: 'Popover Title<a class="close" href="#");">&times;</a>'
});
*/
/*
$(".rating_badge.voted").on('click', function(e) {
$(".rating_badge.voted").popover("toggle");
return false;
});
*/
/*
$(".rating_badge.voted").on('show.bs.popover', function() {
$(document).click(function (e) {
if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
$(".rating_badge.voted").popover('hide');
}
});
});
*/
$('#login_modal').on('show.bs.modal', function (event) {
var modal = $(this);
modal.find('.form').load("{{ login_url }}?status=" + status, function() {
// title = modal.find('form').data("title");
// modal.find('.modal-title').text(title);
// modal.find(".btn-primary").show().text(title);
});
modal.find(".btn-primary").click(function(){
modal.find(".btn-primary").prop('disabled', true);
$.ajax({
type: "POST",
url: "{{ login_url }}",
data: modal.find('form').serialize(),
success: function(msg){
if ($(msg).find(".errorlist").length > 0) {
modal.find('.form').html(msg);
//modal.find('.messages').html("<p class=\"alert alert-danger\">All fields are required.</p>");
modal.find(".btn-primary").prop('disabled', false);
}
else {
//window.location.replace(window.location.href);
//location.reload();
$.ajax({
url: "{% url like content_type content_obj.id 1 %}",
success: function(msg){
console.debug(msg);
if (msg == "vote was forbidden") {
// location.reload();
console.debug("forbidden!");
}
else {
// window.location = "{% url like content_type content_obj.id 1 %}";
console.debug("should have worked");
location.reload();
}
},
error: function(msg){
// alert("failure");
}
});
// window.location = "{% url like content_type content_obj.id 1 %}";
// modal.modal('hide');
/*
title = $(msg).data("title");
modal.find('.modal-title').text(title);
modal.find('.messages').html(msg);
modal.find('.form form').remove();
modal.find(".btn-primary").hide();
*/
}
//modal('hide');
},
error: function(msg){
// modal.find('.modal-body').prepend(msg);
// alert("failure");
}
});
});
}); // show
$('#user_modal').on('show.bs.modal', function (event) {
// var button = $(event.relatedTarget); // Button that triggered the modal
// var recipient = button.data('whatever'); // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this);
// modal.find('.modal-title').text('New message to ' + recipient);
// modal.find('.modal-body input').val(recipient);
// $("#id_username").focus();
modal.find('.form').load("{{ register_url }}", function(e) {
// title = modal.find('form').data("title");
// modal.find('.modal-title').text(title);
modal.find('.messages').html("");
modal.find(".btn-primary").prop('disabled', false).show();
});
modal.find(".btn-primary").click(function(){
modal.find(".btn-primary").prop('disabled', true);
$.ajax({
type: "POST",
url: "{{ register_url }}",
data: modal.find('form').serialize(),
success: function(msg){
if ($(msg).find(".errorlist").length > 0) {
modal.find('.form').html(msg);
//modal.find('.messages').html("<p class=\"alert alert-danger\">All fields are required.</p>");
modal.find(".btn-primary").prop('disabled', false);
}
else {
modal.modal("hide");
status = "inactive";
$('#login_modal').modal();
/*
title = $(msg).data("title");
modal.find('.modal-title').text(title);
modal.find('.messages').html(msg);
modal.find('.form form').remove();
modal.find(".btn-primary").hide();
*/
}
//modal('hide');
},
error: function(msg){
// modal.find('.modal-body').prepend(msg);
// alert("failure");
}
});
});
}); // show
$('#choice_modal').on('show.bs.modal', function (event) {
var modal = $(this);
$.ajax({
type: "GET",
url: "{{ login_url }}",
data: "satus=" + status,
success: function(msg) {
modal.find('.login_form').html(msg);
}
});
$(document).on('submit', '#login_form', function(e){
$(this).find('input[type="submit"]').prop('disabled', true);
$.ajax({
type: "POST",
url: "{{ login_url }}",
data: $(this).serialize(),
success: function(msg){
console.debug(msg);
if ($(msg).find(".errorlist").length > 0) {
modal.find('.login_form').html(msg);
$(this).find('input[type="submit"]').prop('disabled', false);
}
else {
$.ajax({
url: "{% url like content_type content_obj.id 1 %}",
success: function(msg){
if (msg == "vote was forbidden") {
console.debug("forbidden!");
}
else {
location.reload();
}
}
});
}
} // success
}); // ajax
e.preventDefault();
}); // submit
$.ajax({
type: "GET",
url: "{{ register_url }}",
data: "satus=" + status,
success: function(msg) {
modal.find('.register_form').html(msg);
}
});
$(document).on('submit', '#register_form', function(e){
$(this).find('input[type="submit"]').prop('disabled', true);
$.ajax({
type: "POST",
url: "{{ register_url }}",
data: $(this).serialize(),
success: function(msg){
if ($(msg).find(".errorlist").length > 0) {
modal.find('.register_form').html(msg);
$(this).find('input[type="submit"]').prop('disabled', false);
}
else {
modal.find('.register_form').html(msg);
}
} // success
}); // ajax
e.preventDefault();
}); // submit
}); // #choice_modal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment