Skip to content

Commit

Permalink
Item12180: More status updates. Make javascript responsible for initi…
Browse files Browse the repository at this point in the history
…al status. Add warning to Save if outstanding issues. Fix messages. Add FB_GUIVAL(). Handle firstTime in javascript. Look higher for subtabs to update.

git-svn-id: http://svn.foswiki.org/trunk@15924 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Nov 6, 2012
1 parent 199e130 commit 4db853e
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 148 deletions.
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Configure/FoswikiCfg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,9 @@ HERE
my $n = pop @backups;
unlink "$lsc.$n";
}
$msg = "<br />Previous configuration saved as $backup\n";
$msg = "<br />Previous configuration saved in $backup\n";
}
$msg = "Wrote new configuration to $lsc\n$msg";
$msg = "New configuration saved in $lsc\n$msg";
}
else {
unlink $backup if ($backup);
Expand Down
13 changes: 13 additions & 0 deletions core/lib/Foswiki/Configure/MainScreen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@ sub _screenAuthorize {

my $changePassword = $Foswiki::query->param('changePassword') || undef;

my ( $errors, $warnings ) = (0) x 2;
for my $param ( $Foswiki::query->param ) {
next unless ( $param =~ /^\{.*\}errors$/ );
my $value = $Foswiki::query->param($param);
if ( $value =~ /^(\d+) (\d+)$/ ) {
$errors += $1;
$warnings += $2;
}
}

# Used in form templates to control content:
# displayStatus - 1 = No Changes, 2 = Changes, 4 = No Extensions, 8 = Extensions, 16 = Email Test, 32 = Login

Expand All @@ -587,6 +597,9 @@ sub _screenAuthorize {
'extRemoveCount' => 0,
'extAddItems' => [],
'extRemoveItems' => [],
'totalErrors' => $errors,
'totalWarnings' => $warnings,
'someProblems' => $errors + $warnings,
);
dispatch( '_screenAuth', $transact, \&invalidDispatch, \%args );

Expand Down
15 changes: 15 additions & 0 deletions core/lib/Foswiki/Configure/UI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,21 @@ sub FB_VALUE {
=begin TML
---++ ObjectMethod FB_GUIVAL(...)
Like FB_VALUE, but for GUI items. Key needn't exist.
=cut
sub FB_GUIVAL {
my $this = shift;
my $keys = shift;
return "\001$keys\003" . join( "\004", @_ );
}
=begin TML
---++ ObjectMethod hidden($value) -> $html
Used in place of CGI::hidden, which is broken in some CGI versions.
HTML encodes the value
Expand Down
26 changes: 6 additions & 20 deletions core/lib/Foswiki/Configure/UIs/Section.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,12 @@ sub renderHtml {

my $outText = '';
if ( $depth == 1 ) {
my $totalWarningsText;
if ($Foswiki::Configure::UI::totwarnings) {
$totalWarningsText =
$Foswiki::Configure::UI::totwarnings . ' '
. (
$Foswiki::Configure::UI::totwarnings == 1
? 'warning'
: 'warnings'
);
}
my $totalErrorsText;
if ($Foswiki::Configure::UI::toterrors) {
$totalErrorsText =
$Foswiki::Configure::UI::toterrors . ' '
. (
$Foswiki::Configure::UI::toterrors == 1 ? 'error' : 'errors' );
}
my $isFirstTime = $Foswiki::Configure::UI::firsttime || 0;
my $isFirstTime = (
$Foswiki::Configure::UI::firsttime
&& ( $Foswiki::Configure::UI::totwarnings
|| $Foswiki::Configure::UI::toterrors )
)
|| 0;

$outText =
Foswiki::Configure::UI::getTemplateParser()->readTemplate('main');
Expand All @@ -123,8 +111,6 @@ sub renderHtml {
{
'navigation' => $navigation,
'contents' => $contents,
'totalWarnings' => $totalWarningsText,
'totalErrors' => $totalErrorsText,
'firstTime' => $isFirstTime,
'unsavedNotice' => $Foswiki::unsavedChangesNotice,
}
Expand Down
251 changes: 135 additions & 116 deletions core/lib/Foswiki/Configure/resources/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,128 @@ var configure = (function ($) {

contents = $('.configureDefaultValueLinkValue', link)[0];
$(contents).html(template);
},

/* Update the tab summary icons and status summary line from the item error values.
* Each item has a corresponding (key){s}errors hidden value, containing the item's
* error and warning counts. These are initally set with checker results with the
* main page is built, and updated when changed by feedback. updateIndicators
* pushes the values up to the tabs and status line, mostly by adjusting classes.
*/

updateIndicators: function () {
/* Clear all existing indicators.
* This finds all tab links with error classes and removes them.
*/

$('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,
itemClass,
tab,
tabName,
tabNames,
subTab,
statusLine;

$( '[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];

/* Select this item's contribution to the tab's classes */

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

/* Update subtab, if any */
if( tabNames.length === 2 ) {
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 */

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

};
Expand Down Expand Up @@ -544,7 +666,8 @@ var showWhenNothingChangedElements = [];

var unsaved = { id:'{ConfigureGUI}{Unsaved}status', value:'Not a button' },
statusTimer = undefined,
statusDeferred = false;
statusDeferred = false,
errorKeyRe = /^\{.*\}errors$/;

/*
Global fuction
Expand Down Expand Up @@ -717,6 +840,8 @@ $(document).ready(function () {
});
});

configure.updateIndicators();

// make sticky
$('.navigation').affix({
offset: {
Expand Down Expand Up @@ -765,8 +890,7 @@ function doFeedback(key, pathinfo) {
KeyIdSelector = '#' + quoteKeyId,
posturl = document.location.pathname, /* Where to post form */
working,
stsWindowId,
errorKeyRe = /^\{.*\}errors$/;
stsWindowId;

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

Expand Down Expand Up @@ -875,7 +999,10 @@ function doFeedback(key, pathinfo) {
case "hidden":
if( errorKeyRe.test(ctlName) && this.value === "0 0" ) {
return true; /* Don't bother sending "no error" values */
} /* Fall into postFormItem */
}
postFormItem(ctlName, this.value);
return true;

case "text":
case "password":
postFormItem(ctlName, this.value);
Expand Down Expand Up @@ -1126,122 +1253,14 @@ function doFeedback(key, pathinfo) {
}
}

/* Responses with just unchanged updates or with no error count
* changes need no more processing.
/* Responses with just unsaved items updates or with no error count
* changes need no more processing. Otherwise, update the indicators.
*/

if( !stsWindowId || !errorsChanged ) {
return true;
if( stsWindowId && errorsChanged ) {
configure.updateIndicators();
}

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

return true;
} /* complete */
}); /* Ajax */
Expand Down
Loading

0 comments on commit 4db853e

Please sign in to comment.