diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-06-13 17:23:48 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-06-13 17:46:33 +0200 |
commit | 09cd0fbcad7b62fbb7cbfb5adfbf78406db2555a (patch) | |
tree | c5df6008b289ec80f217b2c696294059287a8189 /hyperkitty/static | |
parent | 56d884568d52d42c6a18905fb7b2f004b1a6b296 (diff) | |
download | hyperkitty-09cd0fbcad7b62fbb7cbfb5adfbf78406db2555a.tar.gz hyperkitty-09cd0fbcad7b62fbb7cbfb5adfbf78406db2555a.tar.xz hyperkitty-09cd0fbcad7b62fbb7cbfb5adfbf78406db2555a.zip |
Split the JS code into more manageable chunks
Diffstat (limited to 'hyperkitty/static')
-rw-r--r-- | hyperkitty/static/js/hyperkitty-common.js | 113 | ||||
-rw-r--r-- | hyperkitty/static/js/hyperkitty-frontpage.js | 52 | ||||
-rw-r--r-- | hyperkitty/static/js/hyperkitty-overview.js | 107 | ||||
-rw-r--r-- | hyperkitty/static/js/hyperkitty-thread.js (renamed from hyperkitty/static/js/hyperkitty.js) | 264 | ||||
-rw-r--r-- | hyperkitty/static/js/hyperkitty-userprofile.js | 67 |
5 files changed, 341 insertions, 262 deletions
diff --git a/hyperkitty/static/js/hyperkitty-common.js b/hyperkitty/static/js/hyperkitty-common.js new file mode 100644 index 0000000..2d2ff16 --- /dev/null +++ b/hyperkitty/static/js/hyperkitty-common.js @@ -0,0 +1,113 @@ +/* + * 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> + */ + + +/* + * Generic + */ +function form_to_json(form) { + var form_data = form.serializeArray(); + var data = {}; + for (input in form_data) { + data[form_data[input].name] = form_data[input].value; + } + return data; +} + + +/* + * Voting + */ + +function vote(elem) { + if ($(elem).hasClass("disabled")) { + return; + } + var value = parseInt($(elem).attr("data-vote")); + var form = $(elem).parents("form").first(); + var data = form_to_json(form); + data['vote'] = value; + $.ajax({ + type: "POST", + url: form.attr("action"), + dataType: "json", + data: data, + success: function(response) { + var newcontent = $(response.html); + form.replaceWith(newcontent); + setup_vote(newcontent); // re-bind events + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(jqXHR.responseText); + } + }); +} + + +function setup_vote(baseElem) { + if (!baseElem) { + baseElem = document; + } + $(baseElem).find("a.vote").click(function(e) { + e.preventDefault(); + vote(this); + }); +} + + +/* + * Misc. + */ + +function setup_months_list() { + var current = $("#months-list li.current").parent().prev(); + if (!current.length) { + current = 0; // overview or search + } else { + current = current.prevAll("h3").length; + } + $("#months-list").accordion({ collapsible: true, active: current }); +} + +function setup_disabled_tooltips(baseElem) { + if (!baseElem) { + baseElem = document; + } + $(baseElem).find("a.disabled").tooltip().click(function (e) { + e.preventDefault(); + }); +} + +function setup_flash_messages() { + $('.flashmsgs .alert-success').delay(3000).fadeOut('slow'); +} + + +/* + * Activate + */ + +$(document).ready(function() { + setup_vote(); + setup_months_list(); + setup_disabled_tooltips(); + setup_flash_messages(); +}); diff --git a/hyperkitty/static/js/hyperkitty-frontpage.js b/hyperkitty/static/js/hyperkitty-frontpage.js new file mode 100644 index 0000000..fbcb12d --- /dev/null +++ b/hyperkitty/static/js/hyperkitty-frontpage.js @@ -0,0 +1,52 @@ +/* + * 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> + */ + + +/* + * List descriptions on the front page + */ +function update_list_properties(url) { + $.ajax({ + dataType: "json", + url: url, + success: function(data) { + $(".all-lists .mailinglist").each(function() { + var name = $(this).find(".list-address").text(); + if (!data[name]) { + return; + } + if (data[name]["display_name"]) { + $(this).find(".list-name").text(data[name]["display_name"]); + } + if (data[name]["description"]) { + $(this).find(".list-description") + .text(data[name]["description"]); + } + }); + }, + error: function(jqXHR, textStatus, errorThrown) { + //alert(jqXHR.responseText); + }, + complete: function(jqXHR, textStatus) { + $(".all-lists .mailinglist img.ajaxloader").remove(); + } + }); +} diff --git a/hyperkitty/static/js/hyperkitty-overview.js b/hyperkitty/static/js/hyperkitty-overview.js new file mode 100644 index 0000000..bf88118 --- /dev/null +++ b/hyperkitty/static/js/hyperkitty-overview.js @@ -0,0 +1,107 @@ +/* + * 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> + */ + + +/* + * Recent activity graph + */ +function activity_graph(elem_id, dates, counts, baseurl) { + function merge(dates, counts) { + result = [] + for(i = 0; i < dates.length; i++) { + result.push({ + "date": dates[i], + "count": counts[i] + }) + } + return result; + } + var data = merge(dates, counts); + var margin = {top: 20, right: 20, bottom: 100, left: 50}, + width = 540 - margin.left - margin.right, + height = 330 - margin.top - margin.bottom; + + var format_in = d3.time.format("%Y-%m-%d"); + var format_out = d3.time.format("%m-%d"); + + var x = d3.time.scale() + .range([0, width]); + + var y = d3.scale.linear() + .range([height, 0]); + + var xAxis = d3.svg.axis() + .scale(x) + .orient("bottom") + .tickFormat(format_out) + .ticks(d3.time.days, 2); + + var yAxis = d3.svg.axis() + .scale(y) + .orient("left") + .ticks(5) + .tickSubdivide(1); + + var area = d3.svg.area() + .x(function(d) { return x(d.date); }) + .y0(height) + .y1(function(d) { return y(d.count); }); + + var svg = d3.select(elem_id).append("svg") + .attr("width", width + margin.left + margin.right) + .attr("height", height + margin.top + margin.bottom) + .append("g") + .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); + + data.forEach(function(d) { + d.date = format_in.parse(d.date); + d.count = parseInt(d.count); + }); + + x.domain(d3.extent(data, function(d) { return d.date; })); + y.domain([0, d3.max(data, function(d) { return d.count; })]); + + svg.append("path") + .datum(data) + .attr("class", "area") + .attr("d", area); + + svg.append("g") + .attr("class", "x axis") + .attr("transform", "translate(0," + height + ")") + .call(xAxis) + .selectAll("text") + .attr("y", -5) + .attr("x", -30) + .attr("transform", function(d) { + return "rotate(-90)" + }); + + svg.append("g") + .attr("class", "y axis") + .call(yAxis) + .append("text") + .attr("transform", "rotate(-90)") + .attr("y", 6) + .attr("dy", ".71em") + .style("text-anchor", "end") + .text("Messages"); +} diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty-thread.js index 49bee91..e841f75 100644 --- a/hyperkitty/static/js/hyperkitty.js +++ b/hyperkitty/static/js/hyperkitty-thread.js @@ -21,59 +21,6 @@ /* - * Generic - */ -function form_to_json(form) { - var form_data = form.serializeArray(); - var data = {}; - for (input in form_data) { - data[form_data[input].name] = form_data[input].value; - } - return data; -} - - -/* - * Voting - */ - -function vote(elem) { - if ($(elem).hasClass("disabled")) { - return; - } - var value = parseInt($(elem).attr("data-vote")); - var form = $(elem).parents("form").first(); - var data = form_to_json(form); - data['vote'] = value; - $.ajax({ - type: "POST", - url: form.attr("action"), - dataType: "json", - data: data, - success: function(response) { - var newcontent = $(response.html); - form.replaceWith(newcontent); - setup_vote(newcontent); // re-bind events - }, - error: function(jqXHR, textStatus, errorThrown) { - alert(jqXHR.responseText); - } - }); -} - - -function setup_vote(baseElem) { - if (!baseElem) { - baseElem = document; - } - $(baseElem).find("a.vote").click(function(e) { - e.preventDefault(); - vote(this); - }); -} - - -/* * Tagging */ @@ -92,6 +39,8 @@ function setup_tags() { e.preventDefault(); $(this).parents("form").first().submit(); }); + console.log($(this)); + $(this).find("#id_tag").value(""); }, error: function(jqXHR, textStatus, errorThrown) { // authentication and invalid data @@ -307,93 +256,6 @@ function setup_unreadnavbar(element) { /* - * Recent activity graph - */ -function activity_graph(elem_id, dates, counts, baseurl) { - function merge(dates, counts) { - result = [] - for(i = 0; i < dates.length; i++) { - result.push({ - "date": dates[i], - "count": counts[i] - }) - } - return result; - } - var data = merge(dates, counts); - var margin = {top: 20, right: 20, bottom: 100, left: 50}, - width = 540 - margin.left - margin.right, - height = 330 - margin.top - margin.bottom; - - var format_in = d3.time.format("%Y-%m-%d"); - var format_out = d3.time.format("%m-%d"); - - var x = d3.time.scale() - .range([0, width]); - - var y = d3.scale.linear() - .range([height, 0]); - - var xAxis = d3.svg.axis() - .scale(x) - .orient("bottom") - .tickFormat(format_out) - .ticks(d3.time.days, 2); - - var yAxis = d3.svg.axis() - .scale(y) - .orient("left") - .ticks(5) - .tickSubdivide(1); - - var area = d3.svg.area() - .x(function(d) { return x(d.date); }) - .y0(height) - .y1(function(d) { return y(d.count); }); - - var svg = d3.select(elem_id).append("svg") - .attr("width", width + margin.left + margin.right) - .attr("height", height + margin.top + margin.bottom) - .append("g") - .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); - - data.forEach(function(d) { - d.date = format_in.parse(d.date); - d.count = parseInt(d.count); - }); - - x.domain(d3.extent(data, function(d) { return d.date; })); - y.domain([0, d3.max(data, function(d) { return d.count; })]); - - svg.append("path") - .datum(data) - .attr("class", "area") - .attr("d", area); - - svg.append("g") - .attr("class", "x axis") - .attr("transform", "translate(0," + height + ")") - .call(xAxis) - .selectAll("text") - .attr("y", -5) - .attr("x", -30) - .attr("transform", function(d) { - return "rotate(-90)" - }); - - svg.append("g") - .attr("class", "y axis") - .call(yAxis) - .append("text") - .attr("transform", "rotate(-90)") - .attr("y", 6) - .attr("dy", ".71em") - .style("text-anchor", "end") - .text("Messages"); -} - - -/* * Thread replies list */ function update_thread_replies(url) { @@ -427,125 +289,3 @@ function update_thread_replies(url) { } load_more(url); } - - -/* - * List descriptions on the front page - */ -function update_list_properties(url) { - $.ajax({ - dataType: "json", - url: url, - success: function(data) { - $(".all-lists .mailinglist").each(function() { - var name = $(this).find(".list-address").text(); - if (!data[name]) { - return; - } - if (data[name]["display_name"]) { - $(this).find(".list-name").text(data[name]["display_name"]); - } - if (data[name]["description"]) { - $(this).find(".list-description") - .text(data[name]["description"]); - } - }); - }, - error: function(jqXHR, textStatus, errorThrown) { - //alert(jqXHR.responseText); - }, - complete: function(jqXHR, textStatus) { - $(".all-lists .mailinglist img.ajaxloader").remove(); - } - }); -} - - -/* - * Last viewed threads and votes in the user's profile - */ -function update_user_profile_part(container, base_url) { - container = $(container); - var loader = container.prev(".ajaxloader"); - function _update(url) { - loader.show(); - $.ajax({ - url: url, - success: function(data) { - container.html(data); - container.find(".pagination a").click(function(e) { - e.preventDefault(); - _update(base_url + $(this).attr("href")); - }); - // setup cancellation links - container.find("a.cancel").click(function(e) { - e.preventDefault(); - var form = $(this).parents("form").first(); - var data = form_to_json(form); - $.ajax({ - type: "POST", - url: form.attr("action"), - data: data, - dataType: "json", - success: function(response) { - form.parents("tr").remove(); - }, - error: function(jqXHR, textStatus, errorThrown) { - alert(jqXHR.responseText); - } - }); - }); - }, - error: function(jqXHR, textStatus, errorThrown) { - //alert(jqXHR.responseText); - }, - complete: function(jqXHR, textStatus) { - loader.hide(); - } - }); - } - _update(base_url); -} - - -/* - * Misc. - */ - -function setup_months_list() { - var current = $("#months-list li.current").parent().prev(); - if (!current.length) { - current = 0; // overview or search - } else { - current = current.prevAll("h3").length; - } - $("#months-list").accordion({ collapsible: true, active: current }); -} - -function setup_disabled_tooltips(baseElem) { - if (!baseElem) { - baseElem = document; - } - $(baseElem).find("a.disabled").tooltip().click(function (e) { - e.preventDefault(); - }); -} - -function setup_flash_messages() { - $('.flashmsgs .alert-success').delay(3000).fadeOut('slow'); -} - - -/* - * General - */ - -$(document).ready(function() { - setup_vote(); - setup_tags(); - setup_months_list(); - setup_favorites(); - setup_emails_list(); - setup_disabled_tooltips(); - setup_flash_messages(); -}); diff --git a/hyperkitty/static/js/hyperkitty-userprofile.js b/hyperkitty/static/js/hyperkitty-userprofile.js new file mode 100644 index 0000000..d755f6f --- /dev/null +++ b/hyperkitty/static/js/hyperkitty-userprofile.js @@ -0,0 +1,67 @@ +/* + * 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> + */ + + +/* + * Last viewed threads and votes in the user's profile + */ +function update_user_profile_part(container, base_url) { + container = $(container); + var loader = container.prev(".ajaxloader"); + function _update(url) { + loader.show(); + $.ajax({ + url: url, + success: function(data) { + container.html(data); + container.find(".pagination a").click(function(e) { + e.preventDefault(); + _update(base_url + $(this).attr("href")); + }); + // setup cancellation links + container.find("a.cancel").click(function(e) { + e.preventDefault(); + var form = $(this).parents("form").first(); + var data = form_to_json(form); + $.ajax({ + type: "POST", + url: form.attr("action"), + data: data, + dataType: "json", + success: function(response) { + form.parents("tr").remove(); + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(jqXHR.responseText); + } + }); + }); + }, + error: function(jqXHR, textStatus, errorThrown) { + //alert(jqXHR.responseText); + }, + complete: function(jqXHR, textStatus) { + loader.hide(); + } + }); + } + _update(base_url); +} |