Permalink
Browse files

MDL-33680 JavaScript: Improve error handling on user selector

Since the previous commit to this issue removes the built-in debugging
tests, I've added these back using the M.core libraries.
  • Loading branch information...
1 parent 2803733 commit c2f47c19ad7ede2990661a3149a7143ad7c9e3d1 @andrewnicols andrewnicols committed Mar 12, 2013
Showing with 10 additions and 22 deletions.
  1. +1 −1 user/selector/lib.php
  2. +9 −21 user/selector/module.js
View
@@ -70,7 +70,7 @@
protected static $jsmodule = array(
'name' => 'user_selector',
'fullpath' => '/user/selector/module.js',
- 'requires' => array('node', 'event-custom', 'datasource', 'json'),
+ 'requires' => array('node', 'event-custom', 'datasource', 'json', 'moodle-core-notification'),
'strings' => array(
array('previouslyselectedusers', 'moodle', '%%SEARCHTERM%%'),
array('nomatchingusers', 'moodle', '%%SEARCHTERM%%'),
View
@@ -151,8 +151,7 @@ M.core_user.init_user_selector = function (Y, name, hash, extrafields, lastsearc
method: 'POST',
data: 'selectorid='+hash+'&sesskey='+M.cfg.sesskey+'&search='+value + '&userselector_searchanywhere=' + this.get_option('searchanywhere'),
on: {
- success:this.handle_response,
- failure:this.handle_failure
+ complete: this.handle_response
},
context:this
});
@@ -175,26 +174,15 @@ M.core_user.init_user_selector = function (Y, name, hash, extrafields, lastsearc
}
this.listbox.setStyle('background','');
var data = Y.JSON.parse(response.responseText);
+ if (data.error) {
+ this.searchfield.addClass('error');
+ return new M.core.ajaxException(data);
+ }
this.output_options(data);
} catch (e) {
- this.handle_failure(requestid);
- }
- },
- /**
- * Handles what happens when the ajax request fails.
- */
- handle_failure : function(requestid) {
- delete this.iotransactions[requestid];
- if (!Y.Object.isEmpty(this.iotransactions)) {
- // More searches pending. Wait until they are all done.
- return;
- }
- this.listbox.setStyle('background','');
- this.searchfield.addClass('error');
-
- // If we are in developer debug mode, output a link to help debug the failure.
- if (M.cfg.developerdebug) {
- this.searchfield.insert(Y.Node.create('<a href="'+M.cfg.wwwroot +'/user/selector/search.php?selectorid='+hash+'&sesskey='+M.cfg.sesskey+'&search='+this.get_search_text()+'&debug=1">Ajax call failed. Click here to try the search call directly.</a>'));
+ this.listbox.setStyle('background','');
+ this.searchfield.addClass('error');
+ return new M.core.exception(e);
}
},
/**
@@ -379,4 +367,4 @@ M.core_user.init_user_selector_options_tracker = function(Y) {
user_selector_options_tracker.init();
// Return it just incase it is ever wanted
return user_selector_options_tracker;
-};
+};

0 comments on commit c2f47c1

Please sign in to comment.