-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…02401] * Move from: `user/*.js` to: `js/src/*.js` * 03-15 August 2017
- Loading branch information
Showing
14 changed files
with
663 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*! | ||
OU-OpenID. © Nick Freear. © The Open University. | ||
NDF, 3-August-2017. | ||
*/ | ||
|
||
// IMPORTANT: console.debug() does NOT print output !! | ||
|
||
'use strict'; | ||
|
||
var util = require('./src/ouop-utils'); | ||
var userJsonUrl = '/auth/ouopenid/user/ajax.php?r=' + util.rand(); | ||
|
||
require('./src/when-call')( | ||
function () { | ||
console.debug('>> when'); | ||
return window.jQuery; | ||
}, | ||
function ($) { | ||
var W = window; | ||
var L = W.location; | ||
|
||
console.debug('>> call'); | ||
|
||
if (L.pathname.match(/^\/admin\//)) { | ||
return console.warn('ouopenid: admin page, exiting.'); | ||
} | ||
|
||
var $body = $('body'); | ||
|
||
$body.addClass(L.href.match(/debug=1/) ? 'debug-param' : ''); | ||
|
||
console.warn('ouopenid $:', $.fn.jquery, W.M.cfg); // W.Y.version | ||
|
||
$.getJSON(userJsonUrl).done(function (data, textStat, jqXHR) { // W.M.cfg.wwwroot + .. | ||
console.debug('>> getJSON..'); | ||
|
||
util.set_strings(data); | ||
|
||
data.util = util; | ||
data.$ = $; | ||
|
||
if (! data.profile.ouop_oucu) { | ||
console.warn('ouopenid warning: missing profile.'); | ||
|
||
$body.addClass('ouop-ouopenid-warn-profile'); | ||
} | ||
|
||
console.warn('ouopenid JSON: ', data, jqXHR); | ||
|
||
require('./src/analytics').run($, data); | ||
// ga.analytics($, data); | ||
// ga.handle_moodle_events($); | ||
|
||
$body.addClass(data.body_class) | ||
.addClass(data.profile.ouop_is_team ? 'ouop-is-team' : 'ouop-not-team'); | ||
|
||
$body.addClass(data.debug); | ||
|
||
require('./src/oupilot-ui')($, data); | ||
|
||
require('./src/moodle-user-profile')($, data); | ||
|
||
// .. | ||
|
||
require('./src/local-fixes')($, data); | ||
|
||
require('./src/survey-embed-link')($, data); | ||
|
||
require('./src/tesla-statistics')($); | ||
}) | ||
.fail(function (jqXHR, textStat, ex) { | ||
console.error('ouopenid error: ', textStat, jqXHR, ex); | ||
|
||
$body.addClass('ouop-ouopenid-error-' + jqXHR.status); | ||
}); | ||
|
||
util.less_test($); | ||
} | ||
); | ||
|
||
// End. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/*! | ||
OU-OpenID. © Nick Freear. © The Open University. @preserve | ||
NDF, 3-August-2017. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*! | ||
OU-OpenID. © Nick Freear. © The Open University. (NDF / 02-April-2017) | ||
*/ | ||
|
||
/* global ga: false */ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
run: function ($, resp) { | ||
include_ga_javascript(); | ||
|
||
pageview(resp); | ||
|
||
handle_moodle_events($); | ||
}, | ||
|
||
analytics: function ($, resp) { | ||
include_ga_javascript(); | ||
|
||
pageview(resp); | ||
}, | ||
|
||
handle_moodle_events: handle_moodle_events | ||
}; | ||
|
||
var W = window; | ||
var C = W.console; | ||
|
||
function include_ga_javascript () { | ||
/* eslint-disable *//* jshint ignore:start */ | ||
(function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () { | ||
(i[r].q = i[r].q || []).push(arguments) }, i[r]. l = 1 * new Date(); a = s.createElement(o), | ||
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m) | ||
})(window, window.document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); | ||
/* eslint-enable *//* jshint ignore:end */ | ||
} | ||
|
||
function pageview (resp) { | ||
/* Google Analytics. | ||
*/ | ||
ga('create', resp.config.ga, 'auto'); | ||
ga('send', 'pageview'); | ||
|
||
C.debug('ouop: analytics', resp.config.ga); | ||
} | ||
|
||
function handle_moodle_events ($) { | ||
var $events = $('script[ data-ouop-event ]'); | ||
|
||
$events.each(function (idx, el) { // if ($events.length > 0) { | ||
var event = JSON.parse($(el).text()); | ||
|
||
C.warn('ouop: event', idx, event); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// TeSLA-specific fixes ~~ usability and clarity. | ||
// OUOP.local_fixes = function | ||
|
||
module.exports = function ($, resp) { | ||
|
||
fix_typing_enrollment_page($); | ||
fix_enrollment_start_page($, resp); | ||
|
||
console.warn('ouop: tesla-local-fixes'); | ||
}; | ||
|
||
var tesla_inst_names = { | ||
'Keystroke Dynamics': 'ks', | ||
'Anti-plagiarism': 'tpt', | ||
'Forensic Analysis': 'fa', | ||
'Face Recognition': 'fr', | ||
'Voice Recognition': 'vr' | ||
}; | ||
|
||
function fix_typing_enrollment_page($) { | ||
var $wordcount = $('.path-local-tesla-views .btn #word_counter'); | ||
var $btn = $wordcount.closest('button'); | ||
var $form = $wordcount.closest('form'); | ||
var $question = $form.find('legend').first(); | ||
|
||
$btn.html( | ||
'<span id="ouop-wc-outer" title="Word count">Words: <span id="word_counter" class="badge">0 / 250</span></span> Continue'); | ||
|
||
// Was: $wordcount.attr('title', 'Word count'); | ||
|
||
$form.addClass('ouop-tesla-ks-enrollment-form'); | ||
|
||
var qm = $question.text().match(/Q #?(\d) of (\d)\./); | ||
var qn_text; | ||
|
||
if (qm) { | ||
qn_text = '<small data-ouop-qn="%1">Question <i>%2</i><span> of %3</span></small>' | ||
.replace(/%1/, qm[ 1 ]).replace(/%2/, qm[ 1 ]).replace(/%3/, qm[ 2 ]); | ||
|
||
$question.html($question.text().replace(qm[ 0 ], qn_text)); | ||
} | ||
} | ||
|
||
// 14-August-2017. | ||
function fix_enrollment_start_page($, resp) { | ||
var $alert = $('#page-local-tesla-views-enrollment #user-notifications .alert'); | ||
var message = $alert.text(); | ||
var m_enroll = message ? message.match(/The required enrollments are: ([\w ]+)/) : null; | ||
var inst = m_enroll ? m_enroll[ 1 ] : null; | ||
var inst_code = inst in tesla_inst_names ? tesla_inst_names[ inst ] : null; | ||
|
||
if (inst) { | ||
$('body') | ||
.addClass('ouop-enroll-page') | ||
.addClass('ouop-enroll-' + inst.replace(' ', '-')) | ||
.addClass('ouop-enroll-' + inst_code); | ||
|
||
$alert.removeClass('alert-danger').addClass('alert-warning'); | ||
|
||
console.warn('ouop. Enroll instrument:', inst_code, inst); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Streamline the Moodle user profile form, and pages. | ||
|
||
var util; | ||
|
||
module.exports = function ($, resp) { | ||
util = resp.util; | ||
|
||
complete_user_profile_form($, resp); | ||
user_profile_form_redirect($, resp); | ||
user_profile_continue_link($, resp); | ||
|
||
// Was: if ( L.pathname.match(/^\/user\/edit/) ) | ||
if (! resp.profile.ouop_is_team) { | ||
disable_user_profile_form($); | ||
} | ||
}; | ||
|
||
var W = window; | ||
var C = W.console; | ||
|
||
function complete_user_profile_form ($, resp) { | ||
var $form = $('#page-user-edit #region-main form'); | ||
var $inp_fname = $form.find('[ name = firstname ]'); | ||
var $inp_lname = $form.find('[ name = lastname ]'); | ||
var $inp_email = $form.find('[ name = email ]'); | ||
var prof = resp.profile; | ||
var isteam = prof.ouop_is_team; | ||
|
||
if ($form.length && !$inp_fname.val()) { | ||
$inp_fname.val(isteam ? prof.ouop_firstname : prof.ouop_oucu); | ||
$inp_lname.val(isteam ? prof.ouop_lastname : 'test'); | ||
$inp_email.val(isteam ? prof.ouop_email : util.str('testmail', prof.ouop_oucu)); | ||
} | ||
|
||
C.debug('ouop: complete-user-profile-form'); | ||
}; | ||
|
||
function user_profile_form_redirect ($, resp) { | ||
var $form = $('#page-user-edit #region-main form'); | ||
var cfg = resp.config; | ||
|
||
if ($form.length && cfg.user_form_redirect) { | ||
W.setTimeout(function () { | ||
C.warn('ouop: user-profile-form-redirect - trigger'); | ||
|
||
$form.trigger('submit'); | ||
}, | ||
cfg.redirect_timeout || 2000); | ||
} | ||
|
||
if (cfg.user_form_redirect) { | ||
$form.before(util.alert(util.str('form_warning'), 'ouop-form-disable')); | ||
} else { | ||
$form.before(util.alert(util.str('form_redirect_msg'), 'ouop-form-disable')); | ||
} | ||
}; | ||
|
||
function user_profile_continue_link ($, resp) { | ||
var $pages = $('#page-user-profile, #page-user-preferences'); | ||
|
||
$pages.find('#page-header') | ||
.after(util.alert('<a href="' + resp.redirect_url + '">' + util.str('continuelink') + '</a>')); | ||
|
||
if (!resp.profile.ouop_is_team && $('#page-user-edit').length) { | ||
C.debug('ouopenid redirecting'); | ||
|
||
// Was: W.location = data.redirect_urL; | ||
} | ||
} | ||
|
||
function disable_user_profile_form ($) { | ||
var $form = $('#page-user-edit #region-main form'); | ||
|
||
$form | ||
.attr('title', util.str('form_warning')) | ||
// Was: .before(util.alert(util.str('form_warning'), 'ouop-form-disable')) | ||
.find('input, select').each(function () { | ||
// Was: $(this).attr('disabled', 'disabled'); | ||
if (!$(this).hasClass('btn')) { | ||
$(this).attr('readonly', 'readonly'); | ||
} | ||
}); | ||
|
||
$form.find('#id_submitbutton').val('Continue').text('Continue'); | ||
} |
Oops, something went wrong.