Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Reformat with spaces

  • Loading branch information...
commit 539c01c8b60be30cc662d1c4885a74f474d59017 1 parent 33a4601
Howard M. Lewis Ship authored
322 tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx-multiselect.js
... ... @@ -1,205 +1,205 @@
1   -T5.extendInitializers(function() {
2   -
3   - function setupButton(select, button, callback) {
4   - var enabled = false;
5   -
6   - function updateButton() {
7   - var newEnabled = select.selectedIndex >= 0;
8   -
9   - if (enabled != newEnabled) {
10   - enabled = newEnabled;
11   -
12   - if (enabled)
13   - button.removeClassName("tx-disabled");
14   - else
15   - button.addClassName("tx-disabled");
16   - }
17   - }
18   -
19   - select.observe("change", updateButton);
20   - select.observe("tapx:refreshbuttonstate", updateButton);
21   -
22   - function callbackIfEnabled() {
23   - if (enabled)
24   - callback();
25   - }
26   -
27   - button.observe("click", callbackIfEnabled);
28   -
29   - select.observe("dblclick", callbackIfEnabled);
30   - }
31   -
32   - function moveOption(option, to) {
33   -
34   - var before = $A(to.options).detect(function(targetOption) {
35   - return targetOption.innerHTML > option.innerHTML;
36   - });
37   -
38   - if (Prototype.IE) {
39   - if (before == null) {
40   - to.add(option);
41   - } else {
42   - to.add(option, before.index);
43   - }
44   -
45   - return;
46   - }
  1 +T5.extendInitializers(function () {
  2 +
  3 + function setupButton(select, button, callback) {
  4 + var enabled = false;
  5 +
  6 + function updateButton() {
  7 + var newEnabled = select.selectedIndex >= 0;
  8 +
  9 + if (enabled != newEnabled) {
  10 + enabled = newEnabled;
  11 +
  12 + if (enabled)
  13 + button.removeClassName("tx-disabled");
  14 + else
  15 + button.addClassName("tx-disabled");
  16 + }
  17 + }
  18 +
  19 + select.observe("change", updateButton);
  20 + select.observe("tapx:refreshbuttonstate", updateButton);
  21 +
  22 + function callbackIfEnabled() {
  23 + if (enabled)
  24 + callback();
  25 + }
  26 +
  27 + button.observe("click", callbackIfEnabled);
  28 +
  29 + select.observe("dblclick", callbackIfEnabled);
  30 + }
  31 +
  32 + function moveOption(option, to) {
  33 +
  34 + var before = $A(to.options).detect(function (targetOption) {
  35 + return targetOption.innerHTML > option.innerHTML;
  36 + });
47 37
48   - to.add(option, before);
49   - }
  38 + if (Prototype.IE) {
  39 + if (before == null) {
  40 + to.add(option);
  41 + } else {
  42 + to.add(option, before.index);
  43 + }
50 44
51   - function moveOptions(movers, to) {
52   - movers.each(function(option) {
53   - moveOption(option, to);
54   - });
55   - }
  45 + return;
  46 + }
56 47
57   - function deselectAllOptions(select) {
58   - $A(select.options).each(function(option) {
59   - option.selected = false;
60   - });
61   - }
  48 + to.add(option, before);
  49 + }
62 50
63   - function removeSelectedOptions(select) {
64   - var movers = [];
65   - var options = select.options;
  51 + function moveOptions(movers, to) {
  52 + movers.each(function (option) {
  53 + moveOption(option, to);
  54 + });
  55 + }
66 56
67   - for ( var i = select.selectedIndex; i < select.length; i++) {
68   - var option = options[i];
69   - if (option.selected) {
70   - select.remove(i--);
71   - movers.push(option);
72   - }
73   - }
  57 + function deselectAllOptions(select) {
  58 + $A(select.options).each(function (option) {
  59 + option.selected = false;
  60 + });
  61 + }
74 62
75   - return movers;
76   - }
  63 + function removeSelectedOptions(select) {
  64 + var movers = [];
  65 + var options = select.options;
77 66
78   - function transferOptions(from, to) {
79   - deselectAllOptions(to);
80   - moveOptions(removeSelectedOptions(from), to);
81   - from.fire("tapx:refreshbuttonstate");
82   - to.fire("tapx:refreshbuttonstate");
83   - }
  67 + for (var i = select.selectedIndex; i < select.length; i++) {
  68 + var option = options[i];
  69 + if (option.selected) {
  70 + select.remove(i--);
  71 + movers.push(option);
  72 + }
  73 + }
84 74
85   - // Re. "Modalbox" vs. "Lightbox". Modalbox is a specific implementation of
86   - // the general Lightbox design; we may swap out Modalbox for some other
87   - // Lightbox implementation, given how awkward it is to use with Tapestry.
  75 + return movers;
  76 + }
88 77
89   - function lightbox(title, contentURL) {
  78 + function transferOptions(from, to) {
  79 + deselectAllOptions(to);
  80 + moveOptions(removeSelectedOptions(from), to);
  81 + from.fire("tapx:refreshbuttonstate");
  82 + to.fire("tapx:refreshbuttonstate");
  83 + }
90 84
91   - function updateLightboxFromReply(reply) {
92   - var inits = reply.inits;
93   - reply.inits = null;
  85 + // Re. "Modalbox" vs. "Lightbox". Modalbox is a specific implementation of
  86 + // the general Lightbox design; we may swap out Modalbox for some other
  87 + // Lightbox implementation, given how awkward it is to use with Tapestry.
94 88
95   - Modalbox.show(reply.content, {
96   - title : title,
97   - autoFocusing : false,
98   - afterLoad : function() {
99   - Tapestry.executeInits(inits);
100   - },
101   - afterUpdate : function() {
102   - Modalbox.resizeToContent();
103   - }
104   - });
105   - }
  89 + function lightbox(title, contentURL) {
106 90
107   - // Been experimenting with running the Modalbox loading animation in parallel
108   - // with doing the Ajax, but Modalbox is a twisted singleton that causes some
109   - // bad timing issues. Back to just running the (quick) Ajax request and then running
110   - // the Modalbox animation.
111   -
112   - Tapestry.ajaxRequest(contentURL, function(transport) {
113   - var reply = transport.responseJSON;
  91 + function updateLightboxFromReply(reply) {
  92 + var inits = reply.inits;
  93 + reply.inits = null;
114 94
115   - updateLightboxFromReply(reply);
116   - });
117   - }
  95 + Modalbox.show(reply.content, {
  96 + title: title,
  97 + autoFocusing: false,
  98 + afterLoad: function () {
  99 + Tapestry.executeInits(inits);
  100 + },
  101 + afterUpdate: function () {
  102 + Modalbox.resizeToContent();
  103 + }
  104 + });
  105 + }
118 106
119   - function initializer(spec) {
120   - var availableSelect = $(spec.clientId);
121   - var outerDiv = availableSelect.up(".tx-multiselect");
  107 + // Been experimenting with running the Modalbox loading animation in parallel
  108 + // with doing the Ajax, but Modalbox is a twisted singleton that causes some
  109 + // bad timing issues. Back to just running the (quick) Ajax request and then running
  110 + // the Modalbox animation.
122 111
123   - var hidden = outerDiv.down("input[type='hidden']");
  112 + Tapestry.ajaxRequest(contentURL, function (transport) {
  113 + var reply = transport.responseJSON;
124 114
125   - var selectedSelect = outerDiv.down(".tx-selected select");
  115 + updateLightboxFromReply(reply);
  116 + });
  117 + }
126 118
127   - (spec.model || []).each(function(row) {
  119 + function initializer(spec) {
  120 + var availableSelect = $(spec.clientId);
  121 + var outerDiv = availableSelect.up(".tx-multiselect");
128 122
129   - var valueId = row[0];
130   - var selected = (spec.values || []).include(valueId);
131   - var selectElement = selected ? selectedSelect : availableSelect;
  123 + var hidden = outerDiv.down("input[type='hidden']");
132 124
133   - var option = new Element("option").update(row[1].escapeHTML());
  125 + var selectedSelect = outerDiv.down(".tx-selected select");
134 126
135   - option.txClientValue = valueId;
  127 + (spec.model || []).each(function (row) {
136 128
137   - selectElement.insert(option);
138   - });
  129 + var valueId = row[0];
  130 + var selected = (spec.values || []).include(valueId);
  131 + var selectElement = selected ? selectedSelect : availableSelect;
139 132
140   - function rebuildHiddenFieldValue() {
141   - // First array is the list of selected values (for values
142   - // defined by the model at initial render). Second array is the list
143   - // of selected labels (for values added on the client)
  133 + var option = new Element("option").update(row[1].escapeHTML());
144 134
145   - var hiddenFieldValue = [];
  135 + option.txClientValue = valueId;
146 136
147   - $A(selectedSelect.options).each(function(option) {
148   - hiddenFieldValue.push(option.txClientValue);
149   - });
  137 + selectElement.insert(option);
  138 + });
150 139
151   - hidden.value = Object.toJSON(hiddenFieldValue);
152   - }
  140 + function rebuildHiddenFieldValue() {
  141 + // First array is the list of selected values (for values
  142 + // defined by the model at initial render). Second array is the list
  143 + // of selected labels (for values added on the client)
153 144
154   - rebuildHiddenFieldValue();
  145 + var hiddenFieldValue = [];
155 146
156   - setupButton(availableSelect, outerDiv.down(".tx-select"), function() {
157   - transferOptions(availableSelect, selectedSelect);
158   - rebuildHiddenFieldValue();
  147 + $A(selectedSelect.options).each(function (option) {
  148 + hiddenFieldValue.push(option.txClientValue);
  149 + });
159 150
160   - });
  151 + hidden.value = Object.toJSON(hiddenFieldValue);
  152 + }
161 153
162   - setupButton(selectedSelect, outerDiv.down(".tx-deselect"), function() {
163   - transferOptions(selectedSelect, availableSelect);
164   - rebuildHiddenFieldValue();
165   - });
  154 + rebuildHiddenFieldValue();
166 155
167   - outerDiv.down(".tx-input button").observe("click", function(event) {
168   - event.stop();
  156 + setupButton(availableSelect, outerDiv.down(".tx-select"), function () {
  157 + transferOptions(availableSelect, selectedSelect);
  158 + rebuildHiddenFieldValue();
169 159
170   - lightbox(event.element().innerHTML, spec.newValueURL);
171   - });
  160 + });
172 161
173   - $(spec.clientId).observe("tapx:multiselect:newvalue", function(event) {
  162 + setupButton(selectedSelect, outerDiv.down(".tx-deselect"), function () {
  163 + transferOptions(selectedSelect, availableSelect);
  164 + rebuildHiddenFieldValue();
  165 + });
174 166
175   - var option = event.memo;
176   - option.selected = true;
  167 + outerDiv.down(".tx-input button").observe("click", function (event) {
  168 + event.stop();
177 169
178   - deselectAllOptions(selectedSelect);
  170 + lightbox(event.element().innerHTML, spec.newValueURL);
  171 + });
179 172
180   - moveOption(option, selectedSelect);
  173 + $(spec.clientId).observe("tapx:multiselect:newvalue", function (event) {
181 174
182   - availableSelect.fire("tapx:refreshbuttonstate");
183   - selectedSelect.fire("tapx:refreshbuttonstate");
  175 + var option = event.memo;
  176 + option.selected = true;
184 177
185   - selectedSelect.focus();
  178 + deselectAllOptions(selectedSelect);
186 179
187   - rebuildHiddenFieldValue();
188   - });
189   - }
  180 + moveOption(option, selectedSelect);
190 181
191   - function newValue(spec) {
192   - Modalbox.hide();
  182 + availableSelect.fire("tapx:refreshbuttonstate");
  183 + selectedSelect.fire("tapx:refreshbuttonstate");
193 184
194   - var option = new Element("option").update(spec.label.escapeHTML());
  185 + selectedSelect.focus();
195 186
196   - option.txClientValue = spec.clientValue;
  187 + rebuildHiddenFieldValue();
  188 + });
  189 + }
197 190
198   - $(spec.clientId).fire("tapx:multiselect:newvalue", option);
199   - }
  191 + function newValue(spec) {
  192 + Modalbox.hide();
200 193
201   - return {
202   - tapxMultipleSelect : initializer,
203   - tapxMultipleSelectNewValue : newValue
204   - };
  194 + var option = new Element("option").update(spec.label.escapeHTML());
  195 +
  196 + option.txClientValue = spec.clientValue;
  197 +
  198 + $(spec.clientId).fire("tapx:multiselect:newvalue", option);
  199 + }
  200 +
  201 + return {
  202 + tapxMultipleSelect: initializer,
  203 + tapxMultipleSelectNewValue: newValue
  204 + };
205 205 });

0 comments on commit 539c01c

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