Added overwrite option to genslugs.py.
[wolnelektury.git] / wolnelektury / media / js / catalogue.js
1 (function($) {
2     $(function() {
3         $('form input').labelify({labelledClass: 'blur'});
4         
5         target = $('#login-register-window div.target');
6         
7         $('#show-registration-form').click(function() {
8             $('#login-form').hide();
9             $('#registration-form').show();
10         });
11         
12         $('#show-login-form').click(function() {
13             $('#registration-form').hide();
14             $('#login-form').show();
15         });
16         
17         // Fragments
18         $('.fragment-text').each(function() {
19             if ($(this).prev().filter('.fragment-short-text').length) {
20                 $(this).hover(
21                     function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
22                     function() { $(this).css({background: '#FFF'}); }
23                 ).click(function() {
24                     $(this).fadeOut(function() {
25                         $(this).prev().fadeIn()
26                     });
27                 })
28             }
29         });
30         
31         $('.fragment-short-text').click(function() {
32             $(this).fadeOut(function() { $(this).next().fadeIn() });
33         }).hover(
34             function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
35             function() { $(this).css({background: '#FFF'}); }
36         );
37         
38         $('.show-all-tags').click(function() {
39             $(this).parent().parent().fadeOut(function() { 
40                 $(this).next().fadeIn();
41             });
42             return false;
43         });
44         
45         
46         
47         $('#registration-form').ajaxForm({
48             dataType: 'json',
49             beforeSubmit: function() {
50                 $('#registration-form input[type=submit]')
51                     .attr('disabled', 'disabled')
52                     .after('<img src="/media/img/indicator.gif" style="margin-left: 0.5em"/>');
53             },
54             success: function(response) {
55                 if (response.success) {
56                     location.reload(true);
57                 } else {
58                     $('#registration-form span.error').remove();
59                     $.each(response.errors, function(id, errors) {
60                         $('#id_registration-' + id).before('<span class="error">' + errors[0] + '</span>');
61                     });
62                     $('#registration-form input[type=submit]').removeAttr('disabled');
63                     $('#registration-form img').remove();
64                 }
65             }
66         });
67         
68         $('#login-form').ajaxForm({
69             dataType: 'json',
70             beforeSubmit: function() {
71                 $('#login-form input[type=submit]')
72                     .attr('disabled', 'disabled')
73                     .after('<img src="/media/img/indicator.gif" style="margin-left: 0.5em"/>');
74             },
75             success: function(response) {
76                 if (response.success) {
77                     location.reload(true);
78                 } else {
79                     $('#login-form span.error').remove();
80                     $.each(response.errors, function(id, errors) {
81                         $('#id_login-' + id).before('<span class="error">' + errors[0] + '</span>');
82                     });
83                     $('#login-form input[type=submit]').removeAttr('disabled');
84                     $('#login-form img').remove();
85                 }
86             }
87         });
88         
89         $('#login-register-window').jqm({
90             target: target[0],
91             overlay: 60,
92             trigger: '.login-register-link',
93             onShow: function(hash) {
94                 var offset = $(hash.t).offset();
95                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
96                 $('div.header', hash.w).css({width: $(hash.t).width()});
97                 hash.w.show();
98             }
99         });
100         
101         $('ul.shelf-list li').hover(function() {
102             $(this).css({background: '#EEE', cursor: 'pointer'});
103         }, function() {
104             $(this).css({background: 'transparent'});
105         }).click(function() {
106             location.href = $('a.visit-shelf', this).attr('href');
107         });
108         
109         $('.delete-shelf').click(function() { 
110             var link = $(this);
111             var shelf_name = $('.visit-shelf', link.parent()).text();
112             if (confirm('Czy na pewno usunąć półkę ' + shelf_name + '?')) {
113                 $.post(link.attr('href'), function(data, textStatus) {
114                     link.parent().remove();
115                 });
116             }
117             return false;
118         });
119         
120         $('#user-shelves-window').jqm({
121             ajax: '@href',
122             target: $('#user-shelves-window div.target')[0],
123             overlay: 60,
124             trigger: '#user-shelves-link',
125             onShow: function(hash) {
126                 var offset = $(hash.t).offset();
127                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
128                 $('div.header', hash.w).css({width: $(hash.t).width()});
129                 hash.w.show();
130             },
131             onLoad: function(hash) { 
132                 $('form', hash.w).ajaxForm({
133                     target: $('#user-shelves-window div.target'),
134                     success: function() { setTimeout(function() { $('#user-shelves-window').jqmHide() }, 1000) }
135                 });
136                 
137                 $('input', hash.w).labelify({labelledClass: 'blur'});
138                 
139                 $('ul.shelf-list li', hash.w).hover(function() {
140                     $(this).css({background: '#EEE', cursor: 'pointer'});
141                 }, function() {
142                     $(this).css({background: 'transparent'});
143                 }).click(function() {
144                     location.href = $('a.visit-shelf', this).attr('href');
145                 });
146                 
147                 $('.delete-shelf').click(function() {
148                     var link = $(this);
149                     var shelf_name = $('.visit-shelf', link.parent()).text();
150                     if (confirm('Czy na pewno usunąć półkę ' + shelf_name + '?')) {
151                         $.post(link.attr('href'), function(data, textStatus) {
152                             link.parent().remove();
153                         });
154                     }
155                     return false;
156                 });
157             }
158         });
159     });
160 })(jQuery)