mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-12-27 07:03:26 +08:00
a bit of work on the two creation forms
This commit is contained in:
parent
7db739e3b6
commit
9953c75e87
@ -1,5 +1,8 @@
|
||||
package me.minidigger.hangar.controller;
|
||||
|
||||
import freemarker.ext.beans.BeansWrapperBuilder;
|
||||
import freemarker.template.Configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@ -14,6 +17,10 @@ public abstract class HangarController {
|
||||
protected ModelAndView fillModel(ModelAndView mav) {
|
||||
mav.addObject("modelData", new ModelData());
|
||||
mav.addObject("routes", routeHelper);
|
||||
BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_30);
|
||||
builder.setExposeFields(true);
|
||||
builder.setUseModelCache(true);
|
||||
mav.addObject("@helper", builder.build().getStaticModels());
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
|
@ -7,33 +7,66 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
* Gets or Sets Category
|
||||
*/
|
||||
public enum Category {
|
||||
ADMIN_TOOLS("admin_tools"),
|
||||
CHAT("chat"),
|
||||
DEV_TOOLS("dev_tools"),
|
||||
ECONOMY("economy"),
|
||||
GAMEPLAY("gameplay"),
|
||||
GAMES("games"),
|
||||
PROTECTION("protection"),
|
||||
ROLE_PLAYING("role_playing"),
|
||||
WORLD_MANAGEMENT("world_management"),
|
||||
MISC("misc");
|
||||
ADMIN_TOOLS(0, "Admin Tools", "fa-server", "admin_tools"),
|
||||
CHAT(1, "Chat", "fa-comment", "chat"),
|
||||
DEV_TOOLS(2, "Developer Tools", "fa-wrench", "dev_tools"),
|
||||
ECONOMY(3, "Economy", "fa-money-bill-alt", "economy"),
|
||||
GAMEPLAY(4, "Gameplay", "fa-puzzle-piece", "gameplay"),
|
||||
GAMES(5, "Games", "fa-gamepad", "games"),
|
||||
PROTECTION(6, "Protection", "fa-lock", "protection"),
|
||||
ROLE_PLAYING(7, "Role Playing", "fa-magic", "role_playing"),
|
||||
WORLD_MANAGEMENT(8, "World Management", "fa-globe", "world_management"),
|
||||
MISC(9, "Miscellaneous", "fa-asterisk", "misc"),
|
||||
UNDEFINED(10, "Undefined", "", "undefined");
|
||||
|
||||
private final String value;
|
||||
private final int value;
|
||||
private final String title;
|
||||
private final String icon;
|
||||
private final boolean isVisible;
|
||||
private final String apiName;
|
||||
|
||||
Category(String value) {
|
||||
Category(int value, String title, String icon, String apiName) {
|
||||
this(value, title, icon, apiName, true);
|
||||
}
|
||||
|
||||
Category(int value, String title, String icon, String apiName, boolean isVisible) {
|
||||
this.value = value;
|
||||
this.title = title;
|
||||
this.icon = icon;
|
||||
this.apiName = apiName;
|
||||
this.isVisible = isVisible;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return isVisible;
|
||||
}
|
||||
|
||||
public String getApiName() {
|
||||
return apiName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
return apiName;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static Category fromValue(String text) {
|
||||
for (Category b : Category.values()) {
|
||||
if (String.valueOf(b.value).equals(text)) {
|
||||
if (b.apiName.equals(text)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,10 @@
|
||||
<div class="project-body panel-body">
|
||||
<p class="minor"> <@spring.message "org.info" /></p>
|
||||
|
||||
@form(action = routes.Organizations.create(), Symbol("id") -> "form-continue") {
|
||||
@CSRF.formField
|
||||
<#import "*/utils/form.ftlh" as form>
|
||||
<@form.form action=routes.getRouteUrl("org.create") method="POST" id="form-continue">
|
||||
<#import "*/utils/csrf.ftlh" as csrf>
|
||||
<@csrf.formField />
|
||||
<div class="setting">
|
||||
<div class="setting-description">
|
||||
<h4><@spring.message "org.name" /></h4>
|
||||
@ -33,9 +35,11 @@
|
||||
<i class="fas fa-spinner fa-spin status-org-name" style="display: none;"></i>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
}
|
||||
</@form.form>
|
||||
|
||||
@users.invite.form(owner = request.headerData.currentUser.get, roleCategory = RoleCategory.Organization)
|
||||
<#import "*/users/invite/form.ftlh" as userForm>
|
||||
<#-- <@userForm.form owner=request.headerData.currentUser roleCategory=RoleCategory.Organization />-->
|
||||
<@userForm.form owner="" roleCategory="" />
|
||||
|
||||
<button title="Continue" type="submit" name="create" form="form-continue"
|
||||
value="<@spring.message "general.continue" />"
|
||||
|
@ -26,7 +26,7 @@ showFooter: Boolean = true, noContainer: Boolean = false, additionalMeta: Html =
|
||||
<link rel="prefetch" href="<@hangar.url "manifest/manifest.json" />">
|
||||
<link rel="prefetch" href="<@hangar.url "lib/jquery/dist/jquery.min.js" />">
|
||||
|
||||
<title>${title}</title>
|
||||
<title>${title} | Hangar</title>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
|
@ -41,8 +41,10 @@ Page used for uploading and creating new projects.
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@form(action = routes.getRouteUrl("projects.createProject")) {
|
||||
@CSRF.formField
|
||||
<#import "*/utils/form.ftlh" as form>
|
||||
<@form.form action=routes.getRouteUrl("projects.createProject") method="POST">
|
||||
<#import "*/utils/csrf.ftlh" as csrf>
|
||||
<@csrf.formField />
|
||||
<div class="form-group">
|
||||
<label for="projectName"><@spring.message "project.create.input.name" /></label>
|
||||
<input type="text" id="projectName" name="name" class="form-control">
|
||||
@ -56,8 +58,8 @@ Page used for uploading and creating new projects.
|
||||
<div class="form-group">
|
||||
<label for="projectCategory"><@spring.message "project.create.input.category" /></label>
|
||||
<select id="projectCategory" name="category" class="form-control">
|
||||
<#-- todo: Category.visible -->
|
||||
<#list Category.visible as cat>
|
||||
<#assign Category=@helper["me.minidigger.hangar.model.Category"]>
|
||||
<#list Category.values() as cat>
|
||||
<option>${cat.title}</option>
|
||||
</#list>
|
||||
</select>
|
||||
@ -71,7 +73,7 @@ Page used for uploading and creating new projects.
|
||||
<div class="form-group">
|
||||
<label for="projectCategory"><@spring.message "project.owner" /></label>
|
||||
<select id="projectCategory" name="owner" class="form-control">
|
||||
<option value="@user.id.value">@user.name</option>
|
||||
<option value="${user.id.value}">${user.name}</option>
|
||||
<#list createProjectOrgas as orga>
|
||||
<option value="${orga.id.value}">${orga.name}</option>
|
||||
</#list>
|
||||
@ -79,7 +81,7 @@ Page used for uploading and creating new projects.
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Create project</button>
|
||||
}
|
||||
</@form.form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<#import "/spring.ftl" as spring />
|
||||
<#import "*/utils/hangar.ftlh" as hangar />
|
||||
|
||||
<#--
|
||||
@import ore.OreConfig
|
||||
@import ore.db.Model
|
||||
@import ore.models.user.User
|
||||
@ -9,6 +10,9 @@
|
||||
@import views.html.utils.userAvatar
|
||||
|
||||
@(owner: User, loadedUsers: Seq[Model[User]] = Seq(), roleCategory: RoleCategory)(implicit messages: Messages, config: OreConfig)
|
||||
-->
|
||||
|
||||
<#macro form owner roleCategory loadedUsers=[]>
|
||||
|
||||
<!-- Template row -->
|
||||
<table style="display: none;">
|
||||
@ -16,7 +20,9 @@
|
||||
<tr id="result-row">
|
||||
<td>
|
||||
<input type="hidden"/>
|
||||
@userAvatar(None, clazz = "user-avatar-xs")
|
||||
<#import "*/utils/userAvatar.ftlh" as userAvatar>
|
||||
<@userAvatar.userAvatar clazz = "user-avatar-xs"/>
|
||||
<#-- @userAvatar(None, clazz = "user-avatar-xs")-->
|
||||
<i class="fas fa-times user-cancel"></i>
|
||||
<a class="username" target="_blank" rel="noopener" href=""></a>
|
||||
<span>@users.invite.roleSelect(roleCategory)</span>
|
||||
@ -66,3 +72,4 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</#macro>
|
||||
|
3
src/main/resources/templates/utils/csrf.ftlh
Normal file
3
src/main/resources/templates/utils/csrf.ftlh
Normal file
@ -0,0 +1,3 @@
|
||||
<#macro formField>
|
||||
<#-- TODO CSRF form field -->
|
||||
</#macro>
|
5
src/main/resources/templates/utils/form.ftlh
Normal file
5
src/main/resources/templates/utils/form.ftlh
Normal file
@ -0,0 +1,5 @@
|
||||
<#macro form action method id="">
|
||||
<form action="${action}" method="${method}" <#if id??>id="${id}"</#if>>
|
||||
<#nested>
|
||||
</form>
|
||||
</#macro>
|
Loading…
Reference in New Issue
Block a user