You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
1.3 KiB

define(["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.hasClass("loading")||a.attr("disabled")},k=function(c,e){return j(c)?a.Deferred():(c.addClass("loading"),c.attr("disabled","disabled"),b.call([e])[0].fail(d.exception).always(function(){c.removeClass("loading"),c.removeAttr("disabled")}))},l=function(a){if(!j(a)){var b={methodname:"core_message_create_contacts",args:{userids:[i(a)]}};k(a,b).done(function(){g(a),c.render("message/remove_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})}},m=function(a){if(!j(a)){var b={methodname:"core_message_delete_contacts",args:{userids:[i(a)]}};k(a,b).done(function(){h(a),c.render("message/add_contact_button",{}).done(function(b,d){c.replaceNodeContents(a,b,d)})})}},n=function(b){b=a(b),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){f(b)?m(b):l(b),a.preventDefault(),c.originalEvent.preventDefault()})};return{enhance:n}});