Commit 3835b699 authored by Son Nguyen's avatar Son Nguyen Committed by Robert Lyon

Fix errors when exporting Leap2A. Bug 1536393

1. Move style.css to htdocs/theme/raw/plugintype/blocktype/openbadgedisplayer/style
2. Move js code from tpl to a js file htdocs/blocktype/openbadgedisplayer/js/showdetails.js

behatnotneeded

Change-Id: I21f18e44581d11652553334760bdc1e6a3e5b206
parent 4df6826b
......@@ -28,9 +28,12 @@ if (!isset($emails) || !in_array($email, $emails)) {
}
$uid = PluginBlocktypeOpenbadgedisplayer::get_backpack_id($host, $email);
$hosttitle = get_string('title_' . $host, 'blocktype.openbadgedisplayer');
json_reply(false, array(
'host' => $host,
'hosttitle' => get_string('title_' . $host, 'blocktype.openbadgedisplayer'),
'hosttitle' => $hosttitle,
'uid' => $uid,
'badgegroups' => PluginBlocktypeOpenbadgedisplayer::get_badgegroupnames($host, $uid),
'badgegroups' => isset($uid) ? PluginBlocktypeOpenbadgedisplayer::get_badgegroupnames($host, $uid) : null,
'nobackpackmsg' => get_string('nobackpackidin', 'blocktype.openbadgedisplayer', $hosttitle),
'nobadgegroupsmsg' => get_string('nobadgegroupsin', 'blocktype.openbadgedisplayer', $hosttitle)
));
......@@ -43,7 +43,15 @@ if ((badgegroups_hosts instanceof Array && badgegroups_hosts.length >= 1)
count++;
/* Fetching the badge info via ajax and render the pieform checkbox element */
sendjsonrequest(config['wwwroot'] + '/blocktype/openbadgedisplayer/badgegroupnames.json.php', params, 'POST', function(data) {
if (!jQuery.isEmptyObject(data.badgegroups)) {
if (!data.uid) {
var msg = jQuery('<p>').text(data.nobackpackmsg);
jQuery("div#instconf_loadinginfo_container > div").append(msg);
}
else if (!data.badgegroups || data.badgegroups.length === 0) {
var msg = jQuery('<p>').text(data.nobadgegroupsmsg);
jQuery("div#instconf_loadinginfo_container > div").append(msg);
}
else {
var htmlstr =
'<div id="instconf_' + data.host + '_container" class="checkboxes form-group">' +
'<span class="pseudolabel">' + data["hosttitle"] + '</span>' +
......@@ -72,10 +80,11 @@ if ((badgegroups_hosts instanceof Array && badgegroups_hosts.length >= 1)
'<div class="cl"></div>' +
'</div>';
jQuery("div#instconf_loadinginfo_container > div").append(htmlstr);
count--;
if (count == 0) {
jQuery("div#instconf_loadinginfo_container > p.alert").addClass('hidden');
}
}
count--;
if (count == 0) {
jQuery("div#instconf_loadinginfo_container > p.alert").addClass('hidden');
}
});
}
......
/**
* Show badges details in a modal dialog
*
* @package mahara
* @subpackage blocktype-openbadgedisplayer
* @author Discendum Oy
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
function shorten(str) {
var n = 40;
return str.substr(0, n - 1) + (str.length > n ? '...' : '');
}
function formatDate(date) {
if (!date) {
return '-';
}
if (date.toString().match(/^[0-9]+$/)) {
var d = new Date(0);
d.setUTCSeconds(date);
return d.toLocaleDateString();
}
return date;
}
function urlElement(url) {
if (!url) {
return '-';
}
return jQuery('<a/>').attr({ href: url, title: url }).text(shorten(url));
}
function buildBadgeContent(assertion) {
var el = jQuery('.badge-template').clone().removeClass('badge-template');
el.find('img.badge-image').attr('src', assertion.badge.image);
el.find('tr.issuer-name td.value').text(assertion.badge.issuer.name);
el.find('tr.issuer-url td.value').html(urlElement(assertion.badge.issuer.origin));
el.find('tr.issuer-organization td.value').text(assertion.badge.issuer.org || '-');
el.find('tr.badge-name td.value').text(assertion.badge.name);
el.find('tr.badge-description td.value').text(assertion.badge.description);
el.find('tr.badge-criteria td.value').html(urlElement(assertion.badge.criteria));
el.find('tr.issuance-evidence td.value').html(urlElement(assertion.evidence));
el.find('tr.issuance-issuedon td.value').text(formatDate(assertion.issued_on));
el.find('tr.issuance-expires td.value').text(formatDate(assertion.expires));
return el.prop('outerHTML');
}
function showBadgeContent(data) {
/* Add a modal dialog if not exists */
if (jQuery('div#content').length == 1 && jQuery('div#content #badge-content-dialog').length == 0) {
jQuery('div#content').append(
'<div id="badge-content-dialog" class="modal fade page-modal js-page-modal" role="dialog">' +
' <div class="modal-dialog">' +
' <div class="modal-content">' +
' <div class="modal-body"></div>' +
' <div class="modal-footer">' +
' <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>' +
' </div>' +
' </div>' +
' </div>' +
'</div>');
}
jQuery('#badge-content-dialog .modal-body').html(data.html);
jQuery('#badge-content-dialog').modal('show');
}
......@@ -53,9 +53,13 @@ $string['criteria'] = 'Criteria';
$string['nbadges'] = array('1 badge', '%s badges');
$string['nobackpack'] = 'No Backpack found.<br> Please add your <a href="%s" target="_blank">Backpack</a> email address to your <a href="%s">profile</a>.';
$string['nobackpack'] = 'No Backpack found.<br> Please add your <a href="%s">Backpack</a> email address to your <a href="%s">profile</a>.';
$string['nogroups'] = 'No public badge collections/badges found.<br> Please visit your <a href="%s" target="_blank">Backpack</a> and add your badges to some public collections.';
$string['nobadgegroups'] = 'No public badge collections/badges found.';
$string['nobackpackidin'] = 'Your email is not found in the service %s.';
$string['nobadgegroupsin'] = 'No public badge collections/badges found in the service: %s.';
$string['confighelp'] = 'Select the badge collections to show in this block.<br/>Visit the following services to manage your collections and badges:<br/>%s';
......
......@@ -56,9 +56,9 @@ $string['nbadges'] = array(
1 => '%s merkkiä',
);
$string['nobackpack'] = 'Backpackia ei löydy.<br> Lisää <a href="%s" target="_blank">Backpackiin</a> kytketty sähköpostiosoite <a hreft="%s">profiiliisi.</a>';
$string['nobackpack'] = 'Backpackia ei löydy.<br> Lisää <a href="%s">Backpackiin</a> kytketty sähköpostiosoite <a hreft="%s">profiiliisi.</a>';
$string['nogroups'] = 'Julkisia merkkejä ei löydy.<br> Kirjaudu <a href="%s" target="_blank">Backpackiin</a> ja lisää merkkejä julkisiin merkkiryhmiin.';
$string['nogroups'] = 'Julkisia merkkejä ei löydy.';
$string['obppublicbadges'] = 'Kaikki julkiset merkit Open Badge Passportissa';
$string['organization'] = 'Organisaatio';
......
......@@ -31,7 +31,7 @@ defined('INTERNAL') || die();
$string['badgedetails'] = 'Badge Detaljer';
$string['confighelp'] = 'Välj badge samlingen som skall visas i detta block.<br> Gå till din <a href="%s" target="_blank">Ryggsäck</a> för att hantera samlingar och badges.';
$string['confighelp'] = 'Välj badge samlingen som skall visas i detta block.<br> Gå till din <a href="%s">Ryggsäck</a> för att hantera samlingar och badges.';
$string['criteria'] = 'Kriterium';
......@@ -56,9 +56,9 @@ $string['nbadges'] = array(
1 => '%s badges',
);
$string['nobackpack'] = 'Ingen ryggsäck hittades.<br> Lägg till din <a href="%s" target="_blank">Ryggsäcks</a> e-post adress till din <a href="%s">profil</a>.';
$string['nobackpack'] = 'Ingen ryggsäck hittades.<br> Lägg till din <a href="%s">Ryggsäcks</a> e-post adress till din <a href="%s">profil</a>.';
$string['nogroups'] = 'Inga allmänna badge samlingar hittades. <br> Gå till din <a href="%s" target="_blank">Ryggsäck</a> och lägg till dina badges till några allmänna samlingar.';
$string['nogroups'] = 'Inga allmänna badge samlingar hittades.';
$string['organization'] = 'Organisation';
......
......@@ -81,15 +81,6 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
return;
}
// HACK: In Mahara 1.8 blocktypes cannot declare their own styles. Let's
// make a small hack to include our own styles to page.
$blocks_can_have_css = method_exists('View', 'get_all_blocktype_css');
if (!$blocks_can_have_css) {
global $CFG;
$CFG->additionalhtmlhead .= '<link rel="stylesheet" type="text/css" href="' . $CFG->wwwroot . 'blocktype/openbadgedisplayer/theme/raw/static/style/style.css" media="all"></link>';
}
$host = 'backpack';
$badgegroups = $configdata['badgegroup'];
$html = '';
......@@ -118,6 +109,9 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
if (count($items) > 0) {
$html .= '<ul>' . implode('', array_map(function ($item) { return "<li>{$item}</li>"; }, $items)) . '</ul>';
}
else {
$html .= get_string('nobadgegroups', 'blocktype.openbadgedisplayer');
}
return $html;
}
......@@ -194,9 +188,9 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
}
$html .= '<img '
. 'src="' . $b->image . '" '
. 'title="' . $b->name . '" '
. 'data-assertion="' . htmlentities(json_encode($badge->assertion)) . '" />';
. 'src="' . $b->image . '" '
. 'title="' . $b->name . '" '
. 'data-assertion="' . htmlentities(json_encode($badge->assertion)) . '" />';
$existing[$b->name] = $b->description;
}
......@@ -230,6 +224,9 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
$html .= self::get_badge_html($group);
}
if (empty($html)) {
$html = get_string('nobadgegroups', 'blocktype.openbadgedisplayer');
}
return $html;
}
......@@ -280,7 +277,7 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
foreach ($sources as $source => $url) {
if (!empty($url)) {
$title = get_string('title_' . $source, 'blocktype.openbadgedisplayer');
$sourcelinks[] = '<a href="' . $url . '" target="_blank">' . $title . '</a>';
$sourcelinks[] = '<a href="' . $url . '">' . $title . '</a>';
}
}
......@@ -546,7 +543,7 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
}
public static function get_instance_javascript() {
return array(get_config('wwwroot') . 'js/preview.js');
return array('js/showdetails.js');
}
public static function should_ajaxify() {
......
<div id="openbadges{{$id}}" class="openbadgedisplayer">{{$badgehtml|safe}}</div>
<script type="application/javascript">
(function ($) {
function shorten(str) {
var n = 40;
return str.substr(0, n - 1) + (str.length > n ? '...' : '');
}
function formatDate(date) {
if (!date) {
return '-';
}
if (date.toString().match(/^[0-9]+$/)) {
var d = new Date(0);
d.setUTCSeconds(date);
return d.toLocaleDateString();
}
return date;
}
function urlElement(url) {
if (!url) {
return '-';
}
return $('<a/>').attr({ href: url, title: url }).text(shorten(url));
}
function buildBadgeContent(assertion) {
var el = $('.badge-template').clone().removeClass('badge-template');
el.find('img.badge-image').attr('src', assertion.badge.image);
el.find('tr.issuer-name td.value').text(assertion.badge.issuer.name);
el.find('tr.issuer-url td.value').html(urlElement(assertion.badge.issuer.origin));
el.find('tr.issuer-organization td.value').text(assertion.badge.issuer.org || '-');
el.find('tr.badge-name td.value').text(assertion.badge.name);
el.find('tr.badge-description td.value').text(assertion.badge.description);
el.find('tr.badge-criteria td.value').html(urlElement(assertion.badge.criteria));
el.find('tr.issuance-evidence td.value').html(urlElement(assertion.evidence));
el.find('tr.issuance-issuedon td.value').text(formatDate(assertion.issued_on));
el.find('tr.issuance-expires td.value').text(formatDate(assertion.expires));
return el.prop('outerHTML');
}
function showBadgeContent(data) {
/* Add a modal dialog if not exists */
if (jQuery('div#content').length == 1 && jQuery('div#content #badge-content-dialog').length == 0) {
jQuery('div#content').append(
'<div id="badge-content-dialog" class="modal fade page-modal js-page-modal" role="dialog"> ' +
' <div class="modal-dialog">' +
' <div class="modal-content">' +
' <div class="modal-body"></div>' +
' <div class="modal-footer">' +
' <button type="button" class="btn btn-default" data-dismiss="modal">{{str tag=Close}}</button>' +
' </div>' +
' </div>' +
' </div>' +
'</div>');
}
jQuery('#badge-content-dialog .modal-body').html(data.html);
jQuery('#badge-content-dialog').modal('show');
}
$(function () {
$('#openbadges{{$id}}').on('click', 'img', function () {
showBadgeContent({html: buildBadgeContent($(this).data('assertion'))});
......@@ -76,5 +10,4 @@
})(jQuery);
</script>
{{* {include file="pagemodal.tpl"} *}}
{{include file="blocktype:openbadgedisplayer:badge.tpl"}}
......@@ -24,7 +24,7 @@
}
.openbadges-block img {
width: 90px;
width: 90px;
height: 90px;
float: left;
cursor: pointer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment