2929 Module::getModuleUrl ('discopower/assets/js/suggest.js ' ) . '"></script> ' ;
3030
3131$ this ->data ['head ' ] .= searchScript ();
32+ $ this ->data ['head ' ] .= showEntriesScript ();
33+ $ this ->data ['head ' ] .= setFocus ();
3234
3335const CONFIG_FILE_NAME = 'module_perun.php ' ;
3436
121123 if (!$ warningIsOn || $ warningType === WARNING_TYPE_INFO || $ warningType === WARNING_TYPE_WARNING ) {
122124 if (!empty ($ this ->getPreferredIdp ())) {
123125 echo '<p class="descriptionp"> ' . $ this ->t ('{perun:disco:previous_selection} ' ) . '</p> ' ;
124- echo '<div class="metalist list-group"> ' ;
126+ echo '<div id="last-used-idp" class="metalist list-group"> ' ;
125127 echo showEntry ($ this , $ this ->getPreferredIdp (), true );
126128 echo '</div> ' ;
127129
128-
129130 echo getOr ();
130- }
131131
132- echo '<div class="row"> ' ;
133- foreach ($ this ->getIdps ('preferred ' ) as $ idpentry ) {
134- echo '<div class="col-md-4"> ' ;
135- echo '<div class="metalist list-group"> ' ;
136- echo showEntry ($ this , $ idpentry , false );
137- echo '</div> ' ;
138- echo '</div> ' ;
132+ echo '<span id="showEntries" class="btn btn-block btn-default btn-lg"> ' .
133+ $ this ->t ('{perun:disco:sign_with_other_institution} ' ) .'</span> ' ;
134+ echo '<div id="entries" style="display: none"> ' ;
139135 }
140- echo '</div> ' ;
141136
142- echo '<div class="row"> ' ;
143- foreach ($ this ->getIdps ('social ' ) as $ idpentry ) {
144- echo '<div class="col-md-4"> ' ;
145- echo '<div class="metalist list-group"> ' ;
146- echo showEntry ($ this , $ idpentry , false );
147- echo '</div> ' ;
148- echo '</div> ' ;
149- }
150- echo '</div> ' ;
137+ echo showAllTaggedIdPs ($ this );
151138
152139 echo getOr ();
153140
188175 $ this ->t ('{perun:disco:add_institution} ' ) .
189176 '</a> ' ;
190177 }
178+
179+ if (!empty ($ this ->getPreferredIdp ())) {
180+ echo '</div> ' ;
181+ }
182+
191183 echo '</div> ' ;
192184}
193185
194186$ this ->includeAtTemplateBase ('includes/footer.php ' );
195187
188+ function showEntriesScript ()
189+ {
190+ $ script = '<script type="text/javascript">
191+ $(document).ready(function() {
192+ $("#showEntries").click(function() {
193+ $("#entries").show();
194+ $("#showEntries").hide();
195+ });
196+ });
197+ </script> ' ;
198+ return $ script ;
199+ }
200+
196201function searchScript ()
197202{
198203
@@ -207,6 +212,21 @@ function searchScript()
207212 return $ script ;
208213}
209214
215+ function setFocus ()
216+ {
217+ $ script = '<script type="text/javascript">
218+
219+ $(document).ready(function() {
220+ if ($("#last-used-idp")) {
221+ $("#last-used-idp .metaentry").focus();
222+ }
223+ });
224+
225+ </script> ' ;
226+
227+ return $ script ;
228+ }
229+
210230/**
211231 * @param DiscoTemplate $t
212232 * @param array $metadata
@@ -227,8 +247,6 @@ function showEntry($t, $metadata, $favourite = false)
227247
228248 $ html .= '<strong> ' . $ t ->getTranslatedEntityName ($ metadata ) . '</strong> ' ;
229249
230- $ html .= showIcon ($ metadata );
231-
232250 $ html .= '</a> ' ;
233251
234252 return $ html ;
@@ -237,9 +255,11 @@ function showEntry($t, $metadata, $favourite = false)
237255/**
238256 * @param DiscoTemplate $t
239257 * @param array $metadata
258+ * @param bool $showSignInWith
259+ *
240260 * @return string html
241261 */
242- function showTaggedEntry ($ t , $ metadata )
262+ function showTaggedEntry ($ t , $ metadata, $ showSignInWith = false )
243263{
244264
245265 $ bck = 'white ' ;
@@ -252,36 +272,69 @@ function showTaggedEntry($t, $metadata)
252272
253273 $ html .= '<img src=" ' . $ metadata ['icon ' ] . '"> ' ;
254274
255- $ html .= '<strong>Sign in with ' . $ t ->getTranslatedEntityName ($ metadata ) . '</strong> ' ;
275+ if (isset ($ metadata ['fullDisplayName ' ])) {
276+ $ html .= '<strong> ' . $ metadata ['fullDisplayName ' ] . '</strong> ' ;
277+ } elseif ($ showSignInWith ) {
278+ $ html .= '<strong> ' . $ t ->t ('{perun:disco:sign_in_with} ' ) . $ t ->getTranslatedEntityName ($ metadata ) .
279+ '</strong> ' ;
280+ } else {
281+ $ html .= '<strong> ' . $ t ->getTranslatedEntityName ($ metadata ) . '</strong> ' ;
282+ }
256283
257284 $ html .= '</a> ' ;
258285
259286 return $ html ;
260287}
261288
289+ function getOr ()
290+ {
291+ $ or = '<div class="hrline"> ' ;
292+ $ or .= ' <span>or</span> ' ;
293+ $ or .= '</div> ' ;
294+ return $ or ;
295+ }
262296
263- function showIcon ( $ metadata )
297+ function showAllTaggedIdPs ( $ t )
264298{
265299 $ html = '' ;
266- // Logos are turned off, because they are loaded via URL from IdP. Some IdPs have bad configuration,
267- // so it breaks the WAYF.
268-
269- /*if (isset($metadata['UIInfo']['Logo'][0]['url'])) {
270- $html .= '<img src="' .
271- htmlspecialchars(\SimpleSAML\Utils\HTTP::resolveURL($metadata['UIInfo']['Logo'][0]['url'])) .
272- '" class="idp-logo">';
273- } else if (isset($metadata['icon'])) {
274- $html .= '<img src="' . htmlspecialchars(\SimpleSAML\Utils\HTTP::resolveURL($metadata['icon'])) .
275- '" class="idp-logo">';
276- }*/
277-
300+ $ html .= showTaggedIdPs ($ t , 'preferred ' );
301+ $ html .= showTaggedIdPs ($ t , 'social ' , true );
278302 return $ html ;
279303}
280304
281- function getOr ()
305+
306+ function showTaggedIdPs ($ t , $ tag , $ showSignInWith = false )
282307{
283- $ or = '<div class="hrline"> ' ;
284- $ or .= ' <span>or</span> ' ;
285- $ or .= '</div> ' ;
286- return $ or ;
308+ $ html = '' ;
309+ $ idps = $ t ->getIdPs ($ tag );
310+ $ idpCount = count ($ idps );
311+ $ counter = 0 ;
312+
313+ $ fullRowCount = floor ($ idpCount / 3 );
314+ for ($ i = 0 ; $ i < $ fullRowCount ; $ i ++ ) {
315+ $ html .= '<div class="row"> ' ;
316+ for ($ j = 0 ; $ j < 3 ; $ j ++) {
317+ $ html .= '<div class="col-md-4"> ' ;
318+ $ html .= '<div class="metalist list-group"> ' ;
319+ $ html .= showTaggedEntry ($ t , $ idps [array_keys ($ idps )[$ counter ]], $ showSignInWith );
320+ $ html .= '</div> ' ;
321+ $ html .= '</div> ' ;
322+ $ counter ++;
323+ }
324+ $ html .= '</div> ' ;
325+ }
326+ if (($ idpCount % 3 ) !== 0 ) {
327+ $ html .= '<div class="row"> ' ;
328+ for ($ i = 0 ; $ i < $ idpCount % 3 ; $ i ++) {
329+ $ html .= '<div class="col-md- ' . (12 / ($ idpCount % 3 )) . '"> ' ;
330+ $ html .= '<div class="metalist list-group"> ' ;
331+ $ html .= showTaggedEntry ($ t , $ idps [array_keys ($ idps )[$ counter ]], $ showSignInWith );
332+ $ html .= '</div> ' ;
333+ $ html .= '</div> ' ;
334+ $ counter ++;
335+ }
336+ $ html .= '</div> ' ;
337+ }
338+
339+ return $ html ;
287340}
0 commit comments