Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
5a30fa24
Commit
5a30fa24
authored
8 months ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
transfer changes to dialog buttons from original button, fixes #4745
Closes #4745 Merge request
studip/studip!3540
parent
efb19ff8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
resources/assets/javascripts/lib/dialog.js
+51
-25
51 additions, 25 deletions
resources/assets/javascripts/lib/dialog.js
with
51 additions
and
25 deletions
resources/assets/javascripts/lib/dialog.js
+
51
−
25
View file @
5a30fa24
...
@@ -21,31 +21,40 @@ var dialog_margin = 0;
...
@@ -21,31 +21,40 @@ var dialog_margin = 0;
/**
/**
* Extract buttons from given element.
* Extract buttons from given element.
*
* @param {Element} element
* @param {function|null} callback
*/
*/
function
extractButtons
(
element
)
{
function
extractButtons
(
element
,
callback
=
null
)
{
var
buttons
=
{}
;
const
buttons
=
[]
;
$
(
'
[data-dialog-button]
'
,
element
)
$
(
'
[data-dialog-button]
'
,
element
)
.
hide
()
.
hide
()
.
find
(
'
a,button
'
)
.
find
(
'
a,button
'
)
.
addBack
()
.
addBack
()
.
filter
(
'
a,button
'
)
.
filter
(
'
a,button
'
)
.
each
(
function
()
{
.
each
(
function
()
{
var
label
=
$
(
this
).
text
();
const
id
=
$
(
this
).
uniqueId
().
attr
(
'
id
'
);
var
cancel
=
$
(
this
).
is
(
'
.cancel
'
);
const
label
=
$
(
this
).
text
();
var
index
=
cancel
?
'
cancel
'
:
label
;
const
cancel
=
$
(
this
).
is
(
'
.cancel
'
);
var
classes
=
$
(
this
).
attr
(
'
class
'
)
||
''
;
const
index
=
cancel
?
'
cancel
'
:
label
;
var
name
=
$
(
this
).
attr
(
'
name
'
)
||
''
;
let
classes
=
$
(
this
).
attr
(
'
class
'
)
||
''
;
var
disabled
=
$
(
this
).
is
(
'
:disabled
'
);
const
name
=
$
(
this
).
attr
(
'
name
'
)
||
''
;
const
disabled
=
$
(
this
).
is
(
'
:disabled
'
);
classes
=
classes
.
replace
(
/
\b
button
\b
/
,
''
).
trim
();
classes
=
classes
.
replace
(
/
\b
button
\b
/
,
''
).
trim
();
buttons
[
index
]
=
{
buttons
.
push
({
id
:
id
,
text
:
label
,
text
:
label
,
class
:
classes
,
class
:
classes
,
name
:
name
,
name
:
name
,
disabled
:
disabled
,
disabled
:
disabled
,
click
:
()
=>
this
.
click
()
click
:
()
=>
this
.
click
()
};
});
if
(
callback
!==
null
)
{
callback
(
this
,
index
);
}
});
});
return
buttons
;
return
buttons
;
...
@@ -403,13 +412,6 @@ Dialog.show = function(content, options = {}) {
...
@@ -403,13 +412,6 @@ Dialog.show = function(content, options = {}) {
$
(
'
head
'
).
append
(
scripts
);
$
(
'
head
'
).
append
(
scripts
);
$
(
options
.
origin
||
document
).
trigger
(
'
dialog-open
'
,
{
dialog
:
this
,
options
:
options
});
$
(
options
.
origin
||
document
).
trigger
(
'
dialog-open
'
,
{
dialog
:
this
,
options
:
options
});
// Transfer defined classes from options to actual displayed buttons
// This should work natively, but it kinda does not
Object
.
keys
(
dialog_options
.
buttons
).
forEach
(
function
(
label
,
index
)
{
var
classes
=
dialog_options
.
buttons
[
label
][
'
class
'
];
$
(
buttons
.
get
(
index
)).
addClass
(
classes
);
});
},
},
close
:
function
(
event
)
{
close
:
function
(
event
)
{
$
(
options
.
origin
||
document
).
trigger
(
'
dialog-close
'
,
{
dialog
:
this
,
options
:
options
});
$
(
options
.
origin
||
document
).
trigger
(
'
dialog-close
'
,
{
dialog
:
this
,
options
:
options
});
...
@@ -425,17 +427,41 @@ Dialog.show = function(content, options = {}) {
...
@@ -425,17 +427,41 @@ Dialog.show = function(content, options = {}) {
options
.
buttons
===
undefined
options
.
buttons
===
undefined
||
(
options
.
buttons
&&
!
$
.
isPlainObject
(
options
.
buttons
))
||
(
options
.
buttons
&&
!
$
.
isPlainObject
(
options
.
buttons
))
)
{
)
{
dialog_options
.
buttons
=
extractButtons
.
call
(
this
,
instance
.
element
);
// Create observer to detect changes on disabled attribute
const
observer
=
new
MutationObserver
((
mutations
)
=>
{
mutations
.
forEach
(
mutation
=>
{
const
id
=
mutation
.
target
.
id
;
const
buttonIndex
=
dialog_options
.
buttons
.
findIndex
(
button
=>
button
.
id
===
id
);
if
(
mutation
.
attributeName
===
'
disabled
'
)
{
dialog_options
.
buttons
[
buttonIndex
].
disabled
=
mutation
.
target
.
disabled
;
}
else
if
(
mutation
.
attributeName
===
'
class
'
)
{
const
classes
=
mutation
.
target
.
classList
.
toString
();
dialog_options
.
buttons
[
buttonIndex
].
class
=
classes
.
replace
(
/
\b
button
\b
/
,
''
);
}
instance
.
element
.
dialog
(
'
option
'
,
'
buttons
'
,
dialog_options
.
buttons
);
});
});
dialog_options
.
buttons
=
extractButtons
(
instance
.
element
,
(
button
)
=>
{
observer
.
observe
(
button
,
{
attributes
:
true
,
attributeFilter
:
[
'
class
'
,
'
disabled
'
],
});
});
// Create 'close' button
// Create 'close' button
if
(
dialog_options
.
buttons
.
cancel
===
undefined
)
{
const
cancelButton
=
dialog_options
.
buttons
.
find
(
button
=>
button
.
class
.
split
(
'
'
).
includes
(
'
cancel
'
));
dialog_options
.
buttons
.
cancel
=
{
if
(
!
cancelButton
)
{
dialog_options
.
buttons
.
push
({
text
:
$gettext
(
'
Schließen
'
),
text
:
$gettext
(
'
Schließen
'
),
'
class
'
:
'
cancel
'
class
:
'
cancel
'
,
};
click
:
()
=>
Dialog
.
close
(
options
),
});
}
else
{
cancelButton
.
click
=
()
=>
Dialog
.
close
(
options
);
}
}
dialog_options
.
buttons
.
cancel
.
click
=
function
()
{
Dialog
.
close
(
options
);
};
}
}
// Create/update dialog
// Create/update dialog
...
...
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