From 76a986b0dbfdd9b5978c20b89a591ba519ddeee5 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 9 Jan 2011 14:36:20 -0600 Subject: gjslint recommended javascript cleanups Signed-off-by: Dan McGee --- media/archweb.js | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index 1c80ab64..28398c47 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -1,6 +1,6 @@ /* tablesorter custom parsers for various pages: * devel/index.html, mirrors/status.html, todolists/view.html */ -if(typeof $.tablesorter !== "undefined") { +if (typeof $.tablesorter !== 'undefined') { $.tablesorter.addParser({ id: 'pkgcount', is: function(s) { return false; }, @@ -21,14 +21,14 @@ if(typeof $.tablesorter !== "undefined") { $.tablesorter.addParser({ /* sorts numeric, but put '', 'unknown', and '∞' last. */ id: 'mostlydigit', - is: function(s,table) { + is: function(s, table) { var special = ['', 'unknown', '∞']; var c = table.config; - return ($.inArray(s, special) > -1) || $.tablesorter.isDigit(s,c); + return ($.inArray(s, special) > -1) || $.tablesorter.isDigit(s, c); }, format: function(s) { var special = ['', 'unknown', '∞']; - if($.inArray(s, special) > -1) return Number.MAX_VALUE; + if ($.inArray(s, special) > -1) return Number.MAX_VALUE; return $.tablesorter.formatFloat(s); }, type: 'numeric' @@ -43,7 +43,7 @@ if(typeof $.tablesorter !== "undefined") { }, format: function(s) { var special = ['', 'unknown', '∞']; - if($.inArray(s, special) > -1) return Number.MAX_VALUE; + if ($.inArray(s, special) > -1) return Number.MAX_VALUE; var matches = this.re.exec(s); return matches[1] * 60 + matches[2]; }, @@ -52,17 +52,17 @@ if(typeof $.tablesorter !== "undefined") { $.tablesorter.addParser({ id: 'longDateTime', re: /^(\d{4})-(\d{2})-(\d{2}) ([012]\d):([0-5]\d)(:([0-5]\d))?( (\w+))?$/, - is: function (s) { + is: function(s) { return this.re.test(s); }, - format: function (s) { + format: function(s) { var matches = this.re.exec(s); /* skip group 6, group 7 is optional seconds */ - if(matches[7] == undefined) matches[7] = "0"; + if (matches[7] == undefined) matches[7] = '0'; return $.tablesorter.formatFloat(new Date( matches[1],matches[2],matches[3],matches[4],matches[5],matches[7]).getTime()); }, - type: "numeric" + type: 'numeric' }); } @@ -94,16 +94,16 @@ function ajaxifyFiles() { /* packages/differences.html */ filter_packages = function() { // start with all rows, and then remove ones we shouldn't show - var rows = $("#tbody_differences").children(); + var rows = $('#tbody_differences').children(); var all_rows = rows; - if(!$('#id_multilib').is(':checked')) { - rows = rows.not(".multilib").not(".multilib-testing"); + if (!$('#id_multilib').is(':checked')) { + rows = rows.not('.multilib').not('.multilib-testing'); } - var arch = $("#id_archonly").val(); - if(arch !== "all") { - rows = rows.filter("." + arch); + var arch = $('#id_archonly').val(); + if (arch !== 'all') { + rows = rows.filter('.' + arch); } - if(!$('#id_minor').is(':checked')) { + if (!$('#id_minor').is(':checked')) { // this check is done last because it is the most expensive var pat = /(.*)-(.+)/; rows = rows.filter(function(index) { @@ -111,15 +111,15 @@ filter_packages = function() { // all this just to get the split version out of the table cell var ver_a = cells.eq(2).find('span').text().match(pat); - if(!ver_a) return true; + if (!ver_a) return true; var ver_b = cells.eq(3).find('span').text().match(pat); - if(!ver_b) return true; + if (!ver_b) return true; // first check pkgver - if(ver_a[1] !== ver_b[1]) return true; + if (ver_a[1] !== ver_b[1]) return true; // pkgver matched, so see if rounded pkgrel matches - if(Math.floor(parseFloat(ver_a[2])) == + if (Math.floor(parseFloat(ver_a[2])) == Math.floor(parseFloat(ver_b[2]))) return false; // pkgrel didn't match, so keep the row return true; @@ -129,12 +129,12 @@ filter_packages = function() { all_rows.hide(); rows.show(); // make sure we update the odd/even styling from sorting - $('.results').trigger("applyWidgets"); + $('.results').trigger('applyWidgets'); }; filter_reset = function() { - $('#id_archonly').val("both"); - $('#id_multilib').removeAttr("checked"); - $('#id_minor').removeAttr("checked"); + $('#id_archonly').val('both'); + $('#id_multilib').removeAttr('checked'); + $('#id_minor').removeAttr('checked'); filter_packages(); }; @@ -143,9 +143,11 @@ todolist_flag = function() { var link = this; $.getJSON(link.href, function(data) { if (data.complete) { - $(link).text('Complete').addClass('complete').removeClass('incomplete'); + $(link).text('Complete').addClass( + 'complete').removeClass('incomplete'); } else { - $(link).text('Incomplete').addClass('incomplete').removeClass('complete'); + $(link).text('Incomplete').addClass( + 'incomplete').removeClass('complete'); } }); return false; -- cgit v1.2.3-54-g00ecf From 262f8f3749526a1ec04e208ba3e9945fc12f36ca Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 9 Jan 2011 14:56:40 -0600 Subject: Convert function expressions to declarations Signed-off-by: Dan McGee --- media/archweb.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index 28398c47..bbbc48b2 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -92,7 +92,7 @@ function ajaxifyFiles() { } /* packages/differences.html */ -filter_packages = function() { +function filter_packages() { // start with all rows, and then remove ones we shouldn't show var rows = $('#tbody_differences').children(); var all_rows = rows; @@ -130,16 +130,16 @@ filter_packages = function() { rows.show(); // make sure we update the odd/even styling from sorting $('.results').trigger('applyWidgets'); -}; -filter_reset = function() { +} +function filter_reset() { $('#id_archonly').val('both'); $('#id_multilib').removeAttr('checked'); $('#id_minor').removeAttr('checked'); filter_packages(); -}; +} /* todolists/view.html */ -todolist_flag = function() { +function todolist_flag() { var link = this; $.getJSON(link.href, function(data) { if (data.complete) { @@ -151,4 +151,4 @@ todolist_flag = function() { } }); return false; -}; +} -- cgit v1.2.3-54-g00ecf From 9538d3492eb0efef144b78a50035ce4e4deaf8d1 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 14 Jan 2011 14:38:23 -0600 Subject: Fix JS null error when parsing non-matching date We didn't escape early with some value, causing an invalid dereference. While fixing this, also touch up the other functions and move a few more thngs to parser dictionary attributes. Signed-off-by: Dan McGee --- media/archweb.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index bbbc48b2..cf8acd15 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -21,14 +21,13 @@ if (typeof $.tablesorter !== 'undefined') { $.tablesorter.addParser({ /* sorts numeric, but put '', 'unknown', and '∞' last. */ id: 'mostlydigit', + special: ['', 'unknown', '∞'], is: function(s, table) { - var special = ['', 'unknown', '∞']; var c = table.config; - return ($.inArray(s, special) > -1) || $.tablesorter.isDigit(s, c); + return ($.inArray(s, this.special) > -1) || $.tablesorter.isDigit(s, c); }, format: function(s) { - var special = ['', 'unknown', '∞']; - if ($.inArray(s, special) > -1) return Number.MAX_VALUE; + if ($.inArray(s, this.special) > -1) return Number.MAX_VALUE; return $.tablesorter.formatFloat(s); }, type: 'numeric' @@ -37,14 +36,14 @@ if (typeof $.tablesorter !== 'undefined') { /* sorts duration; put '', 'unknown', and '∞' last. */ id: 'duration', re: /^([0-9]+):([0-5][0-9])$/, + special: ['', 'unknown', '∞'], is: function(s) { - var special = ['', 'unknown', '∞']; - return ($.inArray(s, special) > -1) || this.re.test(s); + return ($.inArray(s, this.special) > -1) || this.re.test(s); }, format: function(s) { - var special = ['', 'unknown', '∞']; - if ($.inArray(s, special) > -1) return Number.MAX_VALUE; + if ($.inArray(s, this.special) > -1) return Number.MAX_VALUE; var matches = this.re.exec(s); + if (!matches) return Number.MAX_VALUE; return matches[1] * 60 + matches[2]; }, type: 'numeric' @@ -57,6 +56,7 @@ if (typeof $.tablesorter !== 'undefined') { }, format: function(s) { var matches = this.re.exec(s); + if (!matches) return 0; /* skip group 6, group 7 is optional seconds */ if (matches[7] == undefined) matches[7] = '0'; return $.tablesorter.formatFloat(new Date( -- cgit v1.2.3-54-g00ecf From d3e1b867e4262ad044a683678adf75cd72b79912 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 14 Jan 2011 15:18:36 -0600 Subject: Update tablesorter cache after clicking todo list status We didn't update this before, so sorting the last after checking off a few todos didn't work right, as it was using the old values. Fix it by adding a call to update; this can eventually be changed to the updateCell call commented out once I upgrade the minified tablesorter.js file. Signed-off-by: Dan McGee --- media/archweb.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index cf8acd15..7a0d1dcc 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -14,7 +14,7 @@ if (typeof $.tablesorter !== 'undefined') { id: 'todostatus', is: function(s) { return false; }, format: function(s) { - return s.match(/incomplete/) ? 1 : 0; + return s.match(/incomplete/i) ? 1 : 0; }, type: 'numeric' }); @@ -149,6 +149,9 @@ function todolist_flag() { $(link).text('Incomplete').addClass( 'incomplete').removeClass('complete'); } + /* let tablesorter know the cell value has changed */ + /* newer version of tablesorter: $('.results').trigger('updateCell', $(link).parent('td')); */ + $('.results').trigger('update'); }); return false; } -- cgit v1.2.3-54-g00ecf From 758476b547c4a4a86541923cd27fab4970060a5b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 14 Jan 2011 23:45:27 -0600 Subject: Use more efficient updateCell event after todo list click Signed-off-by: Dan McGee --- media/archweb.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index 7a0d1dcc..b2f3af2a 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -150,8 +150,7 @@ function todolist_flag() { 'incomplete').removeClass('complete'); } /* let tablesorter know the cell value has changed */ - /* newer version of tablesorter: $('.results').trigger('updateCell', $(link).parent('td')); */ - $('.results').trigger('update'); + $('.results').trigger('updateCell', $(link).parent('td')); }); return false; } -- cgit v1.2.3-54-g00ecf From 487daf1c72f86a064b659f68d9f7722706997ab2 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 18 Jan 2011 10:14:28 -0600 Subject: Make package signoffs AJAX if JS is enabled This makes the signoffs page a heck of a lot more usable as you can go through and click a bunch at once without waiting for the rather slow page to reload. Hopefully the first step to bringing life back into this part of the site. Signed-off-by: Dan McGee --- media/archweb.js | 23 +++++++++++++++++++++++ packages/urls.py | 2 +- packages/views.py | 30 ++++++++++++++++-------------- templates/packages/signoffs.html | 7 +++++-- 4 files changed, 45 insertions(+), 17 deletions(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index b2f3af2a..b7351878 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -154,3 +154,26 @@ function todolist_flag() { }); return false; } + +/* signoffs.html */ +function signoff_package() { + var link = this; + $.getJSON(link.href, function(data) { + if (data.created) { + var signoff = $('
  • ').addClass('signed-username').text(data.user); + $(link).append(signoff); + } + /* update the approved column to reflect reality */ + if (data.approved) { + var approved = $(link).closest('tr').children('.signoff-no'); + approved.text('Yes').addClass( + 'signoff-yes').removeClass('signoff-no'); + } else { + var approved = $(link).closest('tr').children('.signoff-yes'); + approved.text('No').addClass( + 'signoff-no').removeClass('signoff-yes'); + } + $('.results').trigger('updateCell', approved); + }); + return false; +} diff --git a/packages/urls.py b/packages/urls.py index da24ee03..c9006a12 100644 --- a/packages/urls.py +++ b/packages/urls.py @@ -11,7 +11,7 @@ urlpatterns = patterns('packages.views', (r'^flaghelp/$', 'flaghelp'), - (r'^signoffs/$', 'signoffs'), + (r'^signoffs/$', 'signoffs', {}, 'package-signoffs'), (r'^signoff_package/(?P[A-z0-9]+)/(?P[A-z0-9\-+.]+)/$', 'signoff_package'), (r'^update/$', 'update'), diff --git a/packages/views.py b/packages/views.py index 77fa3a07..4e683144 100644 --- a/packages/views.py +++ b/packages/views.py @@ -1,18 +1,19 @@ from django import forms from django.contrib import messages +from django.contrib.admin.widgets import AdminDateWidget +from django.contrib.auth.models import User +from django.contrib.auth.decorators import permission_required from django.conf import settings from django.core.mail import send_mail -from django.template import loader, Context, RequestContext +from django.db.models import Q from django.http import HttpResponse, Http404 from django.shortcuts import get_object_or_404, redirect -from django.contrib.auth.models import User -from django.contrib.auth.decorators import permission_required -from django.contrib.admin.widgets import AdminDateWidget +from django.template import loader, Context, RequestContext +from django.utils import simplejson from django.views.decorators.cache import never_cache from django.views.decorators.vary import vary_on_headers from django.views.generic import list_detail from django.views.generic.simple import direct_to_template -from django.db.models import Q from datetime import datetime import string @@ -276,15 +277,16 @@ def signoff_package(request, arch, pkgname): pkgrel=pkg.pkgrel, packager=request.user) - if created: - messages.info(request, - "You have successfully signed off for %s on %s." % \ - (pkg.pkgname, pkg.arch)) - else: - messages.warning(request, - "You have already signed off for %s on %s." % \ - (pkg.pkgname, pkg.arch)) - return signoffs(request) + if request.is_ajax(): + data = { + 'created': created, + 'approved': pkg.approved_for_signoff(), + 'user': str(request.user), + } + return HttpResponse(simplejson.dumps(data), + mimetype='application/json') + + return redirect('package-signoffs') def flaghelp(request): return direct_to_template(request, 'packages/flaghelp.html') diff --git a/templates/packages/signoffs.html b/templates/packages/signoffs.html index 8d78c8a1..0cb7679c 100644 --- a/templates/packages/signoffs.html +++ b/templates/packages/signoffs.html @@ -33,7 +33,7 @@

    Package Signoffs

    {{ pkg.approved_for_signoff|yesno:"Yes,No" }}
      -
    • Signoff
    • {% for signoff in pkg.signoffs %} @@ -49,9 +49,12 @@

      Package Signoffs

      {% load cdn %}{% jquery %} + {% endif %} -- cgit v1.2.3-54-g00ecf From ecb24ab66a9d0a03ad021d23d4fa543f8163ef3e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 18 Jan 2011 14:23:57 -0600 Subject: Small JS clarification for finding table cell Although it happened to be the parent element in this case, we are really just looking for the containing cell. Change the call to closest so we are future-proofed. Signed-off-by: Dan McGee --- media/archweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index b7351878..330eeff9 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -150,7 +150,7 @@ function todolist_flag() { 'incomplete').removeClass('complete'); } /* let tablesorter know the cell value has changed */ - $('.results').trigger('updateCell', $(link).parent('td')); + $('.results').trigger('updateCell', $(link).closest('td')); }); return false; } -- cgit v1.2.3-54-g00ecf