From d4a75fd58381f2964607a2937946202e34cb6f30 Mon Sep 17 00:00:00 2001 From: Zarino Zappia Date: Thu, 21 Apr 2016 13:39:44 +0100 Subject: Improve in-place moderation UI This rearranges the moderation UI into logical chunks, and improves the 'revert to original' checkboxes by: - hiding them unless there's some original text to revert to - displaying the text that will be reverted to in the appropriate input fields when checked. Part of mysociety/FixMyStreet-Commercial#731 --- perllib/FixMyStreet/App/Controller/Report.pm | 11 +++ templates/web/base/report/_main.html | 115 +++++++++++++------------ templates/web/oxfordshire/report/_main.html | 123 ++++++++++++++------------- web/cobrands/sass/_base.scss | 12 +++ web/js/moderate.js | 13 ++- 5 files changed, 156 insertions(+), 118 deletions(-) diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 475a29fb5..b3e546c2c 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -130,6 +130,17 @@ sub load_problem_or_display_error : Private { } $c->stash->{problem} = $problem; + if ( $c->user_exists && $c->user->has_permission_to(moderate => $problem->bodies_str) ) { + $c->stash->{problem_original} = $problem->find_or_new_related( + moderation_original_data => { + title => $problem->title, + detail => $problem->detail, + photo => $problem->photo, + anonymous => $problem->anonymous, + } + ); + } + return 1; } diff --git a/templates/web/base/report/_main.html b/templates/web/base/report/_main.html index 7260e619a..efff314f8 100644 --- a/templates/web/base/report/_main.html +++ b/templates/web/base/report/_main.html @@ -1,61 +1,40 @@ [% moderating = c.user && c.user.has_permission_to('moderate', problem.bodies_str) %] -[% IF moderating %] -[%# TODO: extract stylesheet! %] - -[% END %] -
+ [% IF moderating %] - [% original = problem.moderation_original_data %] + [% original = problem_original %]
- -
- - -
- - - [% IF problem.photo or original.photo %] -
- - - [% END %] -
+

+ +

[% END %] +

[% problem.title | html %]

- [% IF moderating %] + + [% IF moderating %]
- [% IF problem.title != original.title %] - - - [% END %] -

+ [% IF problem.title != original.title %] + + [% END %] +

- [% END %] + [% END %] +
+ +

[% problem.meta_line(c) | html %] [%- IF !problem.used_map %]; ([% loc('there is no pin shown as the user did not use the map') %])[% END %]

+ [% IF problem.bodies_str %] [% INCLUDE 'report/_council_sent_info.html' %] [% ELSE %] @@ -67,26 +46,50 @@ [% INCLUDE 'report/_support.html' %] + [% IF moderating %] + [% IF problem.photo or original.photo %] +

+ +

+ [% END %] + [% END %] + [% INCLUDE 'report/photo.html' object=problem %]
[% add_links( problem.detail ) | html_para %]
- [% IF moderating %] -
- [% IF problem.detail != original.detail %] - - - [% END %] - -
+ [% IF moderating %] +

+ [% IF problem.detail != original.detail %] + + [% END %] + +

-
+
+

+ +

+

- - -

+

+

+ + +

+
+
[% END %]
diff --git a/templates/web/oxfordshire/report/_main.html b/templates/web/oxfordshire/report/_main.html index a4cb3e20b..2ff193075 100644 --- a/templates/web/oxfordshire/report/_main.html +++ b/templates/web/oxfordshire/report/_main.html @@ -1,61 +1,40 @@ [% moderating = c.user && c.user.has_permission_to('moderate', problem.bodies_str) %] -[% IF moderating %] -[%# TODO: extract stylesheet! %] - -[% END %] -
+ [% IF moderating %] - [% original = problem.moderation_original_data %] + [% original = problem_original %]
- -
- - -
- - - [% IF problem.photo or original.photo %] -
- - - [% END %] -
+

+ +

[% END %] +

[% problem.title | html %]

- [% IF moderating %] + + [% IF moderating %]
- [% IF problem.title != original.title %] - - - [% END %] -

+ [% IF problem.title != original.title %] + + [% END %] +

- [% END %] + [% END %] +
+ +

[% problem.meta_line(c) | html %] [%- IF !problem.used_map %]; ([% loc('there is no pin shown as the user did not use the map') %])[% END %]

+ [% IF problem.whensent %]

[% problem.duration_string(c) %]

[% END %] @@ -65,34 +44,58 @@ [% INCLUDE 'report/_support.html' %] + [% IF moderating %] + [% IF problem.photo or original.photo %] +

+ +

+ [% END %] + [% END %] + [% INCLUDE 'report/photo.html' object=problem %]
[% add_links( problem.detail ) | html_para %]
- [% IF moderating %] -
- [% IF problem.detail != original.detail %] - - - [% END %] - -
+ [% IF moderating %] +

+ [% IF problem.detail != original.detail %] + + [% END %] + +

-
+
+

+ +

+

- - -

+

+

+ + +

+
+
[% END %] [% IF problem.bodies_str %] - [% INCLUDE 'report/_council_sent_info.html' %] + [% INCLUDE 'report/_council_sent_info.html' %] [% ELSE %] -
-

[% loc('Not reported to council') %]

-
+
+

[% loc('Not reported to council') %]

+
[% END %]
diff --git a/web/cobrands/sass/_base.scss b/web/cobrands/sass/_base.scss index 6af6d88ff..a8f6e7a96 100644 --- a/web/cobrands/sass/_base.scss +++ b/web/cobrands/sass/_base.scss @@ -1048,6 +1048,18 @@ input.final-submit { } } +.moderate-edit { + display: none; // gets shown by javascript + + :disabled { + background: #ddd; + } + + h1 input { + border-width: (0.125em/2); // compensate for 2em font-size on h1s + } +} + // map stuff #map_box{ @extend .full-width; diff --git a/web/js/moderate.js b/web/js/moderate.js index 0be3cca8d..53277d9d9 100644 --- a/web/js/moderate.js +++ b/web/js/moderate.js @@ -1,3 +1,11 @@ +function toggle_original ($input, revert) { + $input.prop('disabled', revert); + if (revert) { + $input.data('currentValue', $input.val()); + } + $input.val($input.data(revert ? 'originalValue' : 'currentValue')); +} + function setup_moderation (elem, word) { elem.each( function () { @@ -8,10 +16,11 @@ function setup_moderation (elem, word) { }); $elem.find('.revert-title').change( function () { - $elem.find('input[name=problem_title]').prop('disabled', $(this).prop('checked')); + toggle_original($elem.find('input[name=problem_title]'), $(this).prop('checked')); }); + $elem.find('.revert-textarea').change( function () { - $elem.find('textarea').prop('disabled', $(this).prop('checked')); + toggle_original($elem.find('textarea'), $(this).prop('checked')); }); var hide_document = $elem.find('.hide-document'); -- cgit v1.2.3