Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First commit - refs #60 - lots of bugs, JS errors, not properly teste…

…s yet. Need to inherit the Datepicker module ;) - refs #60
  • Loading branch information...
commit 286d8f704b728288bad9ff83b11b216cba150d25 1 parent ce1c16d
@caarlos0 caarlos0 authored
View
6 .gitmodules
@@ -1,3 +1,7 @@
[submodule "bootstrap"]
path = bootstrap
- url = https://github.com/twitter/bootstrap.git
+ url = https://github.com/twitter/bootstrap.git
+
+[submodule "bootstrap-datepicker"]
+ path = bootstrap-datepicker
+ url = https://github.com/eternicode/bootstrap-datepicker.git
View
34 src/main/java/com/github/gwtbootstrap/datepicker/client/ui/DateBox.java
@@ -1,7 +1,6 @@
package com.github.gwtbootstrap.datepicker.client.ui;
-import com.github.gwtbootstrap.client.ui.TextBox;
-import com.google.gwt.dom.client.Element;
+import com.github.gwtbootstrap.datepicker.client.ui.base.DatePickerBase;
/**
* DateBox component.
@@ -9,36 +8,7 @@
* @since 2.0.3.0
* @author Carlos Alexandro Becker
*/
-public class DateBox extends TextBox {
+public class DateBox extends DatePickerBase {
- private String format = "mm/dd/yyyy";
-
- public DateBox() {
- configure();
- }
-
- public DateBox(String format) {
- this.format = format;
- configure();
- }
-
- public void setFormat(String format) {
- this.format = format;
- }
-
- @Override
- protected void onLoad() {
- super.onLoad();
- configure(getElement());
- }
-
- private final void configure() {
- getElement().setAttribute("data-date-format", format);
- configure(getElement());
- }
-
- private final native void configure(Element e) /*-{
- $wnd.jQuery(e).datepicker();
- }-*/;
}
View
91 src/main/java/com/github/gwtbootstrap/datepicker/client/ui/DateBoxAppended.java
@@ -0,0 +1,91 @@
+package com.github.gwtbootstrap.datepicker.client.ui;
+
+import com.github.gwtbootstrap.client.ui.AddOn;
+import com.github.gwtbootstrap.client.ui.AppendButton;
+import com.github.gwtbootstrap.client.ui.constants.IconType;
+import com.github.gwtbootstrap.datepicker.client.ui.base.DatePickerBase;
+import com.github.gwtbootstrap.datepicker.client.ui.base.HasDateFormat;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.ui.HasValue;
+
+import java.util.Date;
+
+/**
+ * DateBoxAppended component.
+ *
+ * @since 2.0.3.0
+ * @author Carlos Alexandro Becker
+ */
+public class DateBoxAppended extends AppendButton implements HasValue<Date>, HasDateFormat {
+ private final DateBoxAppendedAdapter box;
+
+ {
+ this.box = new DateBoxAppendedAdapter();
+ AddOn icon = new AddOn();
+ icon.setIcon(IconType.TH);
+ add(box);
+ add(icon);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Date getValue() {
+ return box.getValue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setValue(Date value) {
+ box.setValue(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setValue(Date value, boolean fireEvents) {
+ box.setValue(value, fireEvents);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Date> dateValueChangeHandler) {
+ return box.addValueChangeHandler(dateValueChangeHandler);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFormat(String format) {
+ box.setFormat(format);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getFormat() {
+ return box.getFormat();
+ }
+
+ /**
+ * An 'adapter' to change some aspects of the behavior of datepickerbase. //TODO may need refactor.
+ */
+ private class DateBoxAppendedAdapter extends DatePickerBase {
+ @Override
+ protected void configure() {
+ DateBoxAppended that = DateBoxAppended.this;
+ super.configure(that);
+ getBox().getElement().setAttribute("readonly", null);
+ that.addStyleName("date");
+ }
+ }
+}
View
211 src/main/java/com/github/gwtbootstrap/datepicker/client/ui/base/DatePickerBase.java
@@ -0,0 +1,211 @@
+package com.github.gwtbootstrap.datepicker.client.ui.base;
+
+import com.github.gwtbootstrap.client.ui.TextBox;
+import com.github.gwtbootstrap.client.ui.base.HasVisibility;
+import com.github.gwtbootstrap.client.ui.base.HasVisibleHandlers;
+import com.github.gwtbootstrap.client.ui.event.*;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.user.client.ui.HasValue;
+import com.google.gwt.user.client.ui.Widget;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Base DatePicker component.
+ *
+ * @author Carlos Alexandro Becker
+ * @since 2.0.3.0
+ */
+public class DatePickerBase extends Widget implements HasValue<Date>, HasValueChangeHandlers<Date>, HasDateFormat, HasVisibility,
+ HasVisibleHandlers {
+
+ private final TextBox box;
+ private String format;
+ private DateTimeFormat dtf;
+ private Map<String, String> options = new HashMap<String, String>();
+
+ public DatePickerBase() {
+ this.box = new TextBox();
+ setElement(box.getElement());
+ setFormat("mm/dd/yyyy");
+ setValue(new Date());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFormat(String format) {
+ this.format = format;
+ Date oldValue = getValue();
+ this.dtf = DateTimeFormat.getFormat(format.replaceAll("mm", "MM"));
+ if (oldValue != null) {
+ setValue(oldValue);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getFormat() {
+ return format;
+ }
+
+ /**
+ * Returns the internal instance of textbox element. Use only if know what you are doing.
+ *
+ * @return internal textbox intance.
+ */
+ protected TextBox getBox() {
+ return box;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Date getValue() {
+ return dtf != null ? dtf.parse(box.getValue()) : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setValue(Date value) {
+ setValue(value, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setValue(Date value, boolean fireEvents) {
+ box.setValue(dtf.format(value));
+ if (fireEvents) {
+ ValueChangeEvent.fire(this, value);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Date> dateValueChangeHandler) {
+ return addHandler(dateValueChangeHandler, ValueChangeEvent.getType());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onLoad() {
+ super.onLoad();
+ configure();
+ }
+
+ /**
+ * Configure the elements for a specific widget.
+ * Use only if you know what you are doing.
+ *
+ * @param w: the widget to configure.
+ */
+ protected void configure(Widget w) {
+ w.getElement().setAttribute("data-date-format", format);
+ configure(w.getElement(), options);
+ }
+
+ /**
+ * dateChange event handler.
+ */
+ public void onChange() {
+ ValueChangeEvent.fire(this, getValue());
+ }
+
+ /**
+ * configure this datepicker.
+ */
+ protected void configure() {
+ configure(this);
+ }
+
+ public void setAutoClose(boolean autoClose) {
+ options.put("autoclose", Boolean.toString(autoClose));
+ configure();
+ }
+
+ /**
+ * call jquery datepicker plugin in a element.
+ *
+ * @param e: Element that will be transformed in a datepicker.
+ */
+ protected native void configure(Element e, Map<String, String> opts) /*-{
+ var that = this;
+ $wnd.alert(opts);
+ $wnd.jQuery(e).datepicker(opts);
+// $wnd.jQuery(e).on('changeDate', function () {
+// that.@com.github.gwtbootstrap.datepicker.client.ui.base.DatePickerBase::onChange()();
+// });
+// $wnd.jQuery(e).on("show", function () {
+// that.@com.github.gwtbootstrap.datepicker.client.ui.base.DatePickerBase::show()();
+// });
+// $wnd.jQuery(e).on("hide", function () {
+// that.@com.github.gwtbootstrap.datepicker.client.ui.base.DatePickerBase::hide()();
+// });
+ }-*/;
+
+ private native void execute(Element e, String cmd) /*-{
+ $wnd.jQuery(e).datepicker(cmd);
+ }-*/;
+
+ private void execute(String cmd) {
+ execute(getElement(), cmd);
+ }
+
+ @Override
+ public void show() {
+ execute("show");
+ }
+
+ @Override
+ public void hide() {
+ execute("hide");
+ }
+
+ @Override
+ public void toggle() {
+ if (options.containsKey("show")) {
+ hide();
+ } else {
+ show();
+ }
+ }
+
+ @Override
+ public HandlerRegistration addHideHandler(HideHandler handler) {
+ return addHandler(handler, HideEvent.getType());
+ }
+
+ @Override
+ public HandlerRegistration addHiddenHandler(HiddenHandler handler) {
+ return addHandler(handler, HiddenEvent.getType());
+ }
+
+ @Override
+ public HandlerRegistration addShowHandler(ShowHandler handler) {
+ return addHandler(handler, ShowEvent.getType());
+ }
+
+ @Override
+ public HandlerRegistration addShownHandler(ShownHandler handler) {
+ return addHandler(handler, ShownEvent.getType());
+ }
+}
View
23 src/main/java/com/github/gwtbootstrap/datepicker/client/ui/base/HasDateFormat.java
@@ -0,0 +1,23 @@
+package com.github.gwtbootstrap.datepicker.client.ui.base;
+
+/**
+ * Define a element to have the getter and setter of format (string).
+ *
+ * @author Carlos Alexandro Becker
+ * @since 2.0.3.0
+ */
+public interface HasDateFormat {
+
+ /**
+ * Set the format in the component.
+ * @param format: the date format (dd/mm/yyyy, e.g.)
+ */
+ void setFormat(String format);
+
+ /**
+ * get the atual component format.
+ * @return format: the date format (dd/mm/yyyy, e.g.)
+ */
+ String getFormat();
+
+}
View
12 src/showcase/java/com/github/gwtbootstrap/showcase/client/Datepicker.ui.xml
@@ -27,7 +27,17 @@
<b:Row>
<b:Column size="6">
<g:HTMLPanel>
- <b2:DateBox format="dd/mm/yyy" />
+ <b2:DateBox format="dd/mm/yyyy" autoClose="true" />
+ <pre class="prettyprint linenums">
+ &lt;b:Alert type=&quot;SUCCESS&quot; close=&quot;false&quot; animation=&quot;true&quot;&gt;TestAlert
+ without close&lt;/b:Alert&gt;</pre>
+ </g:HTMLPanel>
+ </b:Column>
+ </b:Row>
+ <b:Row>
+ <b:Column size="6">
+ <g:HTMLPanel>
+ <b2:DateBoxAppended />
<pre class="prettyprint linenums">
&lt;b:Alert type=&quot;SUCCESS&quot; close=&quot;false&quot; animation=&quot;true&quot;&gt;TestAlert
without close&lt;/b:Alert&gt;</pre>
Please sign in to comment.
Something went wrong with that request. Please try again.