Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
proc
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
proc
Commits
e1b5c66c
Commit
e1b5c66c
authored
1 year ago
by
Rodrigo Panchiniak Fernandes
Browse files
Options
Downloads
Patches
Plain Diff
Fixed switching of multiple submit IDs.
parent
2c6bd020
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/proc-decrypt-dialog.js
+4
-0
4 additions, 0 deletions
js/proc-decrypt-dialog.js
js/proc-field.js
+75
-58
75 additions, 58 deletions
js/proc-field.js
with
79 additions
and
58 deletions
js/proc-decrypt-dialog.js
+
4
−
0
View file @
e1b5c66c
/**
* @file
* Protected Content dialog .
*
* @todo: we must apply this proc-decrypt-dialog library as a gate to all decrypt calls, or change its name to something
* less generic as proc-decrypt-dialog-default-format.
*
*/
(
function
(
$
,
Drupal
,
once
,
drupalSettings
,
window
)
{
Drupal
.
behaviors
.
ProcDecryptDialogBehavior
=
{
...
...
This diff is collapsed.
Click to expand it.
js/proc-field.js
+
75
−
58
View file @
e1b5c66c
/**
* @file
* Helper for entity reference proc field.
*
* @todo: we must apply this proc-field library as a gate to all dialog calls, or change its name to something less
* generic.
*/
(
function
(
$
,
Drupal
,
drupalSettings
,
once
)
{
Drupal
.
behaviors
.
ProcBehavior
=
{
'
attach
'
:
(
context
,
settings
)
=>
{
attach
(
context
,
settings
)
{
once
(
'
proc-decrypt
'
,
'
html
'
,
context
).
forEach
(
function
(
element
)
{
const
procFieldElements
=
document
.
querySelectorAll
(
'
[proc="true"]
'
);
const
procFields
=
[];
...
...
@@ -22,68 +20,87 @@
});
if
(
drupalSettings
.
proc
&&
drupalSettings
.
proc
.
submit_element_id
)
{
const
isMultipleSubmits
=
(
drupalSettings
.
proc
.
submit_element_id
.
search
(
'
,
'
)
>
-
1
);
const
submitIdsCsv
=
drupalSettings
.
proc
.
submit_element_id
.
replace
(
/ /g
,
''
);
const
submitIds
=
submitIdsCsv
.
split
(
'
,
'
);
let
submitElements
=
[];
submitIds
.
map
((
submitId
,
submitIndex
)
=>
{
submitElements
.
push
(
document
.
getElementById
(
submitId
));
});
if
(
isMultipleSubmits
)
{
const
submitIds
=
drupalSettings
.
proc
.
submit_element_id
.
split
(
'
,
'
);
submitIds
.
forEach
((
submitIdValue
)
=>
{
Drupal
.
behaviors
.
ProcBehavior
.
processSubmitButton
(
submitIdValue
.
trim
(),
procFields
);
});
}
else
{
const
submitId
=
drupalSettings
.
proc
.
submit_element_id
.
trim
();
Drupal
.
behaviors
.
ProcBehavior
.
processSubmitButton
(
submitId
,
procFields
);
}
}
});
},
'
processSubmitButton
'
:
(
submit_element_id
,
procFields
)
=>
{
let
submitElement
=
document
.
getElementById
(
submit_element_id
);
procFields
.
map
((
fieldName
,
fieldIndex
)
=>
{
let
input
=
document
.
querySelector
(
`[name^="
${
fieldName
}
"]`
);
input
.
addEventListener
(
"
input
"
,
updateValue
);
procFields
.
map
((
fieldName
,
fieldIndex
)
=>
{
var
field
=
document
.
querySelector
(
`[name^="
${
fieldName
}
"]`
);
field
.
oninput
=
()
=>
{
if
(
submitElement
.
disabled
===
false
&&
field
.
value
!=
''
)
{
// Disable submit when something is typed in for encryption:
submitElement
.
disabled
=
true
;
}
if
(
submitElement
.
disabled
===
true
&&
field
.
value
===
''
)
{
submitElement
.
disabled
=
false
;
}
};
var
encryptCheckbox
=
document
.
querySelector
(
`[id="encrypt-checkbox-
${
fieldName
}
"]`
);
function
updateValue
(
e
)
{
if
(
e
.
target
.
value
==
''
)
{
// If current field is empty and all other fields are empty:
let
empty
=
1
;
procFields
.
map
((
innerFieldName
,
innerFieldIndex
)
=>
{
let
innerInput
=
document
.
querySelector
(
`[name^="
${
innerFieldName
}
"]`
);
// Check if encryption checkbox is checked.
let
innerCheckbox
=
document
.
querySelector
(
`[id="encrypt-checkbox-
${
innerFieldName
}
"]`
);
if
(
innerInput
.
value
!=
''
&&
!
innerCheckbox
.
checked
)
{
empty
=
0
;
}
});
if
(
empty
==
1
)
{
// Enable submit when all fields are empty:
submitElements
.
map
((
submitElement
,
submitIndex
)
=>
{
submitElement
.
disabled
=
false
;
});
}
}
}
if
(
encryptCheckbox
)
{
encryptCheckbox
.
oninput
=
()
=>
{
if
(
encryptCheckbox
.
value
===
'
1
'
&&
submitElement
.
disabled
===
true
)
{
// If for all other fields there is no plain text:
let
index
=
0
;
procFields
.
map
((
fieldName
,
fieldIndex
)
=>
{
if
(
!
document
.
querySelector
(
`[name^="
${
fieldName
}
"]`
)
.
value
.
startsWith
(
'
******* (
'
)
)
{
index
++
;
const
field
=
document
.
querySelector
(
`[name^="
${
fieldName
}
"]`
);
field
.
oninput
=
()
=>
{
submitElements
.
map
((
submitElement
,
submitIndex
)
=>
{
if
(
submitElement
.
disabled
===
false
&&
field
.
value
!=
''
)
{
// Disable submit when something is typed in for encryption:
submitElement
.
disabled
=
true
;
}
});
if
(
index
===
1
)
{
submitElement
.
disabled
=
false
;
};
const
encryptCheckbox
=
document
.
querySelector
(
`[id="encrypt-checkbox-
${
fieldName
}
"]`
,
);
if
(
encryptCheckbox
)
{
encryptCheckbox
.
addEventListener
(
"
input
"
,
updateCheckboxValue
);
function
updateCheckboxValue
(
checkBoxEvent
)
{
if
(
checkBoxEvent
.
target
.
checked
)
{
// If for all other checkboxes are also checked:
let
checked
=
1
;
procFields
.
map
((
innerFieldName
,
innerFieldIndex
)
=>
{
let
innerCheckbox
=
document
.
querySelector
(
`[id="encrypt-checkbox-
${
innerFieldName
}
"]`
);
if
(
!
innerCheckbox
.
checked
)
{
let
innerInput
=
document
.
querySelector
(
`[name^="
${
innerFieldName
}
"]`
);
checked
=
0
;
if
(
innerInput
.
value
==
''
)
{
checked
=
1
;
}
}
});
if
(
checked
==
1
)
{
// Enable submit when all checkboxes are checked:
submitElements
.
map
((
submitElement
,
submitIndex
)
=>
{
submitElement
.
disabled
=
false
;
});
}
}
else
{
submitElements
.
map
((
submitElement
,
submitIndex
)
=>
{
if
(
submitElement
.
disabled
===
false
)
{
submitElement
.
disabled
=
true
;
}
});
}
}
}
if
(
encryptCheckbox
.
value
===
'
0
'
&&
submitElement
.
disabled
===
false
)
{
submitElement
.
disabled
=
true
;
}
};
});
}
});
}
}
,
};
})(
jQuery
,
Drupal
,
drupalSettings
,
once
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment