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.Item;
020: import info.jtrac.domain.ItemSearch;
021: import info.jtrac.domain.User;
022: import org.apache.wicket.PageParameters;
023: import org.apache.wicket.RestartResponseAtInterceptPageException;
024: import org.apache.wicket.markup.html.WebMarkupContainer;
025: import org.apache.wicket.markup.html.link.Link;
026:
027: /**
028: * dashboard page
029: */
030: public class ItemViewPage extends BasePage {
031:
032: private long itemId;
033:
034: public long getItemId() {
035: return itemId;
036: }
037:
038: public ItemViewPage(PageParameters params) {
039: String refId = params.getString("0");
040: logger.debug("item id parsed from url = '" + refId + "'");
041: Item item;
042: if (refId.indexOf('-') != -1) {
043: // this in the form SPACE-123
044: item = getJtrac().loadItemByRefId(refId);
045: } else {
046: // internal id of type long
047: item = getJtrac().loadItem(Long.parseLong(refId));
048: }
049: itemId = item.getId(); // required for itemRelatePanel
050: addComponents(item);
051: }
052:
053: private void addComponents(final Item item) {
054: final ItemSearch itemSearch = getCurrentItemSearch();
055: add(new ItemRelatePanel("relate", true));
056: Link link = new Link("back") {
057: public void onClick() {
058: itemSearch.setSelectedItemId(item.getId());
059: if (itemSearch.getRefId() != null) {
060: // user had entered item id directly, go back to search page
061: setResponsePage(new ItemSearchFormPage(itemSearch));
062: } else {
063: setResponsePage(ItemListPage.class);
064: }
065: }
066: };
067: if (itemSearch == null) {
068: link.setVisible(false);
069: }
070:
071: add(link);
072:
073: boolean isRelate = itemSearch != null
074: && itemSearch.getRelatingItemRefId() != null;
075:
076: User user = getPrincipal();
077:
078: if (!user.getSpaces().contains(item.getSpace())) {
079: logger.debug("user is not allocated to space");
080: throw new RestartResponseAtInterceptPageException(
081: ErrorPage.class);
082: }
083:
084: add(new Link("edit") {
085: public void onClick() {
086: setResponsePage(new ItemFormPage(item.getId()));
087: }
088: }.setVisible(user.isAdminForAllSpaces()));
089:
090: add(new ItemViewPanel("itemViewPanel", item, isRelate
091: || user.getId() == 0));
092:
093: if (user.isGuestForSpace(item.getSpace()) || isRelate) {
094: add(new WebMarkupContainer("itemViewFormPanel")
095: .setVisible(false));
096: } else {
097: add(new ItemViewFormPanel("itemViewFormPanel", item,
098: itemSearch));
099: }
100: }
101:
102: }
|