@@ -7,105 +7,112 @@ function matrixAuthEscapeHtml(html) {
7
7
/*
8
8
* This handles the addition of new users/groups to the list.
9
9
*/
10
- Behaviour . specify ( ".matrix-auth-add-button" , ' GlobalMatrixAuthorizationStrategy' , 0 , function ( e ) {
10
+ Behaviour . specify ( ".matrix-auth-add-button" , " GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
11
11
e . onclick = function ( e ) {
12
12
const dataReference = e . target ;
13
- const master = document . getElementById ( dataReference . getAttribute ( ' data-table-id' ) ) ;
13
+ const master = document . getElementById ( dataReference . getAttribute ( " data-table-id" ) ) ;
14
14
const table = master . parentNode ;
15
- const type = dataReference . getAttribute ( ' data-type' ) ;
16
- const typeLabel = dataReference . getAttribute ( ' data-type-label' ) ;
15
+ const type = dataReference . getAttribute ( " data-type" ) ;
16
+ const typeLabel = dataReference . getAttribute ( " data-type-label" ) ;
17
17
18
- dialog . prompt ( dataReference . getAttribute ( 'data-message-title' ) , {
19
- message : dataReference . getAttribute ( 'data-message-prompt' )
20
- } ) . then ( ( name ) => {
21
- if ( findElementsBySelector ( table , "TR" ) . find ( function ( n ) {
22
- return n . getAttribute ( "name" ) === '[' + type + ':' + name + ']' ;
23
- } ) != null ) {
24
- dialog . alert ( dataReference . getAttribute ( 'data-message-error' ) ) ;
25
- return ;
26
- }
18
+ dialog
19
+ . prompt ( dataReference . getAttribute ( "data-message-title" ) , {
20
+ message : dataReference . getAttribute ( "data-message-prompt" ) ,
21
+ } )
22
+ . then (
23
+ ( name ) => {
24
+ if (
25
+ findElementsBySelector ( table , "TR" ) . find ( function ( n ) {
26
+ return n . getAttribute ( "name" ) === "[" + type + ":" + name + "]" ;
27
+ } ) != null
28
+ ) {
29
+ dialog . alert ( dataReference . getAttribute ( "data-message-error" ) ) ;
30
+ return ;
31
+ }
27
32
28
- const copy = document . importNode ( master , true ) ;
29
- copy . removeAttribute ( "id" ) ;
30
- copy . removeAttribute ( "style" ) ;
31
- copy . firstChild . innerHTML = matrixAuthEscapeHtml ( name ) ; // TODO consider setting innerText
32
- copy . setAttribute ( "name" , '[' + type + ':' + name + ']' ) ;
33
+ const copy = document . importNode ( master , true ) ;
34
+ copy . removeAttribute ( "id" ) ;
35
+ copy . removeAttribute ( "style" ) ;
36
+ copy . firstChild . innerHTML = matrixAuthEscapeHtml ( name ) ; // TODO consider setting innerText
37
+ copy . setAttribute ( "name" , "[" + type + ":" + name + "]" ) ;
33
38
34
- for ( let child = copy . firstChild ; child !== null ; child = child . nextSibling ) {
35
- if ( child . hasAttribute ( ' data-permission-id' ) ) {
36
- child . setAttribute ( "data-tooltip-enabled" , child . getAttribute ( "data-tooltip-enabled" ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
37
- child . setAttribute ( "data-tooltip-disabled" , child . getAttribute ( "data-tooltip-disabled" ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
38
- }
39
- }
39
+ for ( let child = copy . firstChild ; child !== null ; child = child . nextSibling ) {
40
+ if ( child . hasAttribute ( " data-permission-id" ) ) {
41
+ child . setAttribute ( "data-tooltip-enabled" , child . getAttribute ( "data-tooltip-enabled" ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
42
+ child . setAttribute ( "data-tooltip-disabled" , child . getAttribute ( "data-tooltip-disabled" ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
43
+ }
44
+ }
40
45
41
- const tooltipAttributeName = ' data-html-tooltip' ;
46
+ const tooltipAttributeName = " data-html-tooltip" ;
42
47
43
- findElementsBySelector ( copy , ".stop a" ) . forEach ( function ( item ) {
44
- // TODO Clean this up, `title` should be long obsolete.
45
- let oldTitle = item . getAttribute ( "title" ) ;
46
- if ( oldTitle !== null ) {
47
- item . setAttribute ( "title" , oldTitle . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
48
- }
49
- item . setAttribute ( tooltipAttributeName , item . getAttribute ( tooltipAttributeName ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
50
- } ) ;
48
+ findElementsBySelector ( copy , ".stop a" ) . forEach ( function ( item ) {
49
+ // TODO Clean this up, `title` should be long obsolete.
50
+ let oldTitle = item . getAttribute ( "title" ) ;
51
+ if ( oldTitle !== null ) {
52
+ item . setAttribute ( "title" , oldTitle . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
53
+ }
54
+ item . setAttribute ( tooltipAttributeName , item . getAttribute ( tooltipAttributeName ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
55
+ } ) ;
51
56
52
- findElementsBySelector ( copy , "input[type=checkbox]" ) . forEach ( function ( item ) {
53
- const tooltip = item . nextSibling . getAttribute ( tooltipAttributeName ) ;
54
- if ( tooltip ) {
55
- item . nextSibling . setAttribute ( tooltipAttributeName , tooltip . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
56
- } else {
57
- // TODO Clean this up, `title` should be long obsolete.
58
- item . nextSibling . setAttribute ( "title" , item . getAttribute ( "title" ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
59
- }
60
- } ) ;
61
- table . appendChild ( copy ) ;
62
- Behaviour . applySubtree ( findAncestor ( table , "TABLE" ) , true ) ;
63
- } , ( ) => { } ) ;
64
- }
57
+ findElementsBySelector ( copy , "input[type=checkbox]" ) . forEach ( function ( item ) {
58
+ const tooltip = item . nextSibling . getAttribute ( tooltipAttributeName ) ;
59
+ if ( tooltip ) {
60
+ item . nextSibling . setAttribute ( tooltipAttributeName , tooltip . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
61
+ } else {
62
+ // TODO Clean this up, `title` should be long obsolete.
63
+ item . nextSibling . setAttribute ( "title" , item . getAttribute ( "title" ) . replace ( "__SID__" , name ) . replace ( "__TYPE__" , typeLabel ) ) ;
64
+ }
65
+ } ) ;
66
+ table . appendChild ( copy ) ;
67
+ Behaviour . applySubtree ( findAncestor ( table , "TABLE" ) , true ) ;
68
+ } ,
69
+ ( ) => { } ,
70
+ ) ;
71
+ } ;
65
72
} ) ;
66
73
67
74
/*
68
75
* Behavior for the element removing a permission assignment row for a user/group
69
76
*/
70
- Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.remove" , ' GlobalMatrixAuthorizationStrategy' , 0 , function ( e ) {
71
- e . onclick = function ( ) {
77
+ Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.remove" , " GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
78
+ e . onclick = function ( ) {
72
79
// Run ambiguity warning removal code: If all ambiguous rows are deleted, the warning needs to go as well
73
80
// Order of operations: Find table ancestor, remove row, iterate over leftover rows
74
81
const table = findAncestor ( this , "TABLE" ) ;
75
82
76
83
const tr = findAncestor ( this , "TR" ) ;
77
84
tr . parentNode . removeChild ( tr ) ;
78
85
79
- const tableRows = table . getElementsByTagName ( 'tr' ) ;
86
+ const tableRows = table . getElementsByTagName ( "tr" ) ;
80
87
81
88
let hasAmbiguousRows = false ;
82
89
83
90
for ( let i = 0 ; i < tableRows . length ; i ++ ) {
84
- if ( tableRows [ i ] . getAttribute ( ' name' ) !== null && tableRows [ i ] . getAttribute ( ' name' ) . startsWith ( ' [EITHER' ) ) {
91
+ if ( tableRows [ i ] . getAttribute ( " name" ) !== null && tableRows [ i ] . getAttribute ( " name" ) . startsWith ( " [EITHER" ) ) {
85
92
hasAmbiguousRows = true ;
86
93
}
87
94
}
88
95
if ( ! hasAmbiguousRows ) {
89
96
const alertElements = document . getElementsByClassName ( "alert" ) ;
90
97
for ( let i = 0 ; i < alertElements . length ; i ++ ) {
91
- if ( alertElements [ i ] . hasAttribute ( ' data-table-id' ) && alertElements [ i ] . getAttribute ( ' data-table-id' ) === table . getAttribute ( ' data-table-id' ) ) {
92
- alertElements [ i ] . style . display = ' none' ; // TODO animate this?
98
+ if ( alertElements [ i ] . hasAttribute ( " data-table-id" ) && alertElements [ i ] . getAttribute ( " data-table-id" ) === table . getAttribute ( " data-table-id" ) ) {
99
+ alertElements [ i ] . style . display = " none" ; // TODO animate this?
93
100
}
94
101
}
95
102
}
96
103
97
104
return false ;
98
- }
105
+ } ;
99
106
} ) ;
100
107
101
108
/*
102
109
* Behavior for 'Select all' element that exists for each row of permissions checkboxes
103
110
*/
104
- Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.selectall" , ' GlobalMatrixAuthorizationStrategy' , 0 , function ( e ) {
105
- e . onclick = function ( ) {
111
+ Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.selectall" , " GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
112
+ e . onclick = function ( ) {
106
113
const tr = findAncestor ( this , "TR" ) ;
107
114
const inputs = tr . getElementsByTagName ( "INPUT" ) ;
108
- for ( let i = 0 ; i < inputs . length ; i ++ ) {
115
+ for ( let i = 0 ; i < inputs . length ; i ++ ) {
109
116
if ( inputs [ i ] . type === "checkbox" ) {
110
117
inputs [ i ] . checked = true ;
111
118
}
@@ -118,8 +125,8 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selecta
118
125
/*
119
126
* Behavior for 'Unselect all' element that exists for each row of permissions checkboxes
120
127
*/
121
- Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.unselectall" , ' GlobalMatrixAuthorizationStrategy' , 0 , function ( e ) {
122
- e . onclick = function ( ) {
128
+ Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.unselectall" , " GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
129
+ e . onclick = function ( ) {
123
130
const tr = findAncestor ( this , "TR" ) ;
124
131
const inputs = tr . getElementsByTagName ( "INPUT" ) ;
125
132
for ( let i = 0 ; i < inputs . length ; i ++ ) {
@@ -135,21 +142,21 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselec
135
142
/*
136
143
* Behavior for 'Migrate to user' element that exists for each ambiguous row
137
144
*/
138
- Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.migrate" , ' GlobalMatrixAuthorizationStrategy' , 0 , function ( e ) {
139
- e . onclick = function ( ) {
145
+ Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.migrate" , " GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
146
+ e . onclick = function ( ) {
140
147
const tr = findAncestor ( this , "TR" ) ;
141
- const name = tr . getAttribute ( ' name' ) ;
148
+ const name = tr . getAttribute ( " name" ) ;
142
149
143
- let newName = name . replace ( ' [EITHER:' , ' [USER:' ) ; // migrate_user behavior
144
- if ( this . classList . contains ( ' migrate_group' ) ) {
145
- newName = name . replace ( ' [EITHER:' , ' [GROUP:' ) ;
150
+ let newName = name . replace ( " [EITHER:" , " [USER:" ) ; // migrate_user behavior
151
+ if ( this . classList . contains ( " migrate_group" ) ) {
152
+ newName = name . replace ( " [EITHER:" , " [GROUP:" ) ;
146
153
}
147
154
148
155
const table = findAncestor ( this , "TABLE" ) ;
149
- const tableRows = table . getElementsByTagName ( 'tr' ) ;
156
+ const tableRows = table . getElementsByTagName ( "tr" ) ;
150
157
let newNameElement = null ;
151
158
for ( let i = 0 ; i < tableRows . length ; i ++ ) {
152
- if ( tableRows [ i ] . getAttribute ( ' name' ) === newName ) {
159
+ if ( tableRows [ i ] . getAttribute ( " name" ) === newName ) {
153
160
newNameElement = tableRows [ i ] ;
154
161
break ;
155
162
}
@@ -160,12 +167,12 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
160
167
}
161
168
if ( newNameElement == null ) {
162
169
// no row for this name exists yet, so transform the ambiguous row to unambiguous
163
- tr . setAttribute ( ' name' , newName ) ;
164
- tr . removeAttribute ( ' data-checked' ) ;
170
+ tr . setAttribute ( " name" , newName ) ;
171
+ tr . removeAttribute ( " data-checked" ) ;
165
172
166
173
// remove migration buttons from updated row
167
174
const buttonContainer = findAncestor ( this , "DIV" ) ;
168
- const migrateButtons = buttonContainer . getElementsByClassName ( ' migrate' ) ;
175
+ const migrateButtons = buttonContainer . getElementsByClassName ( " migrate" ) ;
169
176
for ( let i = migrateButtons . length - 1 ; i >= 0 ; i -- ) {
170
177
buttonContainer . removeChild ( migrateButtons [ i ] ) ;
171
178
}
@@ -175,11 +182,11 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
175
182
// migrate permissions from this row
176
183
const ambiguousPermissionInputs = tr . getElementsByTagName ( "INPUT" ) ;
177
184
const unambiguousPermissionInputs = newNameElement . getElementsByTagName ( "INPUT" ) ;
178
- for ( let i = 0 ; i < ambiguousPermissionInputs . length ; i ++ ) {
185
+ for ( let i = 0 ; i < ambiguousPermissionInputs . length ; i ++ ) {
179
186
if ( ambiguousPermissionInputs [ i ] . type === "checkbox" ) {
180
187
unambiguousPermissionInputs [ i ] . checked |= ambiguousPermissionInputs [ i ] . checked ;
181
188
}
182
- newNameElement . classList . add ( ' highlight-entry' ) ;
189
+ newNameElement . classList . add ( " highlight-entry" ) ;
183
190
}
184
191
185
192
// remove this row
@@ -190,15 +197,15 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
190
197
let hasAmbiguousRows = false ;
191
198
192
199
for ( let i = 0 ; i < tableRows . length ; i ++ ) {
193
- if ( tableRows [ i ] . getAttribute ( ' name' ) !== null && tableRows [ i ] . getAttribute ( ' name' ) . startsWith ( ' [EITHER' ) ) {
200
+ if ( tableRows [ i ] . getAttribute ( " name" ) !== null && tableRows [ i ] . getAttribute ( " name" ) . startsWith ( " [EITHER" ) ) {
194
201
hasAmbiguousRows = true ;
195
202
}
196
203
}
197
204
if ( ! hasAmbiguousRows ) {
198
205
let alertElements = document . getElementsByClassName ( "alert" ) ;
199
206
for ( let i = 0 ; i < alertElements . length ; i ++ ) {
200
- if ( alertElements [ i ] . hasAttribute ( ' data-table-id' ) && alertElements [ i ] . getAttribute ( ' data-table-id' ) === table . getAttribute ( ' data-table-id' ) ) {
201
- alertElements [ i ] . style . display = ' none' ; // TODO animate this?
207
+ if ( alertElements [ i ] . hasAttribute ( " data-table-id" ) && alertElements [ i ] . getAttribute ( " data-table-id" ) === table . getAttribute ( " data-table-id" ) ) {
208
+ alertElements [ i ] . style . display = " none" ; // TODO animate this?
202
209
}
203
210
}
204
211
}
@@ -210,20 +217,20 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
210
217
/*
211
218
* Whenever permission assignments change, this ensures that implied permissions get their checkboxes disabled.
212
219
*/
213
- Behaviour . specify ( ".global-matrix-authorization-strategy-table td input" , ' GlobalMatrixAuthorizationStrategy' , 0 , function ( e ) {
220
+ Behaviour . specify ( ".global-matrix-authorization-strategy-table td input" , " GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
214
221
const table = findAncestor ( e , "TABLE" ) ;
215
- if ( table . classList . contains ( ' read-only' ) ) {
222
+ if ( table . classList . contains ( " read-only" ) ) {
216
223
// if this is a read-only UI (ExtendedRead / SystemRead), do not enable checkboxes
217
224
return ;
218
225
}
219
226
220
- const tooltipAttributeName = ' data-html-tooltip' ;
227
+ const tooltipAttributeName = " data-html-tooltip" ;
221
228
222
- const impliedByString = findAncestor ( e , "TD" ) . getAttribute ( ' data-implied-by-list' ) ;
229
+ const impliedByString = findAncestor ( e , "TD" ) . getAttribute ( " data-implied-by-list" ) ;
223
230
const impliedByList = impliedByString . split ( " " ) ;
224
231
const tr = findAncestor ( e , "TR" ) ;
225
232
e . disabled = false ;
226
- let tooltip = matrixAuthEscapeHtml ( findAncestor ( e , "TD" ) . getAttribute ( ' data-tooltip-enabled' ) ) ;
233
+ let tooltip = matrixAuthEscapeHtml ( findAncestor ( e , "TD" ) . getAttribute ( " data-tooltip-enabled" ) ) ;
227
234
e . nextSibling . setAttribute ( tooltipAttributeName , tooltip ) ;
228
235
229
236
for ( let i = 0 ; i < impliedByList . length ; i ++ ) {
@@ -232,13 +239,13 @@ Behaviour.specify(".global-matrix-authorization-strategy-table td input", 'Globa
232
239
if ( reference !== null ) {
233
240
if ( reference . checked ) {
234
241
e . disabled = true ;
235
- let tooltip = matrixAuthEscapeHtml ( findAncestor ( e , "TD" ) . getAttribute ( ' data-tooltip-disabled' ) ) ;
242
+ let tooltip = matrixAuthEscapeHtml ( findAncestor ( e , "TD" ) . getAttribute ( " data-tooltip-disabled" ) ) ;
236
243
e . nextSibling . setAttribute ( tooltipAttributeName , tooltip ) ;
237
244
}
238
245
}
239
246
}
240
247
241
- e . onchange = function ( ) {
248
+ e . onchange = function ( ) {
242
249
Behaviour . applySubtree ( findAncestor ( this , "TABLE" ) , true ) ;
243
250
return true ;
244
251
} ;
@@ -247,12 +254,12 @@ Behaviour.specify(".global-matrix-authorization-strategy-table td input", 'Globa
247
254
/*
248
255
* Each newly added row needs to have the name checked. Triggered by explicit Behaviour#applySubtree calls elsewhere.
249
256
*/
250
- Behaviour . specify ( ".global-matrix-authorization-strategy-table TR.permission-row" , ' GlobalMatrixAuthorizationStrategy' , 0 , function ( e ) {
251
- if ( e . getAttribute ( ' name' ) === ' __unused__' ) {
257
+ Behaviour . specify ( ".global-matrix-authorization-strategy-table TR.permission-row" , " GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
258
+ if ( e . getAttribute ( " name" ) === " __unused__" ) {
252
259
return ;
253
260
}
254
- if ( ! e . hasAttribute ( ' data-checked' ) ) {
255
- FormChecker . delayedCheck ( e . getAttribute ( ' data-descriptor-url' ) + "/checkName?value=" + encodeURIComponent ( e . getAttribute ( "name" ) ) , "GET" , e . firstChild ) ;
256
- e . setAttribute ( ' data-checked' , ' true' ) ;
261
+ if ( ! e . hasAttribute ( " data-checked" ) ) {
262
+ FormChecker . delayedCheck ( e . getAttribute ( " data-descriptor-url" ) + "/checkName?value=" + encodeURIComponent ( e . getAttribute ( "name" ) ) , "GET" , e . firstChild ) ;
263
+ e . setAttribute ( " data-checked" , " true" ) ;
257
264
}
258
265
} ) ;
0 commit comments