moodle/message/amd/build/message_area_profile.min.js

1 line
4.3 KiB
JavaScript

define(["jquery","core/ajax","core/templates","core/notification","core/str","core/config","core/custom_interaction_events","core_message/message_area_events"],function(a,b,c,d,e,f,g,h){function i(a){this.messageArea=a,this._init()}var j={PROFILE:"[data-region='profile']",PROFILEADDCONTACT:"[data-action='profile-add-contact']",PROFILEBLOCKCONTACT:"[data-action='profile-block-contact']",PROFILEREMOVECONTACT:"[data-action='profile-remove-contact']",PROFILESENDMESSAGE:"[data-action='profile-send-message']",PROFILEUNBLOCKCONTACT:"[data-action='profile-unblock-contact']",PROFILEVIEW:"[data-action='profile-view']",SHOWCONTACTS:"[data-action='show-contacts']",MESSAGESAREA:"[data-region='messages-area']",MESSAGINGAREA:"[data-region='messaging-area']"};return i.prototype.messageArea=null,i.prototype._init=function(){g.define(this.messageArea.node,[g.events.activate]),this.messageArea.onCustomEvent(h.CONTACTSELECTED,this._viewProfile.bind(this)),this.messageArea.onDelegateEvent(g.events.activate,j.PROFILEVIEW,function(a,b){this._viewFullProfile(),b.originalEvent.preventDefault()}.bind(this)),this.messageArea.onDelegateEvent(g.events.activate,j.PROFILESENDMESSAGE,function(a,b){this._sendMessage(),b.originalEvent.preventDefault()}.bind(this)),this.messageArea.onDelegateEvent(g.events.activate,j.PROFILEUNBLOCKCONTACT,function(a,b){this._unblockContact(),b.originalEvent.preventDefault()}.bind(this)),this.messageArea.onDelegateEvent(g.events.activate,j.PROFILEBLOCKCONTACT,function(a,b){this._blockContact(),b.originalEvent.preventDefault()}.bind(this)),this.messageArea.onDelegateEvent(g.events.activate,j.PROFILEADDCONTACT,function(a,b){this._addContact(),b.originalEvent.preventDefault()}.bind(this)),this.messageArea.onDelegateEvent(g.events.activate,j.PROFILEREMOVECONTACT,function(a,b){this._removeContact(),b.originalEvent.preventDefault()}.bind(this)),this.messageArea.onDelegateEvent(g.events.activate,j.SHOWCONTACTS,this._hideMessagingArea.bind(this))},i.prototype._viewProfile=function(a,e){c.render("core/loading",{}).done(function(a,b){c.replaceNodeContents(this.messageArea.find(j.MESSAGESAREA),a,b)}.bind(this));var f=b.call([{methodname:"core_message_data_for_messagearea_get_profile",args:{currentuserid:this.messageArea.getCurrentUserId(),otheruserid:e}}]);return f[0].then(function(a){return c.render("core_message/message_area_profile",a)}).then(function(a,b){c.replaceNodeContents(this.messageArea.find(j.MESSAGESAREA),a,b)}.bind(this)).fail(d.exception)},i.prototype._viewFullProfile=function(){window.location.href=f.wwwroot+"/user/profile.php?id="+this._getUserId()},i.prototype._sendMessage=function(){this.messageArea.trigger(h.SENDMESSAGE,this._getUserId())},i.prototype._blockContact=function(){var a=this._performAction("core_message_block_contacts","unblockcontact","profile-block-contact","profile-unblock-contact","");return a.then(function(){this.messageArea.trigger(h.CONTACTBLOCKED,this._getUserId())}.bind(this))},i.prototype._unblockContact=function(){var a=this._performAction("core_message_unblock_contacts","blockcontact","profile-unblock-contact","profile-block-contact","danger");return a.then(function(){this.messageArea.trigger(h.CONTACTUNBLOCKED,this._getUserId())}.bind(this))},i.prototype._addContact=function(){var a=this._performAction("core_message_create_contacts","removecontact","profile-add-contact","profile-remove-contact","danger");return a.then(function(){this.messageArea.trigger(h.CONTACTADDED,this._getUserId())}.bind(this))},i.prototype._removeContact=function(){var a=this._performAction("core_message_delete_contacts","addcontact","profile-remove-contact","profile-add-contact","");return a.then(function(){this.messageArea.trigger(h.CONTACTREMOVED,this._getUserId())}.bind(this))},i.prototype._performAction=function(a,c,f,g,h){var i=b.call([{methodname:a,args:{userid:this.messageArea.getCurrentUserId(),userids:[this._getUserId()]}}]);return i[0].then(function(){return e.get_string(c,"message")}).then(function(a){this._changeText(a,f,g,h)}.bind(this)).fail(d.exception)},i.prototype._changeText=function(a,b,c,d){var e=this.messageArea.find("[data-action='"+b+"']");e.text(a),e.removeClass(),d&&e.addClass(d),e.attr("data-action",c)},i.prototype._getUserId=function(){return this.messageArea.find(j.PROFILE).data("userid")},i.prototype._hideMessagingArea=function(){this.messageArea.find(j.MESSAGINGAREA).removeClass("show-messages").addClass("hide-messages")},i});