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 static info.jtrac.domain.ItemItem.*;
020:
021: import info.jtrac.domain.Item;
022: import info.jtrac.domain.ItemItem;
023: import info.jtrac.wicket.yui.YuiDialog;
024: import org.apache.wicket.PageParameters;
025: import org.apache.wicket.ajax.AjaxRequestTarget;
026: import org.apache.wicket.ajax.markup.html.AjaxLink;
027: import org.apache.wicket.markup.html.basic.Label;
028: import org.apache.wicket.markup.html.form.Form;
029: import org.apache.wicket.markup.html.form.TextArea;
030: import org.apache.wicket.model.BoundCompoundPropertyModel;
031:
032: /**
033: * small form only to confirm and capture comment when removing relationship
034: * between items
035: */
036: public class ItemRelateRemovePage extends BasePage {
037:
038: private long itemId;
039: private ItemItem itemItem;
040:
041: public ItemRelateRemovePage(long itemId, final ItemItem itemItem) {
042: this .itemId = itemId;
043: this .itemItem = itemItem;
044: add(new ConfirmForm("form"));
045: final String relatingRefId = itemItem.getItem().getRefId();
046: final String relatedRefId = itemItem.getRelatedItem()
047: .getRefId();
048: final YuiDialog relatingDialog = new YuiDialog("relatingDialog");
049: final YuiDialog relatedDialog = new YuiDialog("relatedDialog");
050: add(relatingDialog);
051: add(relatedDialog);
052: AjaxLink relating = new AjaxLink("relating") {
053: public void onClick(AjaxRequestTarget target) {
054: Item relating = getJtrac().loadItem(
055: itemItem.getItem().getId());
056: relatingDialog.show(target, relatingRefId,
057: new ItemViewPanel(YuiDialog.CONTENT_ID,
058: relating, true));
059: }
060: };
061: relating.add(new Label("refId", relatingRefId));
062: add(relating);
063:
064: // TODO refactor, duplicate code in ItemViewPanel
065: String message = null;
066: if (itemItem.getType() == DUPLICATE_OF) {
067: message = localize("item_view.duplicateOf");
068: } else if (itemItem.getType() == DEPENDS_ON) {
069: message = localize("item_view.dependsOn");
070: } else if (itemItem.getType() == RELATED) {
071: message = localize("item_view.relatedTo");
072: }
073: add(new Label("message", message));
074:
075: AjaxLink related = new AjaxLink("related") {
076: public void onClick(AjaxRequestTarget target) {
077: Item related = getJtrac().loadItem(
078: itemItem.getRelatedItem().getId());
079: relatedDialog.show(target, relatedRefId,
080: new ItemViewPanel(YuiDialog.CONTENT_ID,
081: related, true));
082: }
083: };
084: related.add(new Label("refId", itemItem.getRelatedItem()
085: .getRefId()));
086: add(related);
087:
088: }
089:
090: /**
091: * wicket form
092: */
093: private class ConfirmForm extends Form {
094:
095: private String comment;
096:
097: public ConfirmForm(String id) {
098: super (id);
099: setModel(new BoundCompoundPropertyModel(this ));
100: TextArea commentArea = new TextArea("comment");
101: commentArea.setRequired(true);
102: commentArea.add(new ErrorHighlighter());
103: add(commentArea);
104: }
105:
106: public String getComment() {
107: return comment;
108: }
109:
110: public void setComment(String comment) {
111: this .comment = comment;
112: }
113:
114: @Override
115: protected void onSubmit() {
116: getJtrac().removeItemItem(itemItem);
117: Item item = getJtrac().loadItem(itemId);
118: item.setEditReason(comment);
119: getJtrac().updateItem(item, getPrincipal());
120: setResponsePage(ItemViewPage.class, new PageParameters("0="
121: + item.getRefId()));
122: }
123:
124: }
125:
126: }
|