Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added missing files

  • Loading branch information...
commit 06d2e3d3d9d7e26151eb31654c8298ab19e7c0c2 1 parent 7fdc8b2
@ivaynberg ivaynberg authored
View
25 wicket-fullcalendar-core/src/main/java/net/ftlines/wicket/fullcalendar/callback/AjaxConcurrency.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.ftlines.wicket.fullcalendar.callback;
+
+public enum AjaxConcurrency
+{
+ /** queue and execute all callbacks */
+ QUEUE,
+ /** drop callbacks if a callback of the same type is already executing */
+ DROP_PER_CALLBACK,
+ /** drop any callback if one is already executing */
+ DROP;
+}
View
103 wicket-fullcalendar-core/src/main/java/net/ftlines/wicket/fullcalendar/callback/BlockingDecorator.java
@@ -0,0 +1,103 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.ftlines.wicket.fullcalendar.callback;
+
+import java.util.UUID;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.IAjaxCallDecorator;
+import org.apache.wicket.util.collections.MicroMap;
+import org.apache.wicket.util.string.interpolator.MapVariableInterpolator;
+
+/**
+ * Prevents multiple clicks while ajax request is executing
+ *
+ * @author igor
+ */
+public class BlockingDecorator implements IAjaxCallDecorator
+{
+ // @formatter:off
+
+ private static final String template=
+ "if (typeof(${var})=='undefined'){${var}=true;}" +
+ "if(${var}==false){return false;}" +
+ "${var}=false;";
+
+ // @formatter:on
+
+ private final AbstractAjaxCallback callback;
+
+ private static String clean(String str)
+ {
+ return str != null ? str.replaceAll("[^0-9a-zA-Z]", "") : null;
+ }
+
+ public BlockingDecorator(AbstractAjaxCallback callback)
+ {
+ this.callback = callback;
+ }
+
+ private String var()
+ {
+ String var = null;
+ switch (callback.getCalendar().getAjaxConcurrency())
+ {
+ case DROP :
+ var = callback.getCalendar().getMarkupId();
+ break;
+ case DROP_PER_CALLBACK :
+ var = callback.getClass().getName();
+ }
+ var = "window.block" + clean(var);
+ return var;
+ }
+
+ @Override
+ public CharSequence decorateScript(CharSequence script)
+ {
+ switch (callback.getCalendar().getAjaxConcurrency())
+ {
+ case QUEUE :
+ return script;
+ case DROP_PER_CALLBACK :
+ case DROP :
+ return new MapVariableInterpolator(template, new MicroMap<String, String>("var", var())).toString() +
+ script;
+ default :
+ throw new IllegalStateException();
+ }
+ }
+
+ @Override
+ public CharSequence decorateOnSuccessScript(CharSequence script)
+ {
+ switch (callback.getCalendar().getAjaxConcurrency())
+ {
+ case QUEUE :
+ return script;
+ case DROP_PER_CALLBACK :
+ case DROP :
+ return var() + "=true;";
+ default :
+ throw new IllegalStateException();
+ }
+ }
+
+ @Override
+ public CharSequence decorateOnFailureScript(CharSequence script)
+ {
+ return decorateOnSuccessScript(script);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.