Skip to content
Snippets Groups Projects
Commit c311e37e authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Major update to discopower module.. improved ui with live search.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1796 44740490-163a-0410-bde0-09ae8108e29a
parent 1f225dda
Branches
No related tags found
No related merge requests found
...@@ -41,6 +41,8 @@ $lang = array( ...@@ -41,6 +41,8 @@ $lang = array(
'no' => 'Andre', 'no' => 'Andre',
'en' => 'Miscellaneous', 'en' => 'Miscellaneous',
), ),
'incommon' => array('en' => 'InCommon'),
'ukacessfederation' => array('en' => 'UK Access Federation'),
); );
......
...@@ -44,12 +44,21 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { ...@@ -44,12 +44,21 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco {
protected function log($message) { protected function log($message) {
SimpleSAML_Logger::info('PowerIdPDisco.' . $this->instance . ': ' . $message); SimpleSAML_Logger::info('PowerIdPDisco.' . $this->instance . ': ' . $message);
} }
public static function mcmp($a, $b) {
# echo 'aort'; exit;
if ($a['name']['en'] == $b['name']['en']) {
return 0;
}
return ($a['name']['en'] < $b['name']['en']) ? -1 : 1;
}
/* /*
* This function will structure the idp list in a hierarchy based upon the tags. * This function will structure the idp list in a hierarchy based upon the tags.
*/ */
protected function idplistStructured($list) { protected function idplistStructured($list) {
# echo '<pre>'; print_r($list); exit; # echo '<pre>'; print_r($list); exit;
$slist = array(); $slist = array();
$order = $this->discoconfig->getValue('taborder'); $order = $this->discoconfig->getValue('taborder');
...@@ -71,6 +80,11 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { ...@@ -71,6 +80,11 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco {
$slist[$tag][$key] = $val; $slist[$tag][$key] = $val;
} }
} }
foreach($slist AS $tab => $tbslist) {
uasort($slist[$tab], array('sspmod_discopower_PowerIdPDisco', 'mcmp'));
}
return $slist; return $slist;
} }
......
...@@ -4,24 +4,36 @@ if(!array_key_exists('header', $this->data)) { ...@@ -4,24 +4,36 @@ if(!array_key_exists('header', $this->data)) {
$this->data['header'] = 'selectidp'; $this->data['header'] = 'selectidp';
} }
$this->data['header'] = $this->t($this->data['header']); $this->data['header'] = $this->t($this->data['header']);
$this->data['jquery'] = array('version' => '1.6', 'core' => TRUE, 'ui' => TRUE, 'css' => TRUE);
$this->data['head'] = '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery.js"></script>'; $this->data['head'] .= '<link rel="stylesheet" media="screen" type="text/css" href="' . SimpleSAML_Module::getModuleUrl('discopower/style.css') . '" />';
$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery-ui.js"></script>';
$this->data['head'] .= '<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 'resources/uitheme/jquery-ui-themeroller.css" />'; $this->data['head'] .= '<script type="text/javascript" src="' . SimpleSAML_Module::getModuleUrl('discopower/js/jquery.livesearch.js') . '"></script>';
$this->data['head'] .= '<script type="text/javascript" src="' . SimpleSAML_Module::getModuleUrl('discopower/js/quicksilver.js') . '"></script>';
$this->data['head'] .= '<script type="text/javascript"> $this->data['head'] .= '<script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$("#discotabs > ul").tabs({ selected: ' . $this->data['defaulttab'] . ' }); $("#discotabs").tabs({ selected: ' . $this->data['defaulttab'] . ' }); ';
/* $i = 0;
$("#foodledescr").resizable({ foreach ($this->data['idplist'] AS $tab => $slist) {
handles: "all" $this->data['head'] .= '$("#query_' . $tab . '").liveUpdate("#list_' . $tab . '")' .
}); ($i++ == 0 ? '.focus()' : '') .
*/ ';';
}
$this->data['head'] .= '
}); });
function chooseidp(idp) {
$("#chosenidp").attr(\'name\', \'idp_\' + idp);
$("#idpselectform").submit();
}
</script>'; </script>';
$this->data['autofocus'] = 'preferredidp'; # $this->data['autofocus'] = 'preferredidp';
$this->includeAtTemplateBase('includes/header.php'); $this->includeAtTemplateBase('includes/header.php');
...@@ -35,16 +47,55 @@ foreach ($this->data['idplist'] AS $slist) { ...@@ -35,16 +47,55 @@ foreach ($this->data['idplist'] AS $slist) {
} }
function showEntry($t, $metadata, $favourite = FALSE) {
$extra = ($favourite ? ' favourite' : '');
$html = '<li class="metaentry' . $extra . '" onclick="chooseidp(\'' . htmlspecialchars($metadata['entityid']) . '\')">';
$html .= '' . htmlspecialchars($t->t('idpname_' . $metadata['entityid'])) . '';
#print_r($metadata['scopes']);
// if (!empty($idpentry['description'])) {
// $html .= ' <p>' . htmlspecialchars($t->t('idpdesc_' . $metadata['entityid'])) . '<br />';
// }
if(array_key_exists('icon', $metadata) && $metadata['icon'] !== NULL) {
$iconUrl = SimpleSAML_Utilities::resolveURL($metadata['icon']);
$html .= '<img style="clear: both; float: left; margin: 1em; padding: 3px; border: 1px solid #999" src="' . htmlspecialchars($iconUrl) . '" />';
}
// $html .= '<input id="preferredidp" type="submit" name="idp_' .
// htmlspecialchars($metadata['entityid']) . '" value="' .
// $t->t('select') . '" /></p>';
$html .= '</li>';
return $html;
}
?> ?>
<h2><?php echo $this->data['header']; ?></h2>
<form method="get" action="<?php echo $this->data['urlpattern']; ?>">
<!-- <h2><?php echo $this->data['header']; ?></h2> -->
<form id="idpselectform" method="get" action="<?php echo $this->data['urlpattern']; ?>">
<input type="hidden" name="entityID" value="<?php echo htmlspecialchars($this->data['entityID']); ?>" /> <input type="hidden" name="entityID" value="<?php echo htmlspecialchars($this->data['entityID']); ?>" />
<input type="hidden" name="return" value="<?php echo htmlspecialchars($this->data['return']); ?>" /> <input type="hidden" name="return" value="<?php echo htmlspecialchars($this->data['return']); ?>" />
<input type="hidden" name="returnIDParam" value="<?php echo htmlspecialchars($this->data['returnIDParam']); ?>" /> <input type="hidden" name="returnIDParam" value="<?php echo htmlspecialchars($this->data['returnIDParam']); ?>" />
<input id="chosenidp" type="hidden" name="<?php echo htmlspecialchars($this->data['returnIDParam']); ?>" value="1" />
<!-- <input type="submit" style="" name="formsubmit" id="formsubmit" value="Submit" /> -->
</form>
<p><?php <p><?php
$checked = ''; $checked = '';
...@@ -60,7 +111,7 @@ foreach ($this->data['idplist'] AS $slist) { ...@@ -60,7 +111,7 @@ foreach ($this->data['idplist'] AS $slist) {
<div id="discotabs"> <div id="discotabs">
<ul> <ul class="tabset_tabs">
<?php <?php
$tabs = array_keys( $this->data['idplist']); $tabs = array_keys( $this->data['idplist']);
...@@ -75,49 +126,37 @@ foreach ($this->data['idplist'] AS $slist) { ...@@ -75,49 +126,37 @@ foreach ($this->data['idplist'] AS $slist) {
<?php <?php
foreach( $this->data['idplist'] AS $tab => $slist) { foreach( $this->data['idplist'] AS $tab => $slist) {
echo '<div id="' . $tab . '">'; echo '<div id="' . $tab . '">';
if (!empty($slist)) {
if (!empty($this->data['preferredidp']) && array_key_exists($this->data['preferredidp'], $slist)) {
$idpentry = $slist[$this->data['preferredidp']]; // echo 'Favourite :: ' . $this->data['preferredidp'];
echo '<div class="preferredidp">'; // echo '<pre>';
echo ' <img src="/' . $this->data['baseurlpath'] .'resources/icons/star.png" style="float: right" />'; // print_r($slist); exit;
if(array_key_exists('icon', $idpentry) && $idpentry['icon'] !== NULL) {
$iconUrl = SimpleSAML_Utilities::resolveURL($idpentry['icon']);
echo '<img style="float: left; margin: 1em; padding: 3px; border: 1px solid #999" src="' . htmlspecialchars($iconUrl) . '" />';
}
echo '<h3 style="margin-top: 8px">' . htmlspecialchars($this->t('idpname_' . $idpentry['entityid'])) . '</h3>';
if (!empty($idpentry['description'])) {
echo ' <p>' . htmlspecialchars($this->t('idpdesc_' . $idpentry['entityid'])) . '<br />';
}
echo('<input id="preferredidp" type="submit" name="idp_' .
htmlspecialchars($idpentry['entityid']) . '" value="' .
$this->t('select') . '" /></p>');
echo '</div>';
}
foreach ($slist AS $idpentry) {
if ($idpentry['entityid'] != $this->data['preferredidp']) {
if(array_key_exists('icon', $idpentry) && $idpentry['icon'] !== NULL) {
$iconUrl = SimpleSAML_Utilities::resolveURL($idpentry['icon']);
echo '<img style="clear: both; float: left; margin: 1em; padding: 3px; border: 1px solid #999" src="' . htmlspecialchars($iconUrl) . '" />';
}
echo ' <h3 style="margin-top: 8px">' . htmlspecialchars($this->t('idpname_' . $idpentry['entityid'])) . '</h3>';
if (!empty($idpentry['description'])) { echo(' <div class="inlinesearch">');
echo(' <p>Incremental search...</p>');
echo(' <input class="inlinesearchf" type="text" value="" name="query_' . $tab . '" id="query_' . $tab . '" />');
echo(' </div>');
echo(' <ul class="metalist" id="list_' . $tab . '">');
if (!empty($this->data['preferredidp']) && array_key_exists($this->data['preferredidp'], $slist)) {
$idpentry = $slist[$this->data['preferredidp']];
echo (showEntry($this, $idpentry, TRUE));
}
echo ' <p>' . htmlspecialchars($this->t('idpdesc_' . $idpentry['entityid'])) . '<br />'; foreach ($slist AS $idpentry) {
if ($idpentry['entityid'] != $this->data['preferredidp']) {
echo (showEntry($this, $idpentry));
} }
echo('<input id="preferredidp" type="submit" name="idp_' .
htmlspecialchars($idpentry['entityid']) . '" value="' .
$this->t('select') . '" /></p>');
} }
echo(' </ul>');
} }
echo '</div>'; echo '</div>';
...@@ -128,7 +167,6 @@ foreach ($this->data['idplist'] AS $slist) { ...@@ -128,7 +167,6 @@ foreach ($this->data['idplist'] AS $slist) {
</div> </div>
</form>
<?php $this->includeAtTemplateBase('includes/footer.php'); ?> <?php $this->includeAtTemplateBase('includes/footer.php'); ?>
modules/discopower/www/icons/arrow_right.png

393 B

modules/discopower/www/icons/heart.png

619 B

modules/discopower/www/icons/magnify.png

586 B

modules/discopower/www/icons/star.png

622 B

jQuery.fn.liveUpdate = function(list){
list = jQuery(list);
if ( list.length ) {
var rows = list.children('li'),
cache = rows.map(function(){
return jQuery(this).text().toLowerCase();
});
this
.keyup(filter).keyup()
.parents('form').submit(function(){
return false;
});
}
return this;
function filter(){
var term = jQuery.trim( jQuery(this).val().toLowerCase() ), scores = [];
if ( !term ) {
rows.show();
} else {
rows.hide();
cache.each(function(i){
var score = this.score(term);
if (score > 0) { scores.push([score, i]); }
});
jQuery.each(scores.sort(function(a, b){return b[0] - a[0];}), function(){
jQuery(rows[ this[1] ]).show();
});
}
}
};
// qs_score - Quicksilver Score
//
// A port of the Quicksilver string ranking algorithm
//
// "hello world".score("axl") //=> 0.0
// "hello world".score("ow") //=> 0.6
// "hello world".score("hello world") //=> 1.0
//
// Tested in Firefox 2 and Safari 3
//
// The Quicksilver code is available here
// http://code.google.com/p/blacktree-alchemy/
// http://blacktree-alchemy.googlecode.com/svn/trunk/Crucible/Code/NSString+BLTRRanking.m
//
// The MIT License
//
// Copyright (c) 2008 Lachie Cox
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
String.prototype.score = function(abbreviation,offset) {
offset = offset || 0 // TODO: I think this is unused... remove
if(abbreviation.length == 0) return 0.9
if(abbreviation.length > this.length) return 0.0
for (var i = abbreviation.length; i > 0; i--) {
var sub_abbreviation = abbreviation.substring(0,i)
var index = this.indexOf(sub_abbreviation)
if(index < 0) continue;
if(index + abbreviation.length > this.length + offset) continue;
var next_string = this.substring(index+sub_abbreviation.length)
var next_abbreviation = null
if(i >= abbreviation.length)
next_abbreviation = ''
else
next_abbreviation = abbreviation.substring(i)
var remaining_score = next_string.score(next_abbreviation,offset+index)
if (remaining_score > 0) {
var score = this.length-next_string.length;
if(index != 0) {
var j = 0;
var c = this.charCodeAt(index-1)
if(c==32 || c == 9) {
for(var j=(index-2); j >= 0; j--) {
c = this.charCodeAt(j)
score -= ((c == 32 || c == 9) ? 1 : 0.15)
}
// XXX maybe not port this heuristic
//
// } else if ([[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[self characterAtIndex:matchedRange.location]]) {
// for (j = matchedRange.location-1; j >= (int) searchRange.location; j--) {
// if ([[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[self characterAtIndex:j]])
// score--;
// else
// score -= 0.15;
// }
} else {
score -= index
}
}
score += remaining_score * next_string.length
score /= this.length;
return score
}
}
return 0.0
}
\ No newline at end of file
.inlinesearch:hover {
}
.inlinesearch {
float: right;
margin: 0em 3px .5em 1em;
/* padding: .3em;*/
}
.inlinesearch p {
font-size: 94%;
color: #aaa;
}
.inlinesearch input {
background-image:url('icons/magnify.png');
background-repeat:no-repeat;
background-position:center left;
border: 1px solid #ccc;
padding: 2px 2px 2px 20px;
margin: 0px 2px 0px 0px;
}
.inlinesearch * {
margin: 0px;
padding: 0px;
}
ul.metalist {
clear: both;
list-style: none;
margin: 1em 2px .5em 2px;
padding: 0px;
}
li.metaentry {
border: 1px solid #ccc;
margin: 0px 0px -1px 0px;
padding: .2em 1em .2em 20px;
cursor: pointer;
cursor: hand;
}
li.metaentry.favourite {
background-image:url('icons/heart.png');
background-repeat:no-repeat;
background-position:center left;
}
li.metaentry:hover {
border: 1px solid #ccc;
background: #eee;
background-image:url('icons/star.png');
background-repeat:no-repeat;
background-position:center left;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment