001    package org.gwtbootstrap3.extras.fullcalendar.client.ui;
002    
003    /*
004     * #%L
005     * GwtBootstrap3
006     * %%
007     * Copyright (C) 2013 - 2014 GwtBootstrap3
008     * %%
009     * Licensed under the Apache License, Version 2.0 (the "License");
010     * you may not use this file except in compliance with the License.
011     * You may obtain a copy of the License at
012     * 
013     *      http://www.apache.org/licenses/LICENSE-2.0
014     * 
015     * Unless required by applicable law or agreed to in writing, software
016     * distributed under the License is distributed on an "AS IS" BASIS,
017     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018     * See the License for the specific language governing permissions and
019     * limitations under the License.
020     * #L%
021     */
022    
023    import com.google.gwt.core.client.JavaScriptObject;
024    import com.google.gwt.core.client.JsArrayInteger;
025    
026    /**
027     * @author Jeff Isenhart
028     * @see http://arshaw.com/fullcalendar/docs/display/
029     */
030    public class GeneralDisplay implements IsJavaScriptObject {
031        private JavaScriptObject general;
032    
033        public GeneralDisplay() {
034            this(new Header());
035        }
036    
037        public GeneralDisplay(final Header header) {
038            newInstance();
039            if (header != null) {
040                setHeader(header.toJavaScript());
041            }
042        }
043    
044        private native void newInstance() /*-{
045            var theInstance = this;
046            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general = {
047                firstDay: 0,
048                isRTL: false,
049                weekends: true,
050                hiddenDays: [],
051                weekMode: 'fixed',
052                weekNumbers: false,
053                weekNumberCalculation: 'local',
054                aspectRatio: 1.35,
055                handleWindowResize: true,
056                prev: 'left-single-arrow',
057                next: 'right-single-arrow',
058                prevYear: 'left-double-arrow',
059                nextYear: 'right-double-arrow'
060            };
061        }-*/;
062    
063        public native void setViewRenderCallback(ViewRenderCallback callback) /*-{
064            if (callback) {
065                var theInstance = this;
066                theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.viewRender = function (view, element) {
067                    callback.@org.gwtbootstrap3.extras.fullcalendar.client.ui.ViewRenderCallback::viewRender(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/dom/client/Element;)(view, element[0]);
068                };
069    
070                theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.viewDestroy = function (view, element) {
071                    callback.@org.gwtbootstrap3.extras.fullcalendar.client.ui.ViewRenderCallback::viewDestroy(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/dom/client/Element;)(view, element[0]);
072                };
073    
074                theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.dayRender = function (date, cell) {
075                    callback.@org.gwtbootstrap3.extras.fullcalendar.client.ui.ViewRenderCallback::dayRender(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/dom/client/Element;)(date, cell);
076                };
077    
078                theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.windowResize = function (view) {
079                    callback.@org.gwtbootstrap3.extras.fullcalendar.client.ui.ViewRenderCallback::windowResize(Lcom/google/gwt/core/client/JavaScriptObject;)(view);
080                };
081            }
082        }-*/;
083    
084        public native void setFirstDayOption(int firstDay) /*-{
085            if (firstDay >= 0 && firstDay <= 6) {
086                var theInstance = this;
087                return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.firstDay = firstDay;
088            }
089        }-*/;
090    
091        public native void setIsRTL(boolean rtl) /*-{
092            var theInstance = this;
093            return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.isRTL = rtl;
094        }-*/;
095    
096        public void setHeader(final Header header) {
097            setHeader(header == null ? null : header.toJavaScript());
098        }
099    
100        private native void setHeader(JavaScriptObject header) /*-{
101            var theInstance = this;
102            return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.header = header;
103        }-*/;
104    
105        public native void setWeekends(boolean weekends) /*-{
106            var theInstance = this;
107            return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.weekends = weekends;
108        }-*/;
109    
110        public void setHiddenDays(final int... days) {
111            if (days != null) {
112                final JsArrayInteger intArr = (JsArrayInteger) JsArrayInteger.createArray();
113                for (final int i : days) {
114                    assert i >= 0 && i <= 6;
115                    intArr.push(i);
116                }
117                setHiddenDays(intArr);
118            }
119        }
120    
121        public native void setHiddenDays(JsArrayInteger hiddenDays) /*-{
122            var theInstance = this;
123            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.hiddenDays = hiddenDays;
124        }-*/;
125    
126        public native void setWeekMode(String mode) /*-{
127            if (mode) {
128                if (mode == 'fixed' || mode == 'liquid' || mode == 'variable') {
129                    var theInstance = this;
130                    theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.weekMode = mode;
131                }
132            }
133    
134        }-*/;
135    
136        public native void setWeekNumbers(boolean weekNumbers) /*-{
137            var theInstance = this;
138            return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.weekNumbers = weekNumbers;
139    
140        }-*/;
141    
142        public native void setWeekNumberCaculation(String calculation) /*-{
143            if (calculation) {
144                if (calculation == 'local' || calculation == 'ISO') {
145                    var theInstance = this;
146                    theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.weekNumberCalculation = calculation;
147                }
148            }
149    
150        }-*/;
151    
152        //to-do: make this a callback
153        public native void setWeekNumberCaculation(JavaScriptObject weekNumberFunction) /*-{
154            if (weekNumberFunction) {
155                var theInstance = this;
156                theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.weekNumberCalculation = weekNumberFunction;
157            }
158    
159        }-*/;
160    
161        public native void setHeight(int height) /*-{
162            var theInstance = this;
163            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.height = height;
164        }-*/;
165    
166        public native void setContentHeight(int contentHeight) /*-{
167            var theInstance = this;
168            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.contentHeight = contentHeight;
169        }-*/;
170    
171        public native void setAspectRatio(double aspectRatio) /*-{
172            var theInstance = this;
173            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.aspectRatio = aspectRatio;
174        }-*/;
175    
176        public native void setHandleWindowResize(boolean handleWindowResize) /*-{
177            var theInstance = this;
178            return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.handleWindowResize = handleWindowResize;
179        }-*/;
180    
181        public native void setPrev(String previous) /*-{
182            var theInstance = this;
183            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.prev = previous;
184        }-*/;
185    
186        public native void setNext(String next) /*-{
187            var theInstance = this;
188            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.next = next;
189        }-*/;
190    
191        public native void setPrevYear(String previousYear) /*-{
192            var theInstance = this;
193            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.prevYear = previousYear;
194        }-*/;
195    
196        public native void setNextYear(String nextYear) /*-{
197            var theInstance = this;
198            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.GeneralDisplay::general.nextYear = nextYear;
199        }-*/;
200    
201        @Override
202        public JavaScriptObject toJavaScript() {
203            return general;
204        }
205    }