-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10eeb04
commit 3d1abec
Showing
16 changed files
with
1,206 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.voelk.holidays.web; | ||
|
||
import org.restlet.*; | ||
import org.restlet.data.*; | ||
import org.restlet.resource.*; | ||
import org.restlet.routing.*; | ||
|
||
import java.util.*; | ||
|
||
public abstract class HolidayApplication extends Application { | ||
|
||
public HolidayApplication() { | ||
getConnectorService().getClientProtocols().add(Protocol.WAR); | ||
getMetadataService().setDefaultCharacterSet(CharacterSet.UTF_8); | ||
} | ||
|
||
@Override | ||
public Restlet createInboundRoot() { | ||
Router router = new Router(getContext()); | ||
for (Map.Entry<String, Class<? extends ServerResource>> entry : getRoutes().entrySet()) { | ||
router.attach(entry.getKey(), entry.getValue()); | ||
} | ||
return router; | ||
} | ||
|
||
protected abstract Map<String, Class<? extends ServerResource>> getRoutes(); | ||
} |
34 changes: 34 additions & 0 deletions
34
java/src/org/voelk/holidays/web/HolidayPagesApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.voelk.holidays.web; | ||
|
||
import freemarker.template.*; | ||
import org.restlet.*; | ||
import org.restlet.ext.freemarker.*; | ||
import org.restlet.resource.*; | ||
import org.voelk.holidays.web.pages.*; | ||
|
||
import java.util.*; | ||
|
||
public class HolidayPagesApplication extends HolidayApplication { | ||
|
||
private Configuration configuration; | ||
|
||
@Override | ||
public Restlet createInboundRoot() { | ||
configuration = new Configuration(); | ||
configuration.setTemplateLoader(new ContextTemplateLoader(getContext(), | ||
"war:///WEB-INF/templates/pages")); | ||
configuration.setDefaultEncoding("UTF-8"); | ||
return super.createInboundRoot(); | ||
} | ||
|
||
@Override | ||
protected Map<String, Class<? extends ServerResource>> getRoutes() { | ||
Map<String, Class<? extends ServerResource>> ret = new HashMap<String, Class<? extends ServerResource>>(); | ||
ret.put("/public/calculator", CalculatorPageResource.class); | ||
return ret; | ||
} | ||
|
||
public Configuration getConfiguration() { | ||
return configuration; | ||
} | ||
} |
21 changes: 12 additions & 9 deletions
21
java/src/org/voelk/holidays/web/HolidayWebservicesApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package org.voelk.holidays.web; | ||
|
||
import org.restlet.*; | ||
import org.restlet.routing.*; | ||
import org.voelk.holidays.web.webservices.HolidayCalculatorWebserviceResource; | ||
|
||
public class HolidayWebservicesApplication extends Application { | ||
public Restlet createInboundRoot() { | ||
Router router = new Router(getContext()); | ||
router.attach("/calculate/neededDays", HolidayCalculatorWebserviceResource.class); | ||
return router; | ||
import org.restlet.resource.*; | ||
import org.voelk.holidays.web.webservices.*; | ||
|
||
import java.util.*; | ||
|
||
public class HolidayWebservicesApplication extends HolidayApplication { | ||
|
||
@Override | ||
protected Map<String, Class<? extends ServerResource>> getRoutes() { | ||
Map<String, Class<? extends ServerResource>> ret = new HashMap<String, Class<? extends ServerResource>>(); | ||
ret.put("/public/calculate/neededDays", HolidayCalculatorWebserviceResource.class); | ||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.voelk.holidays.web; | ||
|
||
import java.util.*; | ||
|
||
public class I18nBean { | ||
private static ResourceBundle labelsBundle = ResourceBundle.getBundle("i18n.labelsBundle"); | ||
|
||
public static String getText(String key) { | ||
return labelsBundle.getString(key); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
java/src/org/voelk/holidays/web/pages/CalculatorPageResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.voelk.holidays.web.pages; | ||
|
||
import com.google.common.collect.*; | ||
|
||
import java.util.*; | ||
|
||
public class CalculatorPageResource extends PageResource { | ||
|
||
|
||
@Override | ||
protected String getTemplatePath() { | ||
return "calculator.ftl"; | ||
} | ||
|
||
@Override | ||
protected Map<String, Object> getPageData() { | ||
return Maps.newHashMap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.voelk.holidays.web.pages; | ||
|
||
import org.restlet.data.*; | ||
import org.restlet.ext.freemarker.*; | ||
import org.restlet.representation.*; | ||
import org.restlet.resource.*; | ||
import org.voelk.holidays.web.*; | ||
|
||
import java.util.*; | ||
|
||
public abstract class PageResource extends ServerResource { | ||
@Override | ||
public HolidayPagesApplication getApplication() { | ||
return (HolidayPagesApplication) super.getApplication(); | ||
} | ||
|
||
@Get | ||
public Representation toHtml() { | ||
return toRepresentation(); | ||
} | ||
|
||
protected MediaType getMediaType() { | ||
return MediaType.TEXT_HTML; | ||
} | ||
|
||
protected abstract String getTemplatePath(); | ||
|
||
protected abstract Map<String, Object> getPageData(); | ||
|
||
protected Representation toRepresentation() { | ||
return new TemplateRepresentation(getTemplatePath(), getApplication().getConfiguration(), getPageData(), getMediaType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
application.title=Urlaubsplaner |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<#import "basePage.ftl" as master> | ||
<@master.page> | ||
<script type="text/javascript" src="js/calculator.js"></script> | ||
<form id="calculationForm" action="/rest/public/calculate/neededDays" method="get"> | ||
<h1>Urlaubsplanung</h1> | ||
|
||
<div id="calendar"> | ||
<label for="localFrom">Von:</label> | ||
<input type="text" name="localFrom" id="localFrom"/><input type="hidden" name="from" id="from"/> | ||
<label for="localTo">Bis:</label> | ||
<input type="text" name="localTo" id="localTo"/><input type="hidden" name="to" id="to"/> | ||
</div> | ||
<div> | ||
benötigte Tage: <span id="daysNeeded"></span> | ||
</div> | ||
</form> | ||
</@master.page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
$(function () { | ||
var dates = $("#from, #to").datepicker({ | ||
/*global $, jQuery */ | ||
function initDatePickers() { | ||
"use strict"; | ||
var dates = $("#localFrom, #localTo").datepicker({ | ||
numberOfMonths:2, | ||
altFormat:"yy-mm-dd", | ||
onSelect:function (selectedDate) { | ||
var option = this.id == "from" ? "minDate" : "maxDate", | ||
var option = this.id === "localFrom" ? "minDate" : "maxDate", | ||
instance = $(this).data("datepicker"), | ||
date = $.datepicker.parseDate( | ||
instance.settings.dateFormat || | ||
$.datepicker._defaults.dateFormat, | ||
selectedDate, instance.settings); | ||
dates.not(this).datepicker("option", option, date); | ||
$("#daysNeeded").text("Berechne..."); | ||
$.ajax({ | ||
url:function () { | ||
var fromDate = dates.filter("#from").datepicker("getDate"), | ||
toDate = dates.filter("#to").datepicker("getDate"), | ||
from = "", | ||
to = ""; | ||
if (fromDate) { | ||
from = $.datepicker.formatDate('yy-mm-dd', fromDate); | ||
} | ||
if (toDate) { | ||
to = $.datepicker.formatDate('yy-mm-dd', toDate); | ||
} | ||
return "/public/rest/calculate/neededDays?from=" + from + "&to=" + to; | ||
}(), | ||
context:document.body, | ||
dataType:"text", | ||
success:function (data) { | ||
$("#daysNeeded").text(data); | ||
} | ||
}); | ||
$('#calculationForm').submit(); | ||
} | ||
}) | ||
; | ||
}); | ||
$("#localFrom").datepicker("option", "altField", '#from'); | ||
$("#localTo").datepicker("option", "altField", '#to'); | ||
} | ||
function bindSubmitToAjaxRequest() { | ||
"use strict"; | ||
var options = { | ||
target:'#daysNeeded' | ||
}; | ||
$('#calculationForm').ajaxForm(options); | ||
} | ||
|
||
$(function () { | ||
"use strict"; | ||
bindSubmitToAjaxRequest(); | ||
initDatePickers(); | ||
}); |
Oops, something went wrong.