001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package info.jtrac.wicket;
018:
019: import info.jtrac.domain.Counts;
020: import info.jtrac.domain.ItemSearch;
021: import info.jtrac.domain.Space;
022: import info.jtrac.domain.User;
023: import info.jtrac.domain.UserSpaceRole;
024: import org.apache.wicket.ajax.AjaxRequestTarget;
025: import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink;
026: import org.apache.wicket.markup.html.WebMarkupContainer;
027: import org.apache.wicket.markup.html.basic.Label;
028: import org.apache.wicket.markup.html.link.Link;
029: import org.apache.wicket.model.PropertyModel;
030:
031: /**
032: * panel for showing the total (un-expanded) statistics for
033: * a single space, will be replaced by expanded view through ajax
034: */
035: public class DashboardRowPanel extends BasePanel {
036:
037: public DashboardRowPanel(String id, final UserSpaceRole usr,
038: final Counts counts) {
039:
040: super (id);
041: setOutputMarkupId(true);
042:
043: final Space space = usr.getSpace();
044: final User user = usr.getUser();
045:
046: add(new Label("space", space.getName()));
047:
048: if (usr.isAbleToCreateNewItem()) {
049: add(new Link("new") {
050: public void onClick() {
051: setCurrentSpace(space);
052: setResponsePage(ItemFormPage.class);
053: }
054: });
055: } else {
056: add(new Label("new").setVisible(false));
057: }
058:
059: add(new Link("search") {
060: public void onClick() {
061: setCurrentSpace(space);
062: setResponsePage(ItemSearchFormPage.class);
063: }
064: });
065:
066: add(new IndicatingAjaxLink("link") {
067: public void onClick(AjaxRequestTarget target) {
068: Counts tempCounts = counts;
069: // avoid hitting the database again if re-expanding
070: if (!tempCounts.isDetailed()) {
071: tempCounts = getJtrac().loadCountsForUserSpace(
072: user, space);
073: }
074: DashboardRowExpandedPanel dashboardRow = new DashboardRowExpandedPanel(
075: "dashboardRow", usr, tempCounts);
076: DashboardRowPanel.this .replaceWith(dashboardRow);
077: target.addComponent(dashboardRow);
078: }
079: });
080:
081: if (user.getId() > 0) {
082: add(new Link("loggedByMe") {
083: public void onClick() {
084: setCurrentSpace(space);
085: ItemSearch itemSearch = new ItemSearch(space, this );
086: itemSearch.setLoggedBy(user);
087: setCurrentItemSearch(itemSearch);
088: setResponsePage(ItemListPage.class);
089: }
090: }.add(new Label("loggedByMe", new PropertyModel(counts,
091: "loggedByMe"))));
092:
093: add(new Link("assignedToMe") {
094: public void onClick() {
095: setCurrentSpace(space);
096: ItemSearch itemSearch = new ItemSearch(space, this );
097: itemSearch.setAssignedTo(user);
098: setCurrentItemSearch(itemSearch);
099: setResponsePage(ItemListPage.class);
100: }
101: }.add(new Label("assignedToMe", new PropertyModel(counts,
102: "assignedToMe"))));
103: } else {
104: add(new WebMarkupContainer("loggedByMe").setVisible(false));
105: add(new WebMarkupContainer("assignedToMe")
106: .setVisible(false));
107: }
108:
109: add(new Link("total") {
110: public void onClick() {
111: setCurrentSpace(space);
112: ItemSearch itemSearch = new ItemSearch(space, this );
113: setCurrentItemSearch(itemSearch);
114: setResponsePage(ItemListPage.class);
115: }
116: }.add(new Label("total", new PropertyModel(counts, "total"))));
117:
118: }
119:
120: }
|