Merge branch 'MDL-51969-master' of https://github.com/dmitriim/moodle
[moodle.git] / badges / backpack.js
blob2282907d6c7cc80605b25401c2a5aaf8dc0fdbab
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) {
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                     M.util.js_complete('badge/backpack::check_site_access');
37                 },
38                 failure: function() {
39                     M.util.js_complete('badge/backpack::check_site_access');
40                 }
41             }
42         };
44     Y.use('io-base', function(Y) {
45         M.util.js_pending('badge/backpack::check_site_access');
46         Y.io('ajax.php', callback);
47     });
49     return false;