[IMP] warnings and shit
[odoo/odoo.git] / addons / website_blog / static / src / js / website_blog.js
1 $(document).ready(function () {
2     $('.js_nav_year a:first').on('click', function (e) {
3         e.preventDefault();
4         $(this).next("ul").toggle();
5     });
6
7     $('.js_nav_month a:first').on('click', function (e) {
8         e.preventDefault();
9         var $ul = $(this).next("ul");
10         if (!$ul.find('li').length) {
11             $.post('/blog/nav', {'domain': $(this).data("domain")}, function (result) {
12                 var blog_id = +window.location.pathname.split("/").pop();
13                 $(JSON.parse(result)).each(function () {
14                     var $a = $('<a href="/blog/' + this.category_id + '/' + this.id + '"/>').text(this.name);
15                     var $li = $("<li/>").append($a);
16                     if (blog_id == this.id)
17                         $li.addClass("active");
18                     if (!this.website_published)
19                         $a.css("color", "red");
20                     $ul.append($li);
21                 });
22
23             });
24         } else {
25             $ul.toggle();
26         }
27     });
28
29     var $form = $('.js_website_blog form#comment');
30     $form.submit(function (e) {
31         e.preventDefault();
32         var error = $form.find("textarea").val().length < 3;
33         $form.find("textarea").toggleClass("has-error", error);
34         if (!error) {
35             $form.css("visibility", "hidden");
36             $.post(window.location.pathname + '/post', {'body': $form.find("textarea").val()}, function (url) {
37                 window.location.href = url
38             });
39         }
40     });
41 });