4 // create containers for all ajaxable form links
5 $('.ajaxable').each(function() {
6 var $window = $("#ajaxable-window").clone();
7 $window.attr("id", this.id + "-window");
8 $('body').append($window);
10 var $trigger = $(this)
11 var trigger = '#' + this.id;
15 ajaxText: '<p><img src="' + STATIC_URL + 'img/indicator.gif" alt="*"/> ' + gettext("Loading") + '</p>',
16 target: $('.target', $window)[0],
19 onShow: function(hash) {
20 var offset = $(hash.t).offset();
21 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
22 var width = $(hash.t).width();
23 width = width > 50 ? width : 50;
24 $('.header', hash.w).css({width: width});
27 onLoad: function(hash) {
28 $('form', hash.w).ajaxForm({
30 target: $('.target', $window),
31 success: function(response) {
32 if (response.success) {
33 $('.target', $window).text(response.message);
34 setTimeout(function() { $window.jqmHide() }, 1000);
35 callback = ajaxable_callbacks[$trigger.attr('data-callback')];
36 callback && callback($trigger, response);
37 if (response.redirect)
38 window.location = response.redirect;
41 $('.error', $window).remove();
42 $.each(response.errors, function(id, errors) {
43 $('#id_' + id, $window).before('<span class="error">' + errors[0] + '</span>');
45 $('input[type=submit]', $window).removeAttr('disabled');
55 var login_and_retry = function($form) {
56 var $window = $("#ajaxable-window").clone();
57 $window.attr("id", "context-login-window");
58 $('body').append($window);
61 ajax: '/uzytkownicy/zaloguj-utworz/',
62 ajaxText: '<p><img src="' + STATIC_URL + 'img/indicator.gif" alt="*"/> ' + gettext("Loading") + '</p>',
63 target: $('.target', $window)[0],
65 onShow: function(hash) {
66 var offset = $form.offset();
67 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $form.width(), top: offset.top});
68 var width = $form.width();
69 width = width > 50 ? width : 50;
70 $('.header', hash.w).css({width: width});
73 onLoad: function(hash) {
74 $('form', hash.w).ajaxForm({
76 target: $('.target', $window),
77 success: function(response) {
78 if (response.success) {
79 $('.target', $window).text(response.message);
80 setTimeout(function() { $window.jqmHide() }, 1000);
84 $('.error', $window).remove();
85 $.each(response.errors, function(id, errors) {
86 $('#id_' + id, $window).before('<span class="error">' + errors[0] + '</span>');
88 $('input[type=submit]', $window).removeAttr('disabled');
99 $('.ajax-form').each(function() {
103 beforeSubmit: function() {
104 $('input[type=submit]', $form)
105 .attr('disabled', 'disabled')
106 .after('<img src="/static/img/indicator.gif" style="margin-left: 0.5em"/>');
108 error: function(response) {
109 if (response.status == 403)
110 login_and_retry($form);
112 success: function(response) {
113 if (response.success) {
114 callback = ajax_form_callbacks[$form.attr('data-callback')];
115 callback && callback($form, response);
118 $('span.error', $form).remove();
119 $.each(response.errors, function(id, errors) {
120 $('#id_' + id, $form).before('<span class="error">' + errors[0] + '</span>');
122 $('input[type=submit]', $form).removeAttr('disabled');
123 $('img', $form).remove();
130 var update_star = function($elem, response) {
131 /* updates the star after successful ajax */
132 var $star = $elem.closest('.star');
134 $star.addClass('like');
135 $star.removeClass('unlike');
138 $star.addClass('unlike');
139 $star.removeClass('like');
143 var ajax_form_callbacks = {
144 'social-like-book': update_star
147 var ajaxable_callbacks = {
148 'social-book-sets': update_star