summaryrefslogtreecommitdiffstats
path: root/hyperkitty/static/js/hyperkitty.js
blob: 2b6a818f8d6b9d5aca95169abdd67df215958edc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * -*- coding: utf-8 -*-
 * Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
 *
 * This file is part of HyperKitty.
 *
 * HyperKitty is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * HyperKitty is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * HyperKitty.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Aurelien Bompard <abompard@fedoraproject.org>
 */



/*
 * Voting
 */

function vote(elem, value) {
    var form_data = $(elem).parent("form").serializeArray();
    var data = {};
    for (input in form_data) {
        data[form_data[input].name] = form_data[input].value;
    }
    data['vote'] = value;
    $.ajax({
        type: "POST",
        url: $(elem).parent("form").attr("action"),
        dataType: "json",
        data: data,
        success: function(response) {
            var likestatus = $(elem).parent("form").find(".likestatus");
            likestatus.find(".likecount").html(response.like);
            likestatus.find(".dislikecount").html(response.dislike);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            // authentication or double-vote
            if (jqXHR.status === 403) {
                alert(jqXHR.responseText);
            }
        }
    });
}


function setup_vote() {
    $(".voteup").click(function() { vote(this, 1); return false; });
    $(".votedown").click(function() { vote(this, -1); return false; });
}


/*
 * Tagging
 */

function setup_add_tag() {
    $("#add_tag_form").submit( function () {
        $.ajax({
            type: "POST",
            dataType: "json",
            data : $(this).serialize(),
            url: $(this).attr("action"),
            success: function(data) {
                $("#tags").html(data.html);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                // authentication and invalid data
                alert(jqXHR.responseText);
            }
        });
        return false;
    });
}



function setup_attachments() {
    $("ul.email_info li.attachments ul.attachments-list").hide();
    $("ul.email_info li.attachments > a").click(function() {
        $(this).next("ul").fadeToggle('fast');
    });
}



/*
 * General
 */

$(document).ready(function() {
    setup_vote();
    setup_attachments();
    setup_add_tag();
});