From f20057271def2240474d64c57eeba8b365642c08 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 17 Apr 2023 23:35:57 +0800 Subject: [PATCH] Fix Org edit page bugs: renaming detection, maxlength (#24161) ## Before * The renaming detection is wrong (eg: pasting a new name into the input doesn't trigger the detection) * The renaming prompt layout is not good * Some MaxSize/maxlength rules is missing ![image](https://user-images.githubusercontent.com/2114189/232379191-5d0f6d10-56ca-4cec-ac52-7f77b9cb4a8a.png) ![image](https://user-images.githubusercontent.com/2114189/232379234-3289373b-9ddb-4627-ae86-f4d74589fa0c.png) ## After * Fix these problems ![image](https://user-images.githubusercontent.com/2114189/232379098-31c6fa21-c210-4e7f-a337-b38b99670835.png) --- modules/structs/org.go | 6 +++--- templates/org/create.tmpl | 2 +- templates/org/settings/options.tmpl | 15 ++++++++------- web_src/js/features/common-organization.js | 19 +++++-------------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/modules/structs/org.go b/modules/structs/org.go index b4c58623fd..7c83dcdee7 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -30,8 +30,8 @@ type OrganizationPermissions struct { // CreateOrgOption options for creating an organization type CreateOrgOption struct { // required: true - UserName string `json:"username" binding:"Required"` - FullName string `json:"full_name"` + UserName string `json:"username" binding:"Required;Username;MaxSize(40)"` + FullName string `json:"full_name" binding:"MaxSize(100)"` Description string `json:"description" binding:"MaxSize(255)"` Website string `json:"website" binding:"ValidUrl;MaxSize(255)"` Location string `json:"location" binding:"MaxSize(50)"` @@ -45,7 +45,7 @@ type CreateOrgOption struct { // EditOrgOption options for editing an organization type EditOrgOption struct { - FullName string `json:"full_name"` + FullName string `json:"full_name" binding:"MaxSize(100)"` Description string `json:"description" binding:"MaxSize(255)"` Website string `json:"website" binding:"ValidUrl;MaxSize(255)"` Location string `json:"location" binding:"MaxSize(50)"` diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index f734a39a93..7e988ba0c7 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -11,7 +11,7 @@ {{template "base/alert" .}}
- + {{.locale.Tr "org.org_name_helper"}}
diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 833b97e347..1caa4210e6 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -14,26 +14,27 @@ {{.CsrfTokenHtml}}
- +
- +
- +
- +
- +
diff --git a/web_src/js/features/common-organization.js b/web_src/js/features/common-organization.js index 1796efc6a8..352e824b05 100644 --- a/web_src/js/features/common-organization.js +++ b/web_src/js/features/common-organization.js @@ -1,25 +1,16 @@ import $ from 'jquery'; import {initCompLabelEdit} from './comp/LabelEdit.js'; -import {hideElem, showElem} from '../utils/dom.js'; +import {toggleElem} from '../utils/dom.js'; export function initCommonOrganization() { if ($('.organization').length === 0) { return; } - if ($('.organization.settings.options').length > 0) { - $('#org_name').on('keyup', function () { - const $prompt = $('#org-name-change-prompt'); - const $prompt_redirect = $('#org-name-change-redirect-prompt'); - if ($(this).val().toString().toLowerCase() !== $(this).data('org-name').toString().toLowerCase()) { - showElem($prompt); - showElem($prompt_redirect); - } else { - hideElem($prompt); - hideElem($prompt_redirect); - } - }); - } + $('.organization.settings.options #org_name').on('input', function () { + const nameChanged = $(this).val().toLowerCase() !== $(this).attr('data-org-name').toLowerCase(); + toggleElem('#org-name-change-prompt', nameChanged); + }); // Labels initCompLabelEdit('.organization.settings.labels');