r103218 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103217‎ | r103218 | r103219 >
Date:20:14, 15 November 2011
Author:rmoen
Status:ok (Comments)
Tags:
Comment:
required inline action reason, added localization
Modified paths:
  • /trunk/extensions/MoodBar/MoodBar.i18n.php (modified) (history)
  • /trunk/extensions/MoodBar/MoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js (modified) (history)
  • /trunk/extensions/MoodBar/modules/ext.moodBar/ext.moodBar.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/MoodBar.i18n.php
@@ -97,6 +97,8 @@
9898 'moodbar-hidden-footer' => 'Hidden Feedback $1',
9999 'moodbar-feedback-restore' => 'restore hidden feedback',
100100 'moodbar-action-item' => 'Feedback item:',
 101+ 'moodbar-action-reason' => 'Reason:',
 102+ 'moodbar-action-reason-required' => 'Please provide a reason.',
101103 'moodbar-hide-header' => 'Hide this item from view',
102104 'moodbar-hide-intro' => '',
103105 'moodbar-restore-header' => "Restore this item's visibility",
Index: trunk/extensions/MoodBar/modules/ext.moodBar/ext.moodBar.core.js
@@ -111,7 +111,6 @@
112112 .localize()
113113 .click( function( e ) {
114114 var $el = $( this );
115 - //mb.ui.overlay.find( '.mw-moodBar-formSubmit').removeAttr('disabled');
116115 mb.ui.overlay.find( '.mw-moodBar-formInput' ).focus();
117116 $mwMoodBarTypes.addClass( 'mw-moodBar-types-select' );
118117 mb.feedbackItem.type = $el.attr( 'rel' );
Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
@@ -249,16 +249,17 @@
250250 }
251251
252252 /**
253 - * Do this before administrative action
 253+ * Do this before administrative action to provide reason
254254 */
255255 function beforeAction(params, $item){
256 - var inlineForm = $('<span class="fbd-item-reason">\
257 - Reason\
 256+ var inlineForm = '<span class="fbd-item-reason">\
 257+ $1\
258258 <input class="fbd-action-reason" name="fb-action-reason" />\
259259 <button class="fbd-action-confirm">Confirm</button>\
260260 <button class="fbd-action-cancel">Cancel</button>\
261 - </span>');
262 -
 261+ </span>'
 262+ .replace( /\$1/g, mw.msg( 'moodbar-action-reason' ));
 263+
263264 var storedParams = params;
264265 var $storedItem = $item;
265266
@@ -268,9 +269,16 @@
269270 $item.find('.fbd-item-message')
270271 .append(inlineForm)
271272 .end();
 273+
 274+ $('.fbd-action-confirm').click( function() {
 275+ storedParams.reason = $item.find('.fbd-action-reason').val();
272276
273 - $('.fbd-action-confirm').click( function() {
274 - doAction(storedParams, $storedItem);
 277+ if( storedParams.reason ) {
 278+ doAction(storedParams, $storedItem);
 279+ } else {
 280+ alert( mw.msg( 'moodbar-action-reason-required' ) );
 281+ }
 282+
275283 });
276284 $('.fbd-action-cancel').click( function() {
277285 reloadItem( $storedItem, true );
@@ -288,9 +296,6 @@
289297 showItemError( $item, error_str );
290298 };
291299
292 - //var reason = prompt("Reason for this action?");
293 - var reason = $item.find('.fbd-action-reason').val();
294 -
295300 var $spinner = $('<span class="mw-ajax-loader">&nbsp;</span>');
296301 $item.find('.fbd-item-hide').empty().append( $spinner );
297302
@@ -324,7 +329,6 @@
325330 function restoreItem(e) {
326331 var $item = $(this).closest('.fbd-item');
327332
328 - //doAction( { 'mbaction' : 'restore' }, $item );
329333 beforeAction( { 'mbaction' : 'restore' }, $item );
330334 e.preventDefault();
331335 }
@@ -334,11 +338,7 @@
335339 */
336340 function hideItem(e) {
337341 var $item = $(this).closest('.fbd-item');
338 -
339 - //var $spinner = $('<span class="mw-ajax-loader">&nbsp;</span>');
340 - //$item.find('.fbd-item-hide').empty().append( $spinner );
341 -
342 - //doAction( { 'mbaction' : 'hide' }, $item );
 342+
343343 beforeAction( { 'mbaction' : 'hide' }, $item );
344344 e.preventDefault();
345345 }
Index: trunk/extensions/MoodBar/MoodBar.php
@@ -149,6 +149,8 @@
150150 'moodbar-feedback-noresults',
151151 'moodbar-feedback-ajaxerror',
152152 'moodbar-feedback-action-error',
 153+ 'moodbar-action-reason',
 154+ 'moodbar-action-reason-required'
153155 ),
154156 );
155157

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r103112added reason prompt when admin hides or restores a commentrmoen01:24, 15 November 2011
r103209revised admin reason to be inline, with cancel / confirm buttonrmoen18:56, 15 November 2011

Comments

#Comment by Raindrift (talk | contribs)   00:23, 16 November 2011

FWIW, instead of doing the '$1'.replace(etc), you can use jQuery to make the entire HTML entity, and skip the regexp step. It's cleaner, but I think this is acceptable.

#Comment by Robmoen (talk | contribs)   08:05, 16 November 2011

Thanks, I will do that instead. I was trying to match existing code for MoodBar. I agree though, and I go forward with this in mind.

#Comment by Catrope (talk | contribs)   10:59, 16 November 2011

For larger quantities of HTML you can also use the jquery.localize module:

var html = '<div>\
        <span>\
                <a><html:msg key="moodbar-foo" /></a>\
        </span>\
</div>';
$bar.append( $( html ).localize() );

Status & tagging log