001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.petstore.console.dev; 018 019import java.util.*; 020 021import org.apache.juneau.http.*; 022import org.apache.juneau.marshall.collections.*; 023import org.apache.juneau.petstore.console.*; 024import org.apache.juneau.petstore.console.pages.*; 025import org.apache.juneau.rest.server.*; 026import org.apache.juneau.console.views.*; 027import org.apache.juneau.console.widgets.*; 028import org.apache.juneau.rest.server.view.*; 029 030/** 031 * Dialogs (builder only): a permanent demo of the two dialog navigation styles, a {@code ModalDef.steps} wizard and a 032 * {@code nav:"folder"} sectioned form, each opened from a ribbon button. 033 * 034 * <p> 035 * Nothing is stored: the submit endpoint accepts the dialog envelope and answers with a success toast. The page 036 * exists so the screenshot sweep and a person can see both dialogs in every palette and scheme. 037 * 038 * <h2 class='section'>Example:</h2> 039 * <p class='bcode'> 040 * GET /console/dev/dialogs 041 * GET /console/dev/dialogs/wizard-form 042 * GET /console/dev/dialogs/folder-form 043 * </p> 044 */ 045@Rest(path="/dialogs", title="Dialogs") 046@SuppressWarnings({ 047 "java:S110" // Inheritance depth comes from the BasicRestServlet hierarchy, not this page. 048}) 049public class DialogsRest extends PetstoreConsolePage { 050 051 private static final long serialVersionUID = 1L; 052 053 /** 054 * Renders the Dialogs page. 055 * 056 * @param req The request. 057 * @return The page. 058 */ 059 @RestGet(path="/") 060 public View page(RestRequest req) { 061 return twin(req, DevPageBuilders.dialogs()); 062 } 063 064 /** 065 * The rows the page's table draws: one per dialog style. 066 * 067 * @return One row per style. 068 */ 069 @RestGet(path="/rows") 070 public List<Map<String,Object>> rows() { 071 return List.of(Map.of("style", "wizard", "steps", 3), Map.of("style", "folder", "steps", 3)); 072 } 073 074 /** 075 * The wizard dialog: three steps with display fields, Back and Next, and a step rail. 076 * 077 * @return The dialog. 078 */ 079 @RestGet(path="/wizard-form") 080 public ModalDef wizardForm() { 081 return ModalDef.create("Register a pet") 082 .step(ModalDef.Step.of("species").title("Pick a species").field("Species", "Dog").field("Breed", "Beagle")) 083 .step(ModalDef.Step.of("owner").title("Owner").field("Name", "Mary Watson").field("Phone", "555-0100")) 084 .step(ModalDef.Step.of("review").title("Review").confirmLabel("Register").field("Fee", "$25.00")); 085 } 086 087 /** 088 * The folder-tab dialog: a sectioned form drawn with square-topped folder tabs. 089 * 090 * @return The dialog. 091 */ 092 @RestGet(path="/folder-form") 093 public ModalDef folderForm() { 094 var form = FormDef.create() 095 .section(FormDef.Section.of("basics", "Basics") 096 .field(FormDef.Input.of("name", "Name", "text").required()) 097 .field(FormDef.Input.of("notes", "Notes", "textarea"))) 098 .section(FormDef.Section.of("options", "Options") 099 .field(FormDef.Input.of("notify", "Notify me", "toggle"))) 100 .section(FormDef.Section.of("danger", "Advanced") 101 .field(FormDef.Input.of("code", "Code", "text"))); 102 return ModalDef.create("Pet settings").nav(ModalDef.NAV_FOLDER).form(form); 103 } 104 105 /** 106 * Accepts either dialog's submit and stores nothing. 107 * 108 * @param body The dialog envelope; ignored. 109 * @return A success toast. 110 */ 111 @RestPost(path="/submit") 112 public ActionResult submit(@Content JsonMap body) { 113 return ActionResult.ok().message("Saved (demo only, nothing is stored)"); 114 } 115}