001package 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
023import com.google.gwt.core.client.JavaScriptObject;
024import com.google.gwt.core.client.ScriptInjector;
025import org.gwtbootstrap3.extras.fullcalendar.client.FullCalendarClientBundle;
026
027/**
028 * Models the Event Source Object
029 *
030 * @author Jeff Isenhart
031 * @see http://arshaw.com/fullcalendar/docs/event_data/Event_Source_Object/
032 */
033public class EventSource implements IsJavaScriptObject {
034
035    private static boolean GCAL_ADDED = false;
036    private JavaScriptObject eventSource;
037
038    public EventSource(final JavaScriptObject jso) {
039        eventSource = jso;
040    }
041
042    public EventSource(final String url,
043                       final String color,
044                       final String backgroundColor,
045                       final String textColor,
046                       final String borderColor,
047                       final String className,
048                       final boolean isEditable,
049                       final boolean isStartEditable,
050                       final boolean isDurationEditable,
051                       final boolean allDayDefault,
052                       final boolean ignoreTimeZone,
053                       final boolean isGoogle//if true include google script file
054    ) {
055        if (isGoogle && !GCAL_ADDED) {
056            GCAL_ADDED = true;
057            ScriptInjector.fromString(FullCalendarClientBundle.INSTANCE.getGoogleCalJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
058        }
059        newEvent(url, color, backgroundColor, textColor, borderColor, className, isEditable, isStartEditable, isDurationEditable, allDayDefault, ignoreTimeZone);
060    }
061
062    private native void newEvent(String url,
063                                 String color,
064                                 String backgroundColor,
065                                 String textColor,
066                                 String borderColor,
067                                 String className,
068                                 boolean isEditable,
069                                 boolean isStartEditable,
070                                 boolean isDurationEditable,
071                                 boolean allDayDefault,
072                                 boolean ignoreTimeZone
073    ) /*-{
074        var theInstance = this;
075        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource = {
076            url: url,
077            color: color,
078            backgroundColor: backgroundColor,
079            textColor: textColor,
080            borderColor: borderColor,
081            className: className,
082            editable: isEditable,
083            startEditable: isStartEditable,
084            durationEditable: isDurationEditable,
085            allDayDefault: allDayDefault,
086            ignoreTimeZone: ignoreTimeZone
087        };
088    }-*/;
089
090    public native void setEventDataTransform(EventDataTransformCallback callback) /*-{
091        var theInstance = this;
092        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.eventTransform = function (eventData) {
093            if (callback) {
094                callback.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventDataTransformCallback::eventData(Lcom/google/gwt/core/client/JavaScriptObject;)(eventData);
095            }
096        }
097    }-*/;
098
099    public native String getUrl() /*-{
100        var theInstance = this;
101        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.url;
102    }-*/;
103
104    public native String getColor() /*-{
105        var theInstance = this;
106        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.color;
107    }-*/;
108
109    public native String getBackgroundColor() /*-{
110        var theInstance = this;
111        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.backgroundColor;
112    }-*/;
113
114    public native String getTextColor() /*-{
115        var theInstance = this;
116        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.textColor;
117    }-*/;
118
119    public native String getBorderColor() /*-{
120        var theInstance = this;
121        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.borderColor;
122    }-*/;
123
124    public native String getClassName() /*-{
125        var theInstance = this;
126        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.className;
127    }-*/;
128
129    public native boolean getIsEditable() /*-{
130        var theInstance = this;
131        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.editable;
132    }-*/;
133
134    public native boolean getStartEditable() /*-{
135        var theInstance = this;
136        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.startEditable;
137    }-*/;
138
139    public native boolean getDurationEditable() /*-{
140        var theInstance = this;
141        if (theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.durationEditable) {
142            return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.durationEditable;
143        }
144        return false;
145    }-*/;
146
147    public native boolean isAllDayDefault() /*-{
148        var theInstance = this;
149        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.allDayDefault;
150    }-*/;
151
152    public native boolean ignoreTimeZone() /*-{
153        var theInstance = this;
154        return theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.EventSource::eventSource.ignoreTimeZone;
155    }-*/;
156
157    @Override
158    public JavaScriptObject toJavaScript() {
159        return this.eventSource;
160    }
161}