MDL-30839 Accessibility, Forms - Improve accessibility or error messages
[moodle.git] / badges / backpack.js
blob98678e8f29e0c005be4d4257bd797dd14b98e2be
1 /**
2  * Push badges to backpack.
3  */
4 function addtobackpack(event, args) {
5     var badgetable = Y.one('#issued-badge-table');
6     var errordiv = Y.one('#addtobackpack-error');
7     var errortext = M.util.get_string('error:backpackproblem', 'badges');
8     var errorhtml = '<div id="addtobackpack-error" class="box boxaligncenter notifyproblem">' + errortext + '</div>';
10     if (typeof OpenBadges !== 'undefined') {
11         OpenBadges.issue([args.assertion], function(errors, successes) { });
12     } else {
13         // Add error div if it doesn't exist yet.
14         if (!errordiv) {
15             var badgerror = Y.Node.create(errorhtml);
16             badgetable.insert(badgerror, 'before');
17         }
18     }
21 /**
22  * Check if website is externally accessible from the backpack.
23  */
24 function check_site_access() {
25     var add = Y.one('#check_connection');
27     var callback = {
28             method: "GET",
29             on: {
30                 success: function(id, o, args) {
31                             var data = Y.JSON.parse(o.responseText);
32                             if (data.code == 'http-unreachable') {
33                                 add.setHTML(data.response);
34                                 add.removeClass('hide');
35                             }
36                         },
37                 failure: function(o) { }
38             }
39         };
41     Y.use('io-base', function(Y) {
42         Y.io('ajax.php', callback);
43     });
45     return false;