Skip to content

Commit 5165b7a

Browse files
committed
fix
1 parent d5d27b3 commit 5165b7a

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

options/locale/locale_en-US.ini

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,18 +3722,22 @@ owner.settings.chef.keypair.description = A key pair is necessary to authenticat
37223722
secrets = Secrets
37233723
description = Secrets will be passed to certain actions and cannot be read otherwise.
37243724
none = There are no secrets yet.
3725-
creation = Add Secret
3725+
3726+
; These keys are also for "edit secret", the keys are kept as-is to avoid unnecessary re-translation
37263727
creation.description = Description
37273728
creation.name_placeholder = case-insensitive, alphanumeric characters or underscores only, cannot start with GITEA_ or GITHUB_
37283729
creation.value_placeholder = Input any content. Whitespace at the start and end will be omitted.
37293730
creation.description_placeholder = Enter short description (optional).
3730-
creation.success = The secret "%s" has been added.
3731-
creation.failed = Failed to add secret.
3731+
3732+
save_success = The secret "%s" has been saved.
3733+
save_failed = Failed to save secret.
3734+
3735+
add_secret = Add secret
3736+
edit_secret = Edit secret
37323737
deletion = Remove secret
37333738
deletion.description = Removing a secret is permanent and cannot be undone. Continue?
37343739
deletion.success = The secret has been removed.
37353740
deletion.failed = Failed to remove secret.
3736-
edit = Edit secret
37373741
management = Secrets Management
37383742
37393743
[actions]

routers/web/shared/secrets/secrets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func PerformSecretsPost(ctx *context.Context, ownerID, repoID int64, redirectURL
3232
s, _, err := secret_service.CreateOrUpdateSecret(ctx, ownerID, repoID, form.Name, util.ReserveLineBreakForTextarea(form.Data), form.Description)
3333
if err != nil {
3434
log.Error("CreateOrUpdateSecret failed: %v", err)
35-
ctx.JSONError(ctx.Tr("secrets.creation.failed"))
35+
ctx.JSONError(ctx.Tr("secrets.save_failed"))
3636
return
3737
}
3838

39-
ctx.Flash.Success(ctx.Tr("secrets.creation.success", s.Name))
39+
ctx.Flash.Success(ctx.Tr("secrets.save_success", s.Name))
4040
ctx.JSONRedirect(redirectURL)
4141
}
4242

templates/shared/secrets/add_list.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<button class="ui primary tiny button show-modal"
55
data-modal="#add-secret-modal"
66
data-modal-form.action="{{.Link}}"
7-
data-modal-header="{{ctx.Locale.Tr "secrets.creation"}}"
7+
data-modal-header="{{ctx.Locale.Tr "secrets.add_secret"}}"
88
data-modal-secret-name.value=""
9-
data-modal-secret-name.read-only=""
9+
data-modal-secret-name.read-only="false"
1010
data-modal-secret-data=""
1111
data-modal-secret-description=""
1212
>
13-
{{ctx.Locale.Tr "secrets.creation"}}
13+
{{ctx.Locale.Tr "secrets.add_secret"}}
1414
</button>
1515
</div>
1616
</h4>
@@ -40,8 +40,8 @@
4040
<button class="ui btn interact-bg show-modal tw-p-2"
4141
data-modal="#add-secret-modal"
4242
data-modal-form.action="{{$.Link}}"
43-
data-modal-header="{{ctx.Locale.Tr "secrets.creation"}}"
44-
data-tooltip-content="{{ctx.Locale.Tr "secrets.edit"}}"
43+
data-modal-header="{{ctx.Locale.Tr "secrets.edit_secret"}}"
44+
data-tooltip-content="{{ctx.Locale.Tr "secrets.edit_secret"}}"
4545
data-modal-secret-name.value="{{.Name}}"
4646
data-modal-secret-name.read-only="true"
4747
data-modal-secret-data=""

web_src/js/features/common-button.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,29 @@ function onHidePanelClick(el: HTMLElement, e: MouseEvent) {
102102
throw new Error('no panel to hide'); // should never happen, otherwise there is a bug in code
103103
}
104104

105+
function assignElementProperty(el: any, name: string, val: string) {
106+
name = camelize(name);
107+
const old = el[name];
108+
if (typeof old === 'boolean') {
109+
el[name] = val === 'true';
110+
} else if (typeof old === 'number') {
111+
el[name] = parseFloat(val);
112+
} else if (typeof old === 'string') {
113+
el[name] = val;
114+
} else {
115+
// in the future, we could introduce a better typing system like `data-modal-form.action:string="..."`
116+
throw new Error(`cannot assign element property ${name} by value ${val}`);
117+
}
118+
}
119+
105120
function onShowModalClick(el: HTMLElement, e: MouseEvent) {
106121
// A ".show-modal" button will show a modal dialog defined by its "data-modal" attribute.
107122
// Each "data-modal-{target}" attribute will be filled to target element's value or text-content.
108123
// * First, try to query '#target'
109124
// * Then, try to query '[name=target]'
110125
// * Then, try to query '.target'
111126
// * Then, try to query 'target' as HTML tag
112-
// If there is a ".{attr}" part like "data-modal-form.action", then the form's "action" attribute will be set.
127+
// If there is a ".{attr}" part like "data-modal-form.action", then the form's "action" property will be set.
113128
e.preventDefault();
114129
const modalSelector = el.getAttribute('data-modal');
115130
const elModal = document.querySelector(modalSelector);
@@ -122,7 +137,7 @@ function onShowModalClick(el: HTMLElement, e: MouseEvent) {
122137
}
123138

124139
const attrTargetCombo = attrib.name.substring(modalAttrPrefix.length);
125-
const [attrTargetName, attrTargetAttr] = attrTargetCombo.split('.');
140+
const [attrTargetName, attrTargetProp] = attrTargetCombo.split('.');
126141
// try to find target by: "#target" -> "[name=target]" -> ".target" -> "<target> tag"
127142
const attrTarget = elModal.querySelector(`#${attrTargetName}`) ||
128143
elModal.querySelector(`[name=${attrTargetName}]`) ||
@@ -133,8 +148,8 @@ function onShowModalClick(el: HTMLElement, e: MouseEvent) {
133148
continue;
134149
}
135150

136-
if (attrTargetAttr) {
137-
(attrTarget as any)[camelize(attrTargetAttr)] = attrib.value;
151+
if (attrTargetProp) {
152+
assignElementProperty(attrTarget, attrTargetProp, attrib.value);
138153
} else if (attrTarget.matches('input, textarea')) {
139154
(attrTarget as HTMLInputElement | HTMLTextAreaElement).value = attrib.value; // FIXME: add more supports like checkbox
140155
} else {

0 commit comments

Comments
 (0)