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.pages; 018 019import org.apache.juneau.console.freemarker.*; 020import org.apache.juneau.console.views.*; 021import org.apache.juneau.console.views.RowAction.*; 022import org.apache.juneau.console.views.TableSpec.*; 023 024/** 025 * Builder twin of the Users page (P11, {@code users.ftlh}). 026 * 027 * <h5 class='section'>Example:</h5> 028 * <p class='bjava'> 029 * <jk>return</jk> <jsm>twin</jsm>(<jv>req</jv>, UsersPageBuilders.<jsm>users</jsm>()); 030 * </p> 031 */ 032@SuppressWarnings({ 033 "java:S1192" // Page-definition ids and labels repeat as inline literals by design. 034}) 035public final class UsersPageBuilders { 036 037 private UsersPageBuilders() {} 038 039 /** 040 * P11 Users. 041 * 042 * @return The page spec. 043 */ 044 public static PageSpec users() { 045 return PageSpec.create().tab("users").toolkit("views") 046 .table(TableSpec.create("users").rowType("User").dataMode(DataMode.SERVER).dataUrl("/console/users/query") 047 .defaultOrder("username", Sort.ASC) 048 .columns( 049 Column.create("username").label("Username"), 050 Column.create("firstName").label("First name"), 051 Column.create("lastName").label("Last name"), 052 Column.create("userStatus").label("Status").render("pill")) 053 .ribbon( 054 RibbonItem.optionGroup("userStatus", 055 RibbonItem.option("active").title("Active").column("userStatus").value("$eq(ACTIVE)"), 056 RibbonItem.option("inactive").title("Inactive").column("userStatus").value("$eq(INACTIVE)")) 057 .title("User status").deselectable(true), 058 RibbonItem.dialog("add-user").title("+ Add user").symbol("plus") 059 .form("/console/users/form").endpoint("/console/users").method(Method.POST).onSuccess(OnSuccess.REDRAW), 060 RibbonItem.refresh()) 061 .rowActions( 062 RowAction.create("edit").label("Edit").form("/console/users/form?username={username}").present(Present.DIALOG) 063 .endpoint("/console/users/{username}").method(Method.PUT).onSuccess(OnSuccess.REDRAW), 064 RowAction.create("delete").label("Delete").endpoint("/console/users/{username}").method(Method.DELETE) 065 .confirm("Delete user '{username}'?").confirmLabel("Delete").tone(Tone.DANGER).onSuccess(OnSuccess.REDRAW)), 066 "Users"); 067 } 068}