Skip to content

Commit

Permalink
Item12180: First pass at keeping error icons and status line up-to-da…
Browse files Browse the repository at this point in the history
…te with feedback. Section summary counts are not yet right.

git-svn-id: http://svn.foswiki.org/trunk@15920 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Nov 6, 2012
1 parent 113afd0 commit 700ffdf
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 8 deletions.
23 changes: 21 additions & 2 deletions core/lib/Foswiki/Configure/Feedback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ feedback request has been received.
->cleanupTemplateResidues($html);

htmlResponse( $html, 200 );

}

sub _actionfeedbackUI {
Expand Down Expand Up @@ -131,6 +130,7 @@ sub deliver {
$this->{valuer} = $valuer;
$this->{root} = $root;
$this->{fb} = {};
$this->{errors} = {};

# 0 = no other; 1 = only changes; 2 = all
$this->{checkall} = $query->param('DEBUG') ? 2 : 1;
Expand Down Expand Up @@ -172,7 +172,19 @@ sub deliver {
}
}

deliverResponse( $this->{fb}, \%updated );
my $fb = $this->{fb};

# Reduce errors to those that changed and generate updates

for my $key ( keys %{ $this->{errors} } ) {
my $old = $query->param("${key}errors");
$old = "0 0" unless ( defined $old );
my $new = $this->{errors}{$key};
$fb->{"${key}errors"} = $ui->FB_GUIVAL( "${key}errors", $new )
if ( $new ne $old );
}

deliverResponse( $fb, \%updated );
}

sub deliverResponse {
Expand Down Expand Up @@ -239,6 +251,9 @@ sub startVisit {
if ( $visitee->isa('Foswiki::Configure::Value') ) {
my $keys = $visitee->getKeys();

$visitee->{errors} = 0;
$visitee->{warnings} = 0;

# my $value = $this->{valuer}->currentValue($visitee);
if ( $this->{fbpass} ) {

Expand Down Expand Up @@ -283,6 +298,8 @@ sub startVisit {
else {
die ".spec ERROR: No source for specified feedback for $keys\n";
}
$this->{errors}{$keys} = "$visitee->{errors} $visitee->{warnings}";

return 0; # Stop scan
}
else {
Expand Down Expand Up @@ -311,6 +328,8 @@ sub startVisit {
$this->{fb}{$keys} = $check;
}
}
$this->{errors}{$keys} =
"$visitee->{errors} $visitee->{warnings}";
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions core/lib/Foswiki/Configure/UIs/Value.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ qq{$index <span class="configureCheckOnChange"><img src="${Foswiki::resourceURI}
else {
$feedback = '';
}
my ( $itemErrors, $itemWarnings ) =
( ( $value->{errors} || 0 ), ( $value->{warnings} || 0 ) );
$index .= Foswiki::Configure::UI::hidden( "${keys}errors",
"$itemErrors $itemWarnings" );

my $resetToDefaultLinkText = '';
if ( $value->needsSaving( $root->{valuer} ) ) {

Expand Down
136 changes: 131 additions & 5 deletions core/lib/Foswiki/Configure/resources/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ function doFeedback(key, pathinfo) {
KeyIdSelector = '#' + quoteKeyId,
posturl = document.location.pathname, /* Where to post form */
working,
stsWindowId;
stsWindowId,
errorKeyRe = /^\{.*\}errors$/;

/* Add a named item from a form to the POST data */

Expand Down Expand Up @@ -836,6 +837,7 @@ function doFeedback(key, pathinfo) {
ilen,
ctlName,
txt;

if (this.disabled) {
return true;
}
Expand Down Expand Up @@ -871,6 +873,9 @@ function doFeedback(key, pathinfo) {
return true;

case "hidden":
if( errorKeyRe.test(ctlName) && this.value === "0 0" ) {
return true; /* Don't bother sending "no error" values */
} /* Fall into postFormItem */
case "text":
case "password":
postFormItem(ctlName, this.value);
Expand Down Expand Up @@ -995,7 +1000,8 @@ function doFeedback(key, pathinfo) {
newval,
opts,
v,
ii;
ii,
errorsChanged = 0;

/* Clear "working" status in case of errors or updates that don't target
* the original status div. This also updates the class.
Expand Down Expand Up @@ -1091,8 +1097,11 @@ function doFeedback(key, pathinfo) {
}
return true;

case "textarea":
case "hidden":
if( errorKeyRe.test(this.name) ) {
errorsChanged++;
} /* Fall into set value */
case "textarea":
case "text":
case "password":
this.value = newval.join("");
Expand All @@ -1113,9 +1122,126 @@ function doFeedback(key, pathinfo) {
errorMessage("Invalid opcode2 in feedback response");
}
}

/* Responses with just unchanged updates or with no error count
* changes need no more processing.
*/

if( !stsWindowId || !errorsChanged ) {
return true;
}

/* Full response. Scan for {key}{s}errors (now updated) and
* apply classes to the items' tabs/subtabs accordingly.
* This will correct the summary icons.
*/

/* Clear all existing indicators. */

$('ul li a.configureWarn,ul li a.configureError,ul li a.configureWarnAndError').removeClass('configureWarn configureError configureWarnAndError' );

/* Find each item's error value & propagate it upwards. */

var totalErrors = 0,
totalWarnings = 0;

$( '[name$=\\}errors]' ).each(function (index) {
if( this.value === "0 0" ) {
return true;
}
var errors = this.value.split(' ');
if( errors.length !== 2 ) {
return true;
}
errors[0] = parseInt(errors[0],10);
totalErrors += errors[0];
errors[1] = parseInt(errors[1],10);
totalWarnings += errors[1];

var itemClass;

if( (errors[0] !== 0) && (errors[1] !== 0) ) {
itemClass = 'configureWarnAndError';
} else { if (errors[0] !== 0) {
itemClass = 'configureError';
} else {
itemClass = 'configureWarn';
}}
var tab = $( this ).closest('div.configureSubSection');
if( tab.size() == 1 ) {
var tabName = tab.find('a').get(0).name;
var tabNames = tabName.split('$' );

/* Update subtab, if any */
if( tabNames.length === 2 ) {
var subtab = $(tab).closest('div.configureRootSection').find('ul.configureSubTab li a[href="'
+ configure.utils.quoteName('#'
+ tabName ) + '"]' );
if( subtab.size() == 1 ) {
if( !subtab.hasClass( 'configureWarnAndError' ) ) {
if( itemClass === 'configureWarnAndError' ) {
subtab.removeClass('configureError configureWarn').addClass(itemClass);
} else { if( !subtab.hasClass( itemClass ) ) {
subtab.addClass(itemClass);
if( subtab.hasClass('configureWarn')
&& subtab.hasClass('configureError') ) {
subtab.removeClass('configureError configureWarn').addClass('configureWarnAndError');
}
}}
}
}
}
/* Update main navigation tab */
tab = $('ul.configureRootTab li a[href="'
+ configure.utils.quoteName('#'+tabNames[1]) +'"]');
} else {
tab = $( this ).closest('div.configureRootSection');
if( tab.size() == 1 ) {
tabName = tab.find('a').get(0).name;
tab = $('ul.configureRootTab li a[href="'
+ configure.utils.quoteName('#'+tabName) +'"]');
}
}

if( tab.size() == 1 ) {
if( !tab.hasClass( 'configureWarnAndError' ) ) {
if( itemClass === 'configureWarnAndError' ) {
tab.removeClass('configureError configureWarn').addClass(itemClass);
} else { if( !tab.hasClass( itemClass ) ) {
tab.addClass(itemClass);
if( tab.hasClass('configureWarn')
&& tab.hasClass('configureError') ) {
tab.removeClass('configureError configureWarn').addClass('configureWarnAndError');
}
}}
}
}

return true;
}); /* errorItem */

/* Finally, the summary status bar */

var status = 'Status: '
if( totalWarnings || totalErrors ) {
if( totalErrors ) {
status += '<span class="configureStatusErrors">' + totalErrors + " Error";
if( totalErrors !== 1 ) { status += 's' };
status += '</span>';
}
if( totalWarnings ) {
status += '<span class="configureStatusWarnings">' + totalWarnings + " Warning";
if( totalWarnings !== 1 ) { status += 's' };
status += '</span>';
}
} else {
status += '<span class="configureStatusOK">No problems detected</span>';
}
$('#configureErrorSummary').html(status);

return true;
}
});
} /* complete */
}); /* Ajax */

/* Consume the button click */

Expand Down
4 changes: 4 additions & 0 deletions core/lib/Foswiki/Configure/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,16 @@ body.configureShowOneSection .configureNotShowSection {
.configureTools span {
margin:0 0 0 .3em;
}
.configureStatusOK,
.configureStatusWarnings,
.configureStatusErrors {
padding:7px .5em 7px 22px;
background-position:0 45%;
background-repeat:no-repeat;
}
.configureStatusOK {
background-image:url(%RESOURCEURI%icon_ok.png);
}
.configureStatusWarnings {
background-image:url(%RESOURCEURI%icon_warn.png);
}
Expand Down
3 changes: 2 additions & 1 deletion core/lib/Foswiki/Configure/templates/main.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
<div class="configureActions">
<div class="section configureActionsContents">
<div class="foswikiLeft">
<span id="configureErrorSummary">
<#if totalWarnings?? || totalErrors??>Status:</#if>
<#if totalErrors??><span class='configureStatusErrors'>${totalErrors}</span></#if>
<#if totalWarnings??><span class='configureStatusWarnings'>${totalWarnings}</span></#if>
<#if firstTime == 1>(we will solve this in a minute)</#if>

</span>
<input type="hidden" disabled="disabled"
id="configureFeedbackWorkingText"
title="I18n - Not form data"
Expand Down

0 comments on commit 700ffdf

Please sign in to comment.