/*
 * Copyright 2012 s_wolff.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.aegee.runanddine.feedback;

import java.util.List;

import org.aegee.runanddine.BasePage;
import org.aegee.runanddine.runanddine.RDManager;
import org.aegee.runanddine.runanddine.RunAndDine;
import org.aegee.runanddine.util.DateFormat;
import org.aegee.runanddine.util.data.ModelNotExistingException;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.request.mapper.parameter.PageParameters;

/**
 * Displays RunAndDines with feedback existing
 * @author s_wolff
 */
public class FeedbackOverviewPage extends BasePage {

    /**
     * Page constructor for page parameters
     * @param parameters HTTP parameters
     * @throws ModelNotExistingException
     */
    public FeedbackOverviewPage(PageParameters parameters) throws ModelNotExistingException {
        super(parameters);

        List<RunAndDine> allRds = RDManager.getInstance().getAll();
        ListView<RunAndDine> listView = new ListView<RunAndDine>("row", allRds) {

            @Override
            protected void populateItem(ListItem<RunAndDine> li) {
                RunAndDine rad = li.getModelObject();
                li.add(new Label("date", DateFormat.format(rad.getDate())));
                li.add(new Label("motto", rad.getMotto()));
                li.add(new BookmarkablePageLink("link", FeedbackInspector.class,
                        new PageParameters("id=" + new Integer(rad.getId()))));
            }
        };
        this.add(listView);
    }
}
