Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reformat with spaces

  • Loading branch information...
commit 539c01c8b60be30cc662d1c4885a74f474d59017 1 parent 33a4601
@hlship authored
View
322 tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx-multiselect.js
@@ -1,205 +1,205 @@
-T5.extendInitializers(function() {
-
- function setupButton(select, button, callback) {
- var enabled = false;
-
- function updateButton() {
- var newEnabled = select.selectedIndex >= 0;
-
- if (enabled != newEnabled) {
- enabled = newEnabled;
-
- if (enabled)
- button.removeClassName("tx-disabled");
- else
- button.addClassName("tx-disabled");
- }
- }
-
- select.observe("change", updateButton);
- select.observe("tapx:refreshbuttonstate", updateButton);
-
- function callbackIfEnabled() {
- if (enabled)
- callback();
- }
-
- button.observe("click", callbackIfEnabled);
-
- select.observe("dblclick", callbackIfEnabled);
- }
-
- function moveOption(option, to) {
-
- var before = $A(to.options).detect(function(targetOption) {
- return targetOption.innerHTML > option.innerHTML;
- });
-
- if (Prototype.IE) {
- if (before == null) {
- to.add(option);
- } else {
- to.add(option, before.index);
- }
-
- return;
- }
+T5.extendInitializers(function () {
+
+ function setupButton(select, button, callback) {
+ var enabled = false;
+
+ function updateButton() {
+ var newEnabled = select.selectedIndex >= 0;
+
+ if (enabled != newEnabled) {
+ enabled = newEnabled;
+
+ if (enabled)
+ button.removeClassName("tx-disabled");
+ else
+ button.addClassName("tx-disabled");
+ }
+ }
+
+ select.observe("change", updateButton);
+ select.observe("tapx:refreshbuttonstate", updateButton);
+
+ function callbackIfEnabled() {
+ if (enabled)
+ callback();
+ }
+
+ button.observe("click", callbackIfEnabled);
+
+ select.observe("dblclick", callbackIfEnabled);
+ }
+
+ function moveOption(option, to) {
+
+ var before = $A(to.options).detect(function (targetOption) {
+ return targetOption.innerHTML > option.innerHTML;
+ });
- to.add(option, before);
- }
+ if (Prototype.IE) {
+ if (before == null) {
+ to.add(option);
+ } else {
+ to.add(option, before.index);
+ }
- function moveOptions(movers, to) {
- movers.each(function(option) {
- moveOption(option, to);
- });
- }
+ return;
+ }
- function deselectAllOptions(select) {
- $A(select.options).each(function(option) {
- option.selected = false;
- });
- }
+ to.add(option, before);
+ }
- function removeSelectedOptions(select) {
- var movers = [];
- var options = select.options;
+ function moveOptions(movers, to) {
+ movers.each(function (option) {
+ moveOption(option, to);
+ });
+ }
- for ( var i = select.selectedIndex; i < select.length; i++) {
- var option = options[i];
- if (option.selected) {
- select.remove(i--);
- movers.push(option);
- }
- }
+ function deselectAllOptions(select) {
+ $A(select.options).each(function (option) {
+ option.selected = false;
+ });
+ }
- return movers;
- }
+ function removeSelectedOptions(select) {
+ var movers = [];
+ var options = select.options;
- function transferOptions(from, to) {
- deselectAllOptions(to);
- moveOptions(removeSelectedOptions(from), to);
- from.fire("tapx:refreshbuttonstate");
- to.fire("tapx:refreshbuttonstate");
- }
+ for (var i = select.selectedIndex; i < select.length; i++) {
+ var option = options[i];
+ if (option.selected) {
+ select.remove(i--);
+ movers.push(option);
+ }
+ }
- // Re. "Modalbox" vs. "Lightbox". Modalbox is a specific implementation of
- // the general Lightbox design; we may swap out Modalbox for some other
- // Lightbox implementation, given how awkward it is to use with Tapestry.
+ return movers;
+ }
- function lightbox(title, contentURL) {
+ function transferOptions(from, to) {
+ deselectAllOptions(to);
+ moveOptions(removeSelectedOptions(from), to);
+ from.fire("tapx:refreshbuttonstate");
+ to.fire("tapx:refreshbuttonstate");
+ }
- function updateLightboxFromReply(reply) {
- var inits = reply.inits;
- reply.inits = null;
+ // Re. "Modalbox" vs. "Lightbox". Modalbox is a specific implementation of
+ // the general Lightbox design; we may swap out Modalbox for some other
+ // Lightbox implementation, given how awkward it is to use with Tapestry.
- Modalbox.show(reply.content, {
- title : title,
- autoFocusing : false,
- afterLoad : function() {
- Tapestry.executeInits(inits);
- },
- afterUpdate : function() {
- Modalbox.resizeToContent();
- }
- });
- }
+ function lightbox(title, contentURL) {
- // Been experimenting with running the Modalbox loading animation in parallel
- // with doing the Ajax, but Modalbox is a twisted singleton that causes some
- // bad timing issues. Back to just running the (quick) Ajax request and then running
- // the Modalbox animation.
-
- Tapestry.ajaxRequest(contentURL, function(transport) {
- var reply = transport.responseJSON;
+ function updateLightboxFromReply(reply) {
+ var inits = reply.inits;
+ reply.inits = null;
- updateLightboxFromReply(reply);
- });
- }
+ Modalbox.show(reply.content, {
+ title: title,
+ autoFocusing: false,
+ afterLoad: function () {
+ Tapestry.executeInits(inits);
+ },
+ afterUpdate: function () {
+ Modalbox.resizeToContent();
+ }
+ });
+ }
- function initializer(spec) {
- var availableSelect = $(spec.clientId);
- var outerDiv = availableSelect.up(".tx-multiselect");
+ // Been experimenting with running the Modalbox loading animation in parallel
+ // with doing the Ajax, but Modalbox is a twisted singleton that causes some
+ // bad timing issues. Back to just running the (quick) Ajax request and then running
+ // the Modalbox animation.
- var hidden = outerDiv.down("input[type='hidden']");
+ Tapestry.ajaxRequest(contentURL, function (transport) {
+ var reply = transport.responseJSON;
- var selectedSelect = outerDiv.down(".tx-selected select");
+ updateLightboxFromReply(reply);
+ });
+ }
- (spec.model || []).each(function(row) {
+ function initializer(spec) {
+ var availableSelect = $(spec.clientId);
+ var outerDiv = availableSelect.up(".tx-multiselect");
- var valueId = row[0];
- var selected = (spec.values || []).include(valueId);
- var selectElement = selected ? selectedSelect : availableSelect;
+ var hidden = outerDiv.down("input[type='hidden']");
- var option = new Element("option").update(row[1].escapeHTML());
+ var selectedSelect = outerDiv.down(".tx-selected select");
- option.txClientValue = valueId;
+ (spec.model || []).each(function (row) {
- selectElement.insert(option);
- });
+ var valueId = row[0];
+ var selected = (spec.values || []).include(valueId);
+ var selectElement = selected ? selectedSelect : availableSelect;
- function rebuildHiddenFieldValue() {
- // First array is the list of selected values (for values
- // defined by the model at initial render). Second array is the list
- // of selected labels (for values added on the client)
+ var option = new Element("option").update(row[1].escapeHTML());
- var hiddenFieldValue = [];
+ option.txClientValue = valueId;
- $A(selectedSelect.options).each(function(option) {
- hiddenFieldValue.push(option.txClientValue);
- });
+ selectElement.insert(option);
+ });
- hidden.value = Object.toJSON(hiddenFieldValue);
- }
+ function rebuildHiddenFieldValue() {
+ // First array is the list of selected values (for values
+ // defined by the model at initial render). Second array is the list
+ // of selected labels (for values added on the client)
- rebuildHiddenFieldValue();
+ var hiddenFieldValue = [];
- setupButton(availableSelect, outerDiv.down(".tx-select"), function() {
- transferOptions(availableSelect, selectedSelect);
- rebuildHiddenFieldValue();
+ $A(selectedSelect.options).each(function (option) {
+ hiddenFieldValue.push(option.txClientValue);
+ });
- });
+ hidden.value = Object.toJSON(hiddenFieldValue);
+ }
- setupButton(selectedSelect, outerDiv.down(".tx-deselect"), function() {
- transferOptions(selectedSelect, availableSelect);
- rebuildHiddenFieldValue();
- });
+ rebuildHiddenFieldValue();
- outerDiv.down(".tx-input button").observe("click", function(event) {
- event.stop();
+ setupButton(availableSelect, outerDiv.down(".tx-select"), function () {
+ transferOptions(availableSelect, selectedSelect);
+ rebuildHiddenFieldValue();
- lightbox(event.element().innerHTML, spec.newValueURL);
- });
+ });
- $(spec.clientId).observe("tapx:multiselect:newvalue", function(event) {
+ setupButton(selectedSelect, outerDiv.down(".tx-deselect"), function () {
+ transferOptions(selectedSelect, availableSelect);
+ rebuildHiddenFieldValue();
+ });
- var option = event.memo;
- option.selected = true;
+ outerDiv.down(".tx-input button").observe("click", function (event) {
+ event.stop();
- deselectAllOptions(selectedSelect);
+ lightbox(event.element().innerHTML, spec.newValueURL);
+ });
- moveOption(option, selectedSelect);
+ $(spec.clientId).observe("tapx:multiselect:newvalue", function (event) {
- availableSelect.fire("tapx:refreshbuttonstate");
- selectedSelect.fire("tapx:refreshbuttonstate");
+ var option = event.memo;
+ option.selected = true;
- selectedSelect.focus();
+ deselectAllOptions(selectedSelect);
- rebuildHiddenFieldValue();
- });
- }
+ moveOption(option, selectedSelect);
- function newValue(spec) {
- Modalbox.hide();
+ availableSelect.fire("tapx:refreshbuttonstate");
+ selectedSelect.fire("tapx:refreshbuttonstate");
- var option = new Element("option").update(spec.label.escapeHTML());
+ selectedSelect.focus();
- option.txClientValue = spec.clientValue;
+ rebuildHiddenFieldValue();
+ });
+ }
- $(spec.clientId).fire("tapx:multiselect:newvalue", option);
- }
+ function newValue(spec) {
+ Modalbox.hide();
- return {
- tapxMultipleSelect : initializer,
- tapxMultipleSelectNewValue : newValue
- };
+ var option = new Element("option").update(spec.label.escapeHTML());
+
+ option.txClientValue = spec.clientValue;
+
+ $(spec.clientId).fire("tapx:multiselect:newvalue", option);
+ }
+
+ return {
+ tapxMultipleSelect: initializer,
+ tapxMultipleSelectNewValue: newValue
+ };
});

0 comments on commit 539c01c

Please sign in to comment.
Something went wrong with that request. Please try again.