Skip to content

Commit

Permalink
Item12180: POST optimizations. Skip window.history where unsupported …
Browse files Browse the repository at this point in the history
…(for now). Cleanup after variable renaming.

git-svn-id: http://svn.foswiki.org/trunk@15925 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Nov 6, 2012
1 parent 4db853e commit 5deb136
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 46 deletions.
5 changes: 3 additions & 2 deletions core/lib/Foswiki/Configure/UI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,15 @@ HTML encodes the value
=cut
sub hidden {
my ( $name, $value ) = @_;
my ( $name, $value, $disabled ) = @_;
$disabled = $disabled ? ' disabled="disabled"' : '';
$name ||= '';
$name =~ s/([[\x01-\x09\x0b\x0c\x0e-\x1f"%&'*<=>@[_\|])/
'&#'.ord($1).';'/ge;
$value ||= '';
$value =~ s/([[\x01-\x09\x0b\x0c\x0e-\x1f"%&'*<=>@[_\|])/
'&#'.ord($1).';'/ge;
return "<input type='hidden' name='$name' value='$value' />";
return "<input type='hidden' name='$name' value='$value'$disabled />";
}
=begin TML
Expand Down
7 changes: 5 additions & 2 deletions core/lib/Foswiki/Configure/UIs/Value.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ qq{$index <span class="configureCheckOnChange"><img src="${Foswiki::resourceURI}
}
my ( $itemErrors, $itemWarnings ) =
( ( $value->{errors} || 0 ), ( $value->{warnings} || 0 ) );
$index .= Foswiki::Configure::UI::hidden( "${keys}errors",
"$itemErrors $itemWarnings" );
$index .= Foswiki::Configure::UI::hidden(
"${keys}errors",
"$itemErrors $itemWarnings",
!( $itemErrors + $itemWarnings )
);

my $resetToDefaultLinkText = '';
if ( $value->needsSaving( $root->{valuer} ) ) {
Expand Down
93 changes: 51 additions & 42 deletions core/lib/Foswiki/Configure/resources/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,19 @@ var configure = (function ($) {
setSub(mainId, subId);

if (mainId || subId) {
if (subId !== undefined) {
subName = subId.split("$")[1];
window.history.pushState(undefined, "Configure / " + mainId + " / " + subName, url + "#" + subId);
} else if (mainId !== undefined) {
window.history.pushState(undefined, "Configure / " + mainId, url + "#$" + mainId);
} else {
window.history.pushState(undefined, "Configure", url);
/* IE doesn't do window.history. https://github.com/balupton/history.js is an alternative,
* but it comes it a lot of baggage. For now, just skip this for browsers that don't support
* window.history.
*/
if( window.history ) {
if (subId !== undefined) {
subName = subId.split("$")[1];
window.history.pushState(undefined, "Configure / " + mainId + " / " + subName, url + "#" + subId);
} else if (mainId !== undefined) {
window.history.pushState(undefined, "Configure / " + mainId, url + "#$" + mainId);
} else {
window.history.pushState(undefined, "Configure", url);
}
}
}

Expand Down Expand Up @@ -559,7 +565,7 @@ configure.utils = (function () {
out = '',
i,
c;
for (i = 0; i < name.length; i = i + 1) {
for (i = 0; i < name.length; i++) {
c = instr[i];
if ("!\"#$%&'()*+,./:;<=>?@[\\]^`{|} ~".indexOf(c) >= 0) {
out = out + '\\' + (c === ':' ? '\\3a' : c);
Expand Down Expand Up @@ -605,7 +611,7 @@ function resetToDefaultValue(inLink, inFormType, inName, inValue) {
elem.checked = value;
} else if (type === 'select-one') {
/* find selected element */
for (i = 0; i < elem.options.length; i = i + 1) {
for (i = 0; i < elem.options.length; i++) {
if (elem.options[i].value === value) {
index = i;
break;
Expand Down Expand Up @@ -709,7 +715,7 @@ function valueChanged(el) {
j,
ct;
$(this).removeClass('foswikiHidden');
for (j = 0; j < jlen; j = j + 1) {
for (j = 0; j < jlen; j++) {
ct = 'foswiki' + controlTypes[j];
if ($(this).hasClass(ct + 'Disabled')) {
$(this).removeClass(ct + 'Disabled');
Expand Down Expand Up @@ -983,7 +989,7 @@ function doFeedback(key, pathinfo) {
/* Select sends the value of each selected option */
opts = this.options;
ilen = opts.length;
for (i = 0; i < ilen; i = i + 1) {
for (i = 0; i < ilen; i++) {
if (opts[i].selected && !opts[i].disabled) {
postFormItem(ctlName, opts[i].value);
}
Expand All @@ -997,12 +1003,6 @@ 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 */
}
postFormItem(ctlName, this.value);
return true;

case "text":
case "password":
postFormItem(ctlName, this.value);
Expand Down Expand Up @@ -1035,6 +1035,7 @@ function doFeedback(key, pathinfo) {
/* Update message area with busy status. I18n note: hidden disabled field in pagebegin.tmpl with desired
* text for internationalization. E.g. <input type="hidden" disabled="disabled"
* id="configureFeedbackWorkingText" value="Nous travaillons sur votre demande...">
* status updates do not provide busy status, and !stsWindowId indicates a status update.
*/

if( key.id !== '{ConfigureGUI}{Unsaved}status' ) {
Expand Down Expand Up @@ -1118,16 +1119,16 @@ function doFeedback(key, pathinfo) {
}

var data = xhr.responseText,
item,
items,
i,
kpair,
kpair = [],
sloc,
delims,
d,
newval,
opts,
v,
ii,
eleDisabled,
errorsChanged = 0;

/* Clear "working" status in case of errors or updates that don't target
Expand All @@ -1153,20 +1154,19 @@ function doFeedback(key, pathinfo) {
/* Hex constants used rather than octal for JSLint issue. */

items = data.split("\x01");
for (i = 0; i < items.length; i = i + 1) {
for (item = 0; item < items.length; item++) {
/* IE sometimes doesn't do capturing split, so simulate one. */
kpair = [];
delims = ["\x02", "\x03"];
for (d = 0; d < delims.length; d = d + 1) {
sloc = items[i].indexOf(delims[d]);
for (i = 0; i < delims.length; i++) {
sloc = items[item].indexOf(delims[i]);
if (sloc >= 0) {
kpair[0] = items[i].substr(0, sloc);
kpair[1] = delims[d];
kpair[2] = items[i].substr(sloc + 1);
kpair[0] = items[item].substr(0, sloc);
kpair[1] = delims[i];
kpair[2] = items[item].substr(sloc + 1);
break;
}
}
if (d >= delims.length) {
if (i >= delims.length) {
errorMessage("Invalid opcode in feedback response");
return true;
}
Expand All @@ -1175,19 +1175,21 @@ function doFeedback(key, pathinfo) {
} else if (kpair[1] === "\x03") {
newval = kpair[2].split(/\x04/);
$('[name="' + configure.utils.quoteName(kpair[0]) + '"]').each(function (idx, ele) {
eleDisabled = this.disabled;
this.disabled = false;
switch (this.type.toLowerCase()) {
/* Ignore these for now (why update labels?) */
case "button":
case "file":
case "submit":
case "reset":
return true;
break;

case "select-one":
opts = this.options;
var selected = -1;

for (i = 0; i < opts.length; i = i + 1) {
for (i = 0; i < opts.length; i++) {
if (opts[i].value === newval[0]) {
opts[i].selected = true;
this.selectedIndex = i;
Expand All @@ -1199,21 +1201,21 @@ function doFeedback(key, pathinfo) {
if (selected < 0) {
errorMessage("Invalid value \"" + newval[0] + "\" for " + kpair[0]);
}
return true;
break;

case "select-multiple":
opts = this.options;

for (i = 0; i < opts.length; i = i + 1) {
for (i = 0; i < opts.length; i++) {
opts[i].selected = false;
}
this.selectedIndex = -1;
for (v = 0; v < newval.length; v = v + 1) {
for (ii = 0; ii < opts.length; ii = ii + 1) {
if (opts[ii].value === newval[v]) {
opts[ii].selected = true;
for (v = 0; v < newval.length; v++) {
for (i = 0; i < opts.length; i++) {
if (opts[i].value === newval[v]) {
opts[i].selected = true;
if (v === 0) {
this.selectedIndex = ii;
this.selectedIndex = i;
}
break;
}
Expand All @@ -1222,28 +1224,35 @@ function doFeedback(key, pathinfo) {
errorMessage("Invalid value \"" + newval[v] + "\" for " + kpair[0]);
}
}
return true;
break;

case "hidden":
v = newval.join("");
if( errorKeyRe.test(this.name) ) {
errorsChanged++;
if( v === "0 0" ) {
eleDisabled = true; /* Do not POST */
} else {
eleDisabled = false;
}
}
this.value = newval.join("");
return true;
this.value = v;
break;

case "textarea":
case "text":
case "password":
this.value = newval.join("");
return true;
break;

case "radio":
case "checkbox":
this.checked = configure.utils.isTrue(newval[0]);
return true;
break;
default:
break;
}
this.disabled = eleDisabled;
/* Ignore all other controls */
return true;
});
Expand Down

0 comments on commit 5deb136

Please sign in to comment.