From c4fa700661c2b69ae02eb282b25bb11d5ebc30f4 Mon Sep 17 00:00:00 2001 From: hernani Date: Fri, 21 May 2010 12:08:55 +0000 Subject: [PATCH] Some general UI enhancements. Merged base and base_content.html for consistency and avoid code duplication. Fixed a bug with negative reputation. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@312 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/action.py | 4 +- forum/skins/default/media/js/osqa.ask.js | 6 +- forum/skins/default/media/js/osqa.main.js | 181 ++++++++++++------ forum/skins/default/media/js/osqa.user.js | 108 +++++------ forum/skins/default/media/style/style.css | 44 +++++ forum/skins/default/media/style/user.css | 33 +--- forum/skins/default/templates/base.html | 108 ++--------- .../skins/default/templates/base_content.html | 42 +++- .../default/templates/node/comments.html | 2 +- .../skins/default/templates/node/report.html | 5 +- forum/skins/default/templates/user.html | 1 - forum/skins/default/templates/users/menu.html | 13 -- 12 files changed, 269 insertions(+), 278 deletions(-) diff --git a/forum/models/action.py b/forum/models/action.py index 82ca34a..4eed471 100644 --- a/forum/models/action.py +++ b/forum/models/action.py @@ -276,11 +276,11 @@ class ActionRepute(models.Model): def save(self, *args, **kwargs): super(ActionRepute, self).save(*args, **kwargs) - self.user.reputation = models.F('reputation') + self.value + self.user.reputation += self.value self.user.save() def delete(self): - self.user.reputation = models.F('reputation') - self.value + self.user.reputation -= self.value self.user.save() super(ActionRepute, self).delete() diff --git a/forum/skins/default/media/js/osqa.ask.js b/forum/skins/default/media/js/osqa.ask.js index e5e8c20..a649997 100644 --- a/forum/skins/default/media/js/osqa.ask.js +++ b/forum/skins/default/media/js/osqa.ask.js @@ -9,9 +9,9 @@ $(function () { $('div#editor_side_bar').hide(); $('div#tags_side_bar').hide(); - $('input#id_title').focus(function(){changeSideBar('div#title_side_bar')}); - $('textarea#editor').focus(function(){changeSideBar('div#editor_side_bar')}); - $('input#id_tags').focus(function(){changeSideBar('div#tags_side_bar')}); + $('#id_title').focus(function(){changeSideBar('div#title_side_bar')}); + $('#editor').focus(function(){changeSideBar('div#editor_side_bar')}); + $('#id_tags').focus(function(){changeSideBar('div#tags_side_bar')}); }); $(function() { diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js index a0617a3..b5aee40 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -124,78 +124,129 @@ var response_commands = { } } -function show_message(object, msg, callback) { - var div = $('

' + msg + '

(' + - 'click to close' + ')
'); - - div.click(function(event) { - $(".vote-notification").fadeOut("fast", function() { - $(this).remove(); - if (callback) { - callback(); - } +function show_dialog (extern) { + var default_close_function = function($diag) { + $diag.fadeOut('fast', function() { + $diag.remove(); }); - }); + } - object.parent().append(div); - div.fadeIn("fast"); -} + var options = { + extra_class: '', + pos: { + x: ($(window).width() / 2) + $(window).scrollLeft(), + y: ($(window).height() / 2) + $(window).scrollTop() + }, + dim: false, + yes_text: messages.ok, + yes_callback: default_close_function, + no_text: messages.cancel, + show_no: false, + close_on_clickoutside: false + } -function load_prompt(object, url) { - var $box = $('
' + - '' + - '
'); + $.extend(options, extern); + if (options.event != undefined) { + options.pos = {x: options.event.pageX, y: options.event.pageY}; + } - object.parent().append($box); - $box.fadeIn("fast"); + var html = ''; + + $dialog = $(html); + $('body').append($dialog); + + if (options.dim === false) { + $dialog.css({ + visibility: 'hidden', + display: 'block' }); - $box.find('.prompt-submit').click(function() { - start_command(); - $.post(url, {prompt: $box.find('textarea').val()}, function(data) { - $box.fadeOut('fast', function() { - $box.remove(); - }); - process_ajax_response(data, object); - }, 'json'); - return false; + options.dim = {w: $dialog.width(), h: $dialog.height()}; + + $dialog.css({ + width: 1, + height: 1, + visibility: 'visible' }); + } + + $dialog.css({ + top: options.pos.y, + left: options.pos.x + }); + + $dialog.animate({ + top: "-=" + (options.dim.h / 2), + left: "-=" + (options.dim.w / 2), + width: options.dim.w, + height: options.dim.h + }, 200); + + $dialog.find('.dialog-no').click(function() { + default_close_function($dialog); }); -} -function show_prompt(object, msg, callback) { - var div = $('
' + msg + '
' + - '
' + - '' + - '' + - '
'); + $dialog.find('.dialog-yes').click(function() { + options.yes_callback($dialog); + }); - function fade_out() { - div.fadeOut("fast", function() { div.remove(); }); + if (options.close_on_clickoutside) { + $dialog.one('clickoutside', function() { + default_close_function($dialog); + }); } - div.find('.prompt-cancel').click(fade_out); + return $dialog; +} - div.find('.prompt-ok').click(function(event) { - callback(div.find('.command-prompt').val()); - fade_out(); +function show_message(evt, msg, callback) { + var $dialog = show_dialog({ + html: msg, + extra_class: 'warning', + event: evt, + yes_callback: function() { + $dialog.fadeOut('fast', function() { + $dialog.remove(); + }); + if (callback) { + callback(); + } + }, + close_on_clickoutside: true }); +} - object.parent().append(div); - div.fadeIn("fast"); +function load_prompt(evt, url) { + $.get(url, function(data) { + var $dialog = show_dialog({ + html: data, + //extra_class: 'warning', + event: evt, + yes_callback: function() { + $.post(url, {prompt: $dialog.find('.prompt-return').val()}, function(data) { + $dialog.fadeOut('fast', function() { + $dialog.remove(); + }); + process_ajax_response(data, evt); + }, 'json'); + }, + show_no: true + }); + }); } -function process_ajax_response(data, el, callback) { +function process_ajax_response(data, evt, callback) { if (!data.success && data['error_message'] != undefined) { - show_message(el, data.error_message, function() {if (callback) callback(true);}); + show_message(evt, data.error_message, function() {if (callback) callback(true);}); end_command(false); } else if (typeof data['commands'] != undefined){ for (var command in data.commands) { @@ -203,7 +254,7 @@ function process_ajax_response(data, el, callback) { } if (data['message'] != undefined) { - show_message(el, data.message, function() {if (callback) callback(false);}) + show_message(evt, data.message, function() {if (callback) callback(false);}) } else { if (callback) callback(false); } @@ -232,17 +283,17 @@ function end_command(success) { } $(function() { - $('a.ajax-command').live('click', function() { + $('a.ajax-command').live('click', function(evt) { if (running) return false; var el = $(this); if (el.is('.withprompt')) { - load_prompt(el, el.attr('href')); + load_prompt(evt, el.attr('href')); } else { start_command(); $.getJSON(el.attr('href'), function(data) { - process_ajax_response(data, el); + process_ajax_response(data, evt); }); } @@ -385,7 +436,7 @@ $(function() { return false; }); - $button.click(function() { + $button.click(function(evt) { if (running) return false; var post_data = { @@ -398,7 +449,7 @@ $(function() { start_command(); $.post($form.attr('action'), post_data, function(data) { - process_ajax_response(data, $button, function(error) { + process_ajax_response(data, evt, function(error) { if (!error) { cleanup_form(); hide_comment_form(); @@ -925,10 +976,6 @@ var notify = function() { visible = true; }, close: function(doPostback) { - if (doPostback) { - $.post(scriptUrl + $.i18n._("messages/") + - $.i18n._("markread/"), { formdata: "required" }); - } $(".notify").fadeOut("fast"); $("body").css("margin-top", "0"); visible = false; @@ -936,3 +983,13 @@ var notify = function() { isVisible: function() { return visible; } }; } (); + +/* + * jQuery outside events - v1.1 - 3/16/2010 + * http://benalman.com/projects/jquery-outside-events-plugin/ + * + * Copyright (c) 2010 "Cowboy" Ben Alman + * Dual licensed under the MIT and GPL licenses. + * http://benalman.com/about/license/ + */ +(function($,c,b){$.map("click dblclick mousemove mousedown mouseup mouseover mouseout change select submit keydown keypress keyup".split(" "),function(d){a(d)});a("focusin","focus"+b);a("focusout","blur"+b);$.addOutsideEvent=a;function a(g,e){e=e||g+b;var d=$(),h=g+"."+e+"-special-event";$.event.special[e]={setup:function(){d=d.add(this);if(d.length===1){$(c).bind(h,f)}},teardown:function(){d=d.not(this);if(d.length===0){$(c).unbind(h)}},add:function(i){var j=i.handler;i.handler=function(l,k){l.target=k;j.apply(this,arguments)}}};function f(i){$(d).each(function(){var j=$(this);if(this!==i.target&&!j.has(i.target).length){j.triggerHandler(e,[i.target])}})}}})(jQuery,document,"outside"); \ No newline at end of file diff --git a/forum/skins/default/media/js/osqa.user.js b/forum/skins/default/media/js/osqa.user.js index 4a168a2..6450c3c 100644 --- a/forum/skins/default/media/js/osqa.user.js +++ b/forum/skins/default/media/js/osqa.user.js @@ -1,41 +1,17 @@ - -function show_dialog (html, extra_class, pos, dim, yes, no_text) { - $dialog = $('
' - + '
' + html + '
' - + '' - + '' - + '
'); - - $('body').append($dialog); - - $dialog.css({ - top: pos.y, - left: pos.x - }); - - $dialog.animate({ - top: "-=" + (dim.h / 2), - left: "-=" + (dim.w / 2), - width: dim.w, - height: dim.h - }, 200, function() { - $dialog.find('.dialog-no').click(function() { - $dialog.fadeOut('fast'); - }); - $dialog.find('.dialog-yes').click(function() { - yes.callback($dialog); - }); - }); - -} - - $().ready(function() { var $dropdown = $('#user-menu-dropdown'); $('#user-menu').click(function(){ - $('.dialog').fadeOut('fast'); - $dropdown.slideToggle('fast'); + $('.dialog').fadeOut('fast', function() { + $dialog.remove(); + }); + $dropdown.slideToggle('fast', function() { + if ($dropdown.is(':visible')) { + $dropdown.one('clickoutside', function() { + $dropdown.slideUp('fast') + }); + } + }); }); $('.confirm').each(function() { @@ -43,14 +19,18 @@ $().ready(function() { $link.click(function(e) { $dropdown.slideUp('fast'); - var html = messages.confirm; - show_dialog(html, 'confirm', {x: e.pageX, y: e.pageY}, {w: 200, h: 100}, { - text: messages.yes, - callback: function() { + show_dialog({ + html: messages.confirm, + extra_class: 'confirm', + event: e, + yes_callback: function() { window.location = $link.attr('href'); - } - }, messages.no); + }, + yes_text: messages.yes, + show_no: true, + no_text: messages.no + }); return false; }); @@ -59,31 +39,33 @@ $().ready(function() { $('#award-rep-points').click(function(e) { $dropdown.slideUp('fast'); - var html = '' + var table = '
' + messages.points + '
' + '
' + messages.points + '
' + messages.message + '
'; - show_dialog(html, 'award-rep-points', {x: e.pageX, y: e.pageY}, {w: 300, h: 125}, { - text: messages.award, - callback: function($dialog) { - var $points_input = $('#points-to-award'); - var _points = parseInt($points_input.val()); - - if(!isNaN(_points)) { - $dialog.fadeOut('fast'); - var _message = $('#award-message').val(); - $.post($('#award-rep-points').attr('href'), {points: _points, message: _message}, function(data) { - if (data.success) { - $('#user-reputation').css('background', 'yellow'); - $('#user-reputation').html(data.reputation); - - $('#user-reputation').animate({ backgroundColor: "transparent" }, 1000); - - } - }, 'json') - } - } - }, messages.cancel); - + show_dialog({ + html: table, + extra_class: 'award-rep-points', + event: e, + yes_callback: function($dialog) { + var $points_input = $('#points-to-award'); + var _points = parseInt($points_input.val()); + + if(!isNaN(_points)) { + $dialog.fadeOut('fast'); + var _message = $('#award-message').val(); + $.post($('#award-rep-points').attr('href'), {points: _points, message: _message}, function(data) { + if (data.success) { + $('#user-reputation').css('background', 'yellow'); + $('#user-reputation').html(data.reputation); + + $('#user-reputation').animate({ backgroundColor: "transparent" }, 1000); + + } + }, 'json') + } + }, + show_no: true + }); return false; }); diff --git a/forum/skins/default/media/style/style.css b/forum/skins/default/media/style/style.css index 373b1d5..3084b55 100644 --- a/forum/skins/default/media/style/style.css +++ b/forum/skins/default/media/style/style.css @@ -1371,4 +1371,48 @@ div.comment-tools a:hover { #ask-related-questions { max-height: 150px; overflow-y: auto; +} + +div.dialog { + position: absolute; + background-color: #EEEEEE; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + -moz-box-shadow: 2px 2px 5px #3060A8; + -webkit-box-shadow: 2px 2px 5px #3060A8; +} + +div.dialog .dialog-content { + padding: 12px 12px 37px 12px; +} + +div.dialog .dialog-buttons { + margin: 0px; + height: 25px; + text-align: center; + position: absolute; + bottom: 0px; + left: 0px; + width: 100%; +} + +.dialog-yes, .dialog-no { + margin: 0 3px 5px 3px; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + background-color: #3060A8; + color: white; + height: 20px; + line-height: 20px; + font-weight: bold; + border: 0; +} + +div.dialog.confirm, div.dialog.warning { + text-align: center; +} + +div.dialog.confirm { + font-size: 140%; + font-weight: bold; } \ No newline at end of file diff --git a/forum/skins/default/media/style/user.css b/forum/skins/default/media/style/user.css index 5804226..f4fff84 100644 --- a/forum/skins/default/media/style/user.css +++ b/forum/skins/default/media/style/user.css @@ -11,44 +11,15 @@ color: #3060A8; } -#user-menu-dropdown, div.dialog { +#user-menu-dropdown { position: absolute; - background-color: #B6C4E2; + background-color: #EEEEEE; -moz-border-radius: 5px; -webkit-border-radius: 5px; -moz-box-shadow: 2px 2px 5px #3060A8; -webkit-box-shadow: 2px 2px 5px #3060A8; } -div.dialog .dialog-buttons { - margin: 0px; - height: 25px; - text-align: center; - position: absolute; - bottom: 0px; - left: 0px; - width: 100%; -} - -.dialog-yes, .dialog-no { - margin: 0 3px 5px 3px; - -moz-border-radius: 3px; - -webkit-border-radius: 3px; - background-color: #3060A8; - color: white; - height: 20px; - line-height: 20px; - font-weight: bold; - border: 0; -} - -div.dialog.confirm { - text-align: center; - line-height: 75px; - font-size: 140%; - font-weight: bold; -} - div.dialog.award-rep-points table { margin: auto; margin-top: 8px; diff --git a/forum/skins/default/templates/base.html b/forum/skins/default/templates/base.html index 80eb598..09525b5 100644 --- a/forum/skins/default/templates/base.html +++ b/forum/skins/default/templates/base.html @@ -1,93 +1,23 @@ - - -{% load extra_filters %} -{% load extra_tags %} -{% load i18n %} - - - {% block fulltitle %}{% block title %}{% endblock %} - {{ settings.APP_SHORT_NAME }}{% endblock %} - {% spaceless %} - {% block meta %}{% endblock %} - {% endspaceless %} - - {% if settings.GOOGLE_SITEMAP_CODE %} - - {% endif %} - - - - - - - {% if user_messages %} - - - {% endif %} - {% block forejs %}{% endblock %} +{% extends "base_content.html" %} +{% block page_center %} +
+
+
+ {% block content%} + {% endblock%} - - - {% if settings.GOOGLE_ANALYTICS_KEY %} - - {% endif %} - - - - {% include "header.html" %} -
-
-
- {% block content%} - {% endblock%} - -
-
- {% block sidebar%} - {% endblock%} +
+ {% block sidebar%} + {% endblock%} -
-
- {% block tail %} - {% endblock %} -
-
-
- {% include "footer.html" %} - {% block endjs %} - {% endblock %} - - - +
+ {% block tail %} + {% endblock %} +
+
+
+
+{% endblock %} + diff --git a/forum/skins/default/templates/base_content.html b/forum/skins/default/templates/base_content.html index ea93bce..d1d3bd9 100644 --- a/forum/skins/default/templates/base_content.html +++ b/forum/skins/default/templates/base_content.html @@ -4,16 +4,15 @@ {% load extra_tags %} - {% block title %}{% endblock %} - {{ settings.APP_TITLE }} + {% block fulltitle %}{% block title %}{% endblock %} - {{ settings.APP_SHORT_NAME }}{% endblock %} + {% block meta %}{% endblock %} {% if settings.GOOGLE_SITEMAP_CODE %} {% endif %} - {% spaceless %} {% block forestyle %}{% endblock %} - {% endspaceless %} - + {% if user_messages %} {% endif %} - - {% block forejs %} - {% endblock %} + {% block forejs %}{% endblock %} + {% include "header.html" %} + {% block page_center %}
@@ -66,9 +76,23 @@
+ {% endblock %} {% include "footer.html" %} {% block endjs %} {% endblock %} + {% if settings.GOOGLE_ANALYTICS_KEY %} + + {% endif %} diff --git a/forum/skins/default/templates/node/comments.html b/forum/skins/default/templates/node/comments.html index 571fd24..43b1553 100644 --- a/forum/skins/default/templates/node/comments.html +++ b/forum/skins/default/templates/node/comments.html @@ -47,7 +47,7 @@
{{ min_length }}|{{ max_length }} - {% trans "characters to go" %} + {% trans "characters needed" %} {% trans "characters left" %} diff --git a/forum/skins/default/templates/node/report.html b/forum/skins/default/templates/node/report.html index dbc8630..c8607bb 100644 --- a/forum/skins/default/templates/node/report.html +++ b/forum/skins/default/templates/node/report.html @@ -7,10 +7,7 @@ {% endfor %} - -
- -
+
diff --git a/forum/skins/default/templates/users/menu.html b/forum/skins/default/templates/users/menu.html index 06ff4b3..731ec3a 100644 --- a/forum/skins/default/templates/users/menu.html +++ b/forum/skins/default/templates/users/menu.html @@ -1,19 +1,6 @@ {% load i18n %} {% load smart_if %} - -
{% trans "User tools" %} ▼
    -- 2.45.2