ItEr23S08CUEdicionCalendarioLaboral: Highlighting exception days on calendar.

This commit is contained in:
Manuel Rego Casasnovas 2009-08-26 09:14:02 +02:00 committed by Óscar González Fernández
parent a3ba759fa6
commit d385c64c19
7 changed files with 168 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
import org.navalplanner.business.calendars.entities.BaseCalendar.Days;
@ -597,4 +598,37 @@ public class BaseCalendarCRUDController extends GenericForwardComposer {
getVisibility().showOnly(editWindow);
}
public String getDays() {
LocalDate currentDate = new LocalDate(baseCalendarModel
.getSelectedDay());
LocalDate minDate = currentDate.dayOfMonth().withMinimumValue();
LocalDate maxDate = currentDate.dayOfMonth().withMaximumValue();
String days = "";
for (LocalDate date = minDate; date.compareTo(maxDate) <= 0; date = date
.plusDays(1)) {
DayType typeOfDay = baseCalendarModel.getTypeOfDay(date);
if (typeOfDay != null) {
switch (typeOfDay) {
case ANCESTOR_EXCEPTION:
case OWN_EXCEPTION:
days += date.getDayOfMonth() + ",";
break;
case ZERO_HOURS:
case NORMAL:
default:
break;
}
}
}
if (days.length() > 0) {
days = days.substring(0, days.length() - 1);
}
return days;
}
}

View file

@ -244,6 +244,16 @@ public class BaseCalendarModel implements IBaseCalendarModel {
return getBaseCalendar().getType(selectedDate);
}
@Override
@Transactional(readOnly = true)
public DayType getTypeOfDay(LocalDate date) {
if (getBaseCalendar() == null) {
return null;
}
return getBaseCalendar().getType(date);
}
@Override
@Transactional(readOnly = true)
public void createException(Integer hours) {

View file

@ -3,6 +3,7 @@ package org.navalplanner.web.calendars;
import java.util.Date;
import java.util.List;
import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
import org.navalplanner.business.calendars.entities.BaseCalendar.Days;
@ -75,6 +76,8 @@ public interface IBaseCalendarModel {
DayType getTypeOfDay();
DayType getTypeOfDay(LocalDate date);
Integer getHoursOfDay();
void createException(Integer hours);

View file

@ -0,0 +1,56 @@
package org.navalplanner.web.common.components;
import java.util.Date;
import org.navalplanner.web.common.Util;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Calendar;
/**
* ZK macro component that uses the {@link Calendar} component adding the
* possibility to highlight some days in the calendar.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public class CalendarHighlightedDays extends HtmlMacroComponent {
private Date value;
private String days;
public void setInternalValue(Date value) {
this.value = value;
Util.saveBindings(this);
highlightDays();
}
public Date getInternalValue() {
highlightDays();
return value;
}
public void setValue(Date value) {
this.value = value;
}
public Date getValue() {
return value;
}
public void setDays(String days) {
this.days = days;
}
public String getDays() {
return days;
}
private void highlightDays() {
Clients
.evalJavaScript("highlightDays('" + days
+ "', 'black', 'red');");
}
}

View file

@ -11,10 +11,16 @@
<macro-uri>/common/components/twowayselector.zul</macro-uri>
</component>
<component>
<component>
<component-name>i18n</component-name>
<component-class>org.navalplanner.web.common.components.I18n</component-class>
<macro-uri>/common/components/i18n.zul</macro-uri>
</component>
</language-addon>
<component>
<component-name>calendarhighlighteddays</component-name>
<component-class>org.navalplanner.web.common.components.CalendarHighlightedDays</component-class>
<macro-uri>/common/components/calendarhighlighteddays.zul</macro-uri>
</component>
</language-addon>

View file

@ -50,7 +50,10 @@
</vbox>
<vbox id="dayInformation">
<calendar id="calendarWidget" value="@{controller.selectedDay}" />
<calendarhighlighteddays id="calendarWidget"
value="@{controller.selectedDay,access='both'}"
days="@{controller.days,access='both'}"/>
<hbox>
<label value="${i18n:_('Type of day')}" />

View file

@ -0,0 +1,53 @@
<zk xmlns:n="http://www.zkoss.org/2005/zk/native">
<n:script src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js" />
<n:script src="http://yui.yahooapis.com/2.7.0/build/selector/selector-min.js" />
<n:script language="javascript">
<![CDATA[
Array.prototype.in_array = function(p_val) {
for(var i = 0, l = this.length; i < l; i++) {
if(this[i] == p_val) {
return true;
}
}
return false;
}
function highlightDays(days, color, bgcolor) {
var candidates = document.getElementsByTagName("td");
var nodes = YAHOO.util.Selector.filter(candidates, "[zk_day]");
var exceptions = days.split(",");
for (var i = 0; i < nodes.length; i++) {
var month = nodes[i].getAttribute("zk_monofs");
if (month == 0) {
var day = nodes[i].getAttribute("zk_day");
if (exceptions.in_array(day)) {
nodes[i].setAttribute("style",
"color:" + color + ";background-color:" + bgcolor);
} else {
nodes[i].removeAttribute("style");
}
} else {
nodes[i].setAttribute("style", "color:lightgrey;background-color:white");
}
}
}
]]>
</n:script>
<calendar value="@{self.parent.internalValue}" />
</zk>