Skip to content

Commit

Permalink
Bug #1, Added disable_moodle_user_profile_form() to JS [iet:8336249]
Browse files Browse the repository at this point in the history
  • Loading branch information
nfreear committed Mar 14, 2017
1 parent b4f7e0e commit 62c38a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 23 additions & 6 deletions user/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,17 +25,23 @@

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');
}

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);
Expand All @@ -47,6 +54,17 @@
});


/* ------------------------------------------- */

function disable_moodle_user_profile_form($) {
$('form[ action *= "/user/edit" ]')
.attr('title', form_warning)
.before('<p class="ouop-form-disable alert alert-warning">%s</p>'.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;
Expand All @@ -59,8 +77,7 @@
W.clearInterval(int_id);
callback_FN();
}
}, interval || 200); // Milliseconds.
}, interval || 300); // Milliseconds.
}


}(window));

0 comments on commit 62c38a9

Please sign in to comment.