moodle/message/amd/build/toggle_contact_button.min.js
2020-09-07 09:10:46 +08:00

3 lines
1.5 KiB
JavaScript

define ("core_message/toggle_contact_button",["jquery","core/ajax","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e){var f=function(a){return"1"==a.attr("data-is-contact")},g=function(a){a.attr("data-is-contact","1")},h=function(a){a.attr("data-is-contact","0")},i=function(a){return a.attr("data-userid")},j=function(a){return a.attr("data-currentuserid")},k=function(a){return a.hasClass("loading")||a.attr("disabled")},l=function(c,e){if(k(c)){return a.Deferred()}c.addClass("loading");c.attr("disabled","disabled");return b.call([e])[0].fail(d.exception).always(function(){c.removeClass("loading");c.removeAttr("disabled")})},m=function(a){if(k(a)){return}var b={methodname:"core_message_create_contact_request",args:{userid:j(a),requesteduserid:i(a)}};l(a,b).done(function(){g(a);c.render("message/remove_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})},n=function(a){if(k(a)){return}var b={methodname:"core_message_delete_contacts",args:{userids:[i(a)]}};l(a,b).done(function(){h(a);c.render("message/add_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})};return{enhance:function enhance(b){b=a(b);if(!b.children(".loading-icon").length){c.render("core/loading",{}).done(function(a,c){b.append(a,c)})}e.define(b,[e.events.activate]);b.on(e.events.activate,function(a,c){if(f(b)){n(b)}else{m(b)}a.preventDefault();c.originalEvent.preventDefault()})}}});
//# sourceMappingURL=toggle_contact_button.min.js.map