Skip to content

Commit

Permalink
Bug #8, fix to generic_embeds() Javascript function; BRASIL [iet:10…
Browse files Browse the repository at this point in the history
…334595]

* Plus, add `create_survey_url()` function
* https://iet.eu.teamwork.com/desk/#/tickets/248080
  • Loading branch information
nfreear committed May 31, 2018
1 parent c4adfc1 commit f9b5fc2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions js/src/ouop-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function ouop_less_test ($) {
}

// https://github.com/nfreear/gaad-widget/blob/3.x/src/methods.js#L79-L85
function replace_object (str, mapObj) {
var re = new RegExp(Object.keys(mapObj).join('|'), 'g'); // Was: "gi".
function replace_object (str, mapObj, reFlags) {
var re = new RegExp(Object.keys(mapObj).join('|'), reFlags || 'g'); // Was: "gi".

return str.replace(re, function (matched) {
return mapObj[ matched ]; // Was: matched.toLowerCase().
Expand Down
2 changes: 1 addition & 1 deletion js/src/oupilot-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var L = W.location;
var C = W.console;

function add_course_code_to_urls ($, resp) {
var $links = $('a').filter('[ href *= "/mod/" ], [ href *= "/course/" ]');
var $links = $('a').filter('[href *= "/mod/"], [href *= "/course/"]');

$links.each(function (idx, el) {
var url = $(el).attr('href');
Expand Down
22 changes: 15 additions & 7 deletions js/src/survey-embed-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ function generic_embeds ($, resp) {
}

var $links = $('a[ href *= _EMBED_ME_ ]');
var util = resp.util;
var replaceObj = resp.util.replace; // Was: var util = resp.util;

$links.each(function (idx, el) {
var $link = $(el);
var url = util.replace($link.attr('href'), { '{oucu}': resp.profile.ouop_oucu });
var url = create_survey_url($link.attr('href'), resp);
var m_height = url.match(/height=(\d+\w+);?/);
var height = 'height: ' + (m_height ? m_height[ 1 ] : '1050px;');

$link.replaceWith(util.replace('<iframe src="{u}" style="{h}" class="ouop-generic-ifr" id="ifr-{i}"></iframe>', {
$link.replaceWith(replaceObj('<iframe src="{u}" style="{h}" class="ouop-generic-ifr" id="ifr-{i}"></iframe>', {
'{u}': url, '{h}': height, '{i}': idx
})); // .replace(/%s/, url).replace(/%h/, height).replace(/%d/, idx)
var $iframe = $('#s' + idx);
Expand All @@ -40,7 +40,9 @@ function generic_embeds ($, resp) {
}

function embed_pilot_surveys ($, resp) {
var $links = $('a[ href *= -pre-survey-embed ], a[ href *= -post-survey-embed ]');
var $links = $('a').filter('[ href *= -pre-survey-embed ], [ href *= -post-survey-embed ]');
// Was: var $links = $('a[ href *= -pre-survey-embed ], a[ href *= -post-survey-embed ]');
var replaceObj = resp.util.replace;

$links.each(function (idx, el) {
var $link = $(el);
Expand All @@ -50,9 +52,10 @@ function embed_pilot_surveys ($, resp) {
var m_height = url.match(/height=(\d+\w+);?/);
var height = m_height ? ('height: '+ m_height[ 1 ]) : '';

survey_url = survey_url.replace(/\{?OUCU\}?/, resp.profile.ouop_oucu).replace(/\{COURSE\}/gi, resp.course_code);
survey_url = create_survey_url(survey_url, resp);
// Was: survey_url = survey_url.replace(/\{?OUCU\}?/, resp.profile.ouop_oucu).replace(/\{COURSE\}/gi, resp.course_code);

$link.replaceWith(resp.util.replace('<iframe src="{u}" style="{h}" id="ifr-{i}"></iframe>', {
$link.replaceWith(replaceObj('<iframe src="{u}" style="{h}" class="ouop-survey-ifr" id="ifr-{i}"></iframe>', {
'{u}': survey_url, '{h}': height, '{i}': idx
})); // .replace(/%s/, survey_url).replace(/%h/, height).replace(/%d/, idx)

Expand Down Expand Up @@ -90,7 +93,8 @@ function inject_post_activity_survey_link ($, resp) {
// var $container_quiz_rev = $('#page-mod-quiz-review #user-notifications');
var $container_quiz = $('.path-mod-quiz'); // Was: $('#page-mod-quiz-view');
var $container_assign = $('#page-mod-assign-view');
var survey_url = resp.survey_urls.post.replace('{OUCU}', resp.profile.ouop_oucu).replace('{COURSE}', resp.course_code);
var survey_url = create_survey_url(resp.survey_urls.post, resp);
// Was: resp.survey_urls.post.replace('{OUCU}', resp.profile.ouop_oucu).replace('{COURSE}', resp.course_code);
// WAS: var survey_url = resp.survey_urls[ resp.course_code ].post.replace('{OUCU}', resp.profile.ouop_oucu);
var util = resp.util;

Expand Down Expand Up @@ -130,3 +134,7 @@ function survey_return_redirect ($, resp) {
W.location = resp.redirect_url;
}
}

function create_survey_url(url, resp) {
return resp.util.replace(url, { '{oucu}': resp.profile.ouop_oucu, '{course}': resp.course_code }, 'gi');
}

0 comments on commit f9b5fc2

Please sign in to comment.