From 62c38a9138bd32b7f351482797c7950bcdc83043 Mon Sep 17 00:00:00 2001 From: Nick Freear Date: Tue, 14 Mar 2017 17:17:32 +0000 Subject: [PATCH] Bug #1, Added `disable_moodle_user_profile_form()` to JS [iet:8336249] --- composer.json | 2 +- user/script.js | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 605ff00..759c7ee 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ ], "npm-install": "npm install eslint", "eslint-config": [ - "echo '---\n extends: eslint:recommended\n globals:\n window: false\n' > .eslintrc.yaml", + "echo '---\n extends: eslint:recommended\n globals:\n window: false\n root: true\n' > .eslintrc.yaml", "echo '{\n \"extends\": \"eslint:recommended\",\n \"globals\": { \"window\": false }\n}' > .eslintrc-XX.json" ], "eslint-echo": "node_modules/.bin/eslint --print-config .eslintrc.yaml", diff --git a/user/script.js b/user/script.js index 971277a..101d4de 100644 --- a/user/script.js +++ b/user/script.js @@ -4,7 +4,8 @@ (function (W) { - var user_json = '/auth/ouopenid/user/ajax.php?r=' + rand() + var user_json_url = '/auth/ouopenid/user/ajax.php?r=' + rand() + , form_warning = "Please don't edit your user profile!" , C = W.console , L = W.location; @@ -24,9 +25,9 @@ C.debug('ouopenid $:', $.fn.jquery); - $.getJSON(user_json).done(function (data, textStat, jqXHR) { + $.getJSON(user_json_url).done(function (data, textStat, jqXHR) { - if (! data.profile.length) { + if (! data.profile.ouop_oucu) { C.error('ouopenid error: missing profile.'); $body.addClass('ouop-ouopenid-error-profile'); @@ -34,7 +35,13 @@ C.debug('ouopenid JSON: ', data, jqXHR); - $body.addClass(data.body_class); + $body.addClass(data.body_class) + .addClass(data.profile.is_team ? 'ouop-is-team' : 'ouop-not-team'); + + //if ( L.pathname.match(/^\/user\/edit/) ) + if (! data.profile.is_team) { + disable_moodle_user_profile_form($); + } }).fail(function (jqXHR, textStat, ex) { C.error('ouopenid error: ', textStat, jqXHR, ex); @@ -47,6 +54,17 @@ }); + /* ------------------------------------------- */ + + function disable_moodle_user_profile_form($) { + $('form[ action *= "/user/edit" ]') + .attr('title', form_warning) + .before('

%s

'.replace(/%s/, form_warning)) + .find('input, select').each(function () { + $(this).attr('disabled', 'disabled'); + }); + } + function rand() { var min = 11, max = 999; return Math.floor(Math.random() * (max - min)) + min; @@ -59,8 +77,7 @@ W.clearInterval(int_id); callback_FN(); } - }, interval || 200); // Milliseconds. + }, interval || 300); // Milliseconds. } - }(window));