text: window.wp=window.wp||{},window.bp=window.bp||{},function(e,s){"undefined"!=typeof BP_Nouveau&&(_.extend(bp,_.pick(wp,"Backbone","ajax","template")),bp.Models=bp.Models||{},bp.Collections=bp.Collections||{},bp.Views=bp.Views||{},bp.Nouveau=bp.Nouveau||{},bp.Nouveau.Messages={start:function(){this.views=new Backbone.Collection,this.threads=new bp.Collections.Threads,this.messages=new bp.Collections.Messages,this.router=new bp.Nouveau.Messages.Router,this.box="inbox",this.setupNav(),Backbone.history.start({pushState:!0,root:BP_Nouveau.messages.rootUrl})},setupNav:function(){var e=this;s("#compose-personal-li").addClass("last"),s("#subnav a").on("click",function(t){t.preventDefault();var a=s(t.target).prop("id");if(e.removeTinyMCE(),"compose"===a)if(_.isUndefined(e.views.get("compose")))e.router.navigate("compose/",{trigger:!0});else{var i=e.views.get("compose");i.get("view").remove(),e.views.remove({id:"compose",view:i}),"single"===e.box&&(e.box="inbox"),e.router.navigate(e.box+"/",{trigger:!0})}else e.box===a&&_.isUndefined(e.views.get("compose"))||(e.clearViews(),e.router.navigate(a+"/",{trigger:!0}))})},removeTinyMCE:function(){"undefined"!=typeof tinymce&&null!==tinymce.get("message_content")&&tinymce.EditorManager.execCommand("mceRemoveEditor",!0,"message_content")},tinyMCEinit:function(){void 0!==window.tinyMCE&&null!==window.tinyMCE.activeEditor&&void 0!==window.tinyMCE.activeEditor&&(_.isEmpty(e.mentions)||s(window.tinyMCE.activeEditor.contentDocument.activeElement).atwho("setIframe",s("#message_content_ifr")[0]).bp_mentions({data:[],suffix:" "}))},removeFeedback:function(){var e;_.isUndefined(this.views.get("feedback"))||((e=this.views.get("feedback")).get("view").remove(),this.views.remove({id:"feedback",view:e}))},displayFeedback:function(e,s){var t;this.removeFeedback(),e&&(t=new bp.Views.Feedback({value:e,type:s||"info"}),this.views.add({id:"feedback",view:t}),t.inject(".bp-messages-feedback"))},clearViews:function(){_.isUndefined(this.views.models)||(_.each(this.views.models,function(e){e.get("view").remove()},this),this.views.reset())},composeView:function(){this.clearViews();var e=new bp.Views.messageForm({model:new bp.Models.Message});this.views.add({id:"compose",view:e}),e.inject(".bp-messages-content")},threadsView:function(){s("#subnav ul li").each(function(e,t){s(t).removeClass("current selected")}),s("#subnav a#"+this.box).closest("li").addClass("current selected");var e=new bp.Views.userThreads({collection:this.threads,box:this.box});this.views.add({id:"threads",view:e}),e.inject(".bp-messages-content"),this.displayFilters(this.threads)},displayFilters:function(e){var s;this.filters=new Backbone.Model({page:1,total_page:0,search_terms:"",box:this.box}),s=new bp.Views.messageFilters({model:this.filters,threads:e}),this.views.add({id:"filters",view:s}),s.inject(".bp-messages-filters")},singleView:function(e){this.clearViews(),this.box="single";var s=new bp.Views.userMessages({collection:this.messages,thread:e});this.views.add({id:"single",view:s}),s.inject(".bp-messages-content")}},bp.Models.Message=Backbone.Model.extend({defaults:{send_to:[],subject:"",message_content:"",meta:{}},sendMessage:function(){if(!0!==this.get("sending")){this.set("sending",!0,{silent:!0});var e=bp.ajax.post("messages_send_message",_.extend({nonce:BP_Nouveau.messages.nonces.send},this.attributes));return this.set("sending",!1,{silent:!0}),e}}}),bp.Models.Thread=Backbone.Model.extend({defaults:{id:0,message_id:0,subject:"",excerpt:"",content:"",unread:!0,sender_name:"",sender_link:"",sender_avatar:"",count:0,date:0,display_date:"",recipients:[]},updateReadState:function(e){return e=e||{},e.data=_.extend(_.pick(this.attributes,["id","message_id"]),{action:"messages_thread_read",nonce:BP_Nouveau.nonces.messages}),bp.ajax.send(e)}}),bp.Models.messageThread=Backbone.Model.extend({defaults:{id:0,content:"",sender_id:0,sender_name:"",sender_link:"",sender_avatar:"",date:0,display_date:""}}),bp.Collections.Threads=Backbone.Collection.extend({model:bp.Models.Thread,initialize:function(){this.options={page:1,total_page:0}},sync:function(e,s,t){if(t=t||{},t.context=this,t.data=t.data||{},t.data.nonce=BP_Nouveau.nonces.messages,"read"===e)return t.data=_.extend(t.data,{action:"messages_get_user_message_threads"}),bp.ajax.send(t)},parse:function(e){return _.isArray(e.threads)||(e.threads=[e.threads]),_.each(e.threads,function(s,t){_.isNull(s)||(e.threads[t].id=s.id,e.threads[t].message_id=s.message_id,e.threads[t].subject=s.subject,e.threads[t].excerpt=s.excerpt,e.threads[t].content=s.content,e.threads[t].unread=s.unread,e.threads[t].sender_name=s.sender_name,e.threads[t].sender_link=s.sender_link,e.threads[t].sender_avatar=s.sender_avatar,e.threads[t].count=s.count,e.threads[t].date=new Date(s.date),e.threads[t].display_date=s.display_date,e.threads[t].recipients=s.recipients,e.threads[t].star_link=s.star_link,e.threads[t].is_starred=s.is_starred)}),_.isUndefined(e.meta)||(this.options.page=e.meta.page,this.options.total_page=e.meta.total_page),bp.Nouveau.Messages.box&&(this.options.box=bp.Nouveau.Messages.box),_.isUndefined(e.extraContent)||_.extend(this.options,_.pick(e.extraContent,["beforeLoop","afterLoop"])),e.threads},doAction:function(e,s,t){return t=t||{},t.context=this,t.data=t.data||{},t.data=_.extend(t.data,{action:"messages_"+e,nonce:BP_Nouveau.nonces.messages,id:s}),bp.ajax.send(t)}}),bp.Collections.Messages=Backbone.Collection.extend({model:bp.Models.messageThread,options:{},sync:function(e,s,t){return t=t||{},t.context=this,t.data=t.data||{},t.data.nonce=BP_Nouveau.nonces.messages,"read"===e?(t.data=_.extend(t.data,{action:"messages_get_thread_messages"}),bp.ajax.send(t)):"create"===e?(t.data=_.extend(t.data,{action:"messages_send_reply",nonce:BP_Nouveau.messages.nonces.send},s||{}),bp.ajax.send(t)):void 0},parse:function(e){return _.isArray(e.messages)||(e.messages=[e.messages]),_.each(e.messages,function(s,t){_.isNull(s)||(e.messages[t].id=s.id,e.messages[t].content=s.content,e.messages[t].sender_id=s.sender_id,e.messages[t].sender_name=s.sender_name,e.messages[t].sender_link=s.sender_link,e.messages[t].sender_avatar=s.sender_avatar,e.messages[t].date=new Date(s.date),e.messages[t].display_date=s.display_date,e.messages[t].star_link=s.star_link,e.messages[t].is_starred=s.is_starred)}),_.isUndefined(e.thread)||(this.options.thread_id=e.thread.id,this.options.thread_subject=e.thread.subject,this.options.recipients=e.thread.recipients),e.messages}}),bp.Nouveau.Messages.View=bp.Backbone.View.extend({inject:function(e){this.render(),s(e).html(this.el),this.views.ready()},prepare:function(){return!_.isUndefined(this.model)&&_.isFunction(this.model.toJSON)?this.model.toJSON():{}}}),bp.Views.Feedback=bp.Nouveau.Messages.View.extend({tagName:"div",className:"bp-messages bp-user-messages-feedback",template:bp.template("bp-messages-feedback"),initialize:function(){this.model=new Backbone.Model({type:this.options.type||"info",message:this.options.value})}}),bp.Views.Hook=bp.Nouveau.Messages.View.extend({tagName:"div",template:bp.template("bp-messages-hook"),initialize:function(){this.model=new Backbone.Model({extraContent:this.options.extraContent}),this.el.className="bp-messages-hook",this.options.className&&(this.el.className+=" "+this.options.className)}}),bp.Views.messageEditor=bp.Nouveau.Messages.View.extend({template:bp.template("bp-messages-editor"),initialize:function(){this.on("ready",this.activateTinyMce,this)},activateTinyMce:function(){"undefined"!=typeof tinymce&&tinymce.EditorManager.execCommand("mceAddEditor",!0,"message_content")}}),bp.Views.messageForm=bp.Nouveau.Messages.View.extend({tagName:"form",id:"send_message_form",className:"standard-form",template:bp.template("bp-messages-form"),events:{"click #bp-messages-send":"sendMessage","click #bp-messages-reset":"resetForm"},initialize:function(){this.resetModel=this.model.clone(),this.views.add("#bp-message-content",new bp.Views.messageEditor),this.model.on("change",this.resetFields,this),this.on("ready",this.addMentions,this)},addMentions:function(){var e=s(this.el).find("#send-to-input"),t=bp.Nouveau.getLinkParams(null,"r")||null;e.bp_mentions({data:[],suffix:" "}),_.isNull(t)||(e.val("@"+_.escape(t)+" "),e.focus())},resetFields:function(e){_.each(e.previousAttributes(),function(e,t){"message_content"===t?void 0!==tinyMCE.activeEditor&&null!==tinyMCE.activeEditor&&tinyMCE.activeEditor.setContent(""):"meta"!==t&&!1!==e&&s('input[name="'+t+'"]').val("")}),s(this.el).trigger("message:reset",_.pick(e.previousAttributes(),"meta"))},sendMessage:function(e){var t={},a=[],i=this;if(e.preventDefault(),bp.Nouveau.Messages.removeFeedback(),_.each(this.$el.serializeArray(),function(e){if(e.name=e.name.replace("[]",""),-1===_.indexOf(["send_to","subject","message_content"],e.name))_.isUndefined(t[e.name])?t[e.name]=e.value:(_.isArray(t[e.name])||(t[e.name]=[t[e.name]]),t[e.name].push(e.value));else if("send_to"===e.name){var i=e.value.match(/(^|[^@\w\-])@([a-zA-Z0-9_\-]{1,50})\b/g);i?((i=i.map(function(e){return e=s.trim(e)}))&&s.isArray(i)||a.push("send_to"),this.model.set("send_to",i,{silent:!0})):a.push("send_to")}else"message_content"===e.name&&void 0!==tinyMCE.activeEditor&&(e.value=tinyMCE.activeEditor.getContent()),e.value?this.model.set(e.name,e.value,{silent:!0}):a.push(e.name)},this),a.length){var n="";return _.each(a,function(e){n+=BP_Nouveau.messages.errors[e]+"<br/>"}),void bp.Nouveau.Messages.displayFeedback(n,"error")}this.model.set("meta",t,{silent:!0}),this.model.sendMessage().done(function(e){i.model.set(i.resetModel),bp.Nouveau.Messages.displayFeedback(e.feedback,e.type),bp.Nouveau.Messages.removeTinyMCE();var s=bp.Nouveau.Messages.views.get("compose");s.get("view").remove(),bp.Nouveau.Messages.views.remove({id:"compose",view:s}),bp.Nouveau.Messages.router.navigate("sentbox/",{trigger:!0})}).fail(function(e){e.feedback&&bp.Nouveau.Messages.displayFeedback(e.feedback,e.type)})},resetForm:function(e){e.preventDefault(),this.model.set(this.resetModel)}}),bp.Views.userThreads=bp.Nouveau.Messages.View.extend({tagName:"div",events:{"click .subject":"changePreview"},initialize:function(){var e=[new bp.Nouveau.Messages.View({tagName:"ul",id:"message-threads",className:"message-lists"}),new bp.Views.previewThread({collection:this.collection})];_.each(e,function(e){this.views.add(e)},this),this.requestThreads(),this.collection.on("reset",this.cleanContent,this),this.collection.on("add",this.addThread,this)},requestThreads:function(){this.collection.reset(),bp.Nouveau.Messages.displayFeedback(BP_Nouveau.messages.loading,"loading"),this.collection.fetch({data:_.pick(this.options,"box"),success:_.bind(this.threadsFetched,this),error:this.threadsFetchError})},threadsFetched:function(){bp.Nouveau.Messages.removeFeedback(),this.collection.options.afterLoop&&this.views.add(new bp.Views.Hook({extraContent:this.collection.options.afterLoop,className:"after-messages-loop"}),{at:1}),this.collection.options.beforeLoop&&this.views.add(new bp.Views.Hook({extraContent:this.collection.options.beforeLoop,className:"before-messages-loop"}),{at:0}),bp.Nouveau.Messages.displayFeedback(BP_Nouveau.messages.howto,"info")},threadsFetchError:function(e,s){bp.Nouveau.Messages.displayFeedback(s.feedback,s.type)},cleanContent:function(){_.each(this.views._views["#message-threads"],function(e){e.remove()})},addThread:function(e){var s=this.collection.findWhere({active:!0});_.isUndefined(s)&&e.set("active",!0),this.views.add("#message-threads",new bp.Views.userThread({model:e}))},setActiveThread:function(e){e&&_.each(this.collection.models,function(s){s.id===e?s.set("active",!0):s.unset("active")},this)},changePreview:function(e){var t=s(e.currentTarget);e.preventDefault(),bp.Nouveau.Messages.removeFeedback(),t.closest(".thread-item").hasClass("selected")?bp.Nouveau.Messages.router.navigate("view/"+t.closest(".thread-content").data("thread-id")+"/",{trigger:!0}):(this.setActiveThread(t.closest(".thread-content").data("thread-id")),s(".message-action-view").focus())}}),bp.Views.userThread=bp.Nouveau.Messages.View.extend({tagName:"li",template:bp.template("bp-messages-thread"),className:"thread-item",events:{"click .message-check":"singleSelect"},initialize:function(){if(this.model.get("active")&&(this.el.className+=" selected"),this.model.get("unread")&&(this.el.className+=" unread"),"sentbox"===bp.Nouveau.Messages.box){var e=this.model.get("recipients").length,s="";2===e?s=BP_Nouveau.messages.toOthers.one:2<e&&(s=BP_Nouveau.messages.toOthers.more.replace("%d",Number(e-1))),this.model.set({recipientsCount:e,toOthers:s},{silent:!0})}else this.model.get("recipientsCount")&&this.model.unset("recipientsCount",{silent:!0});this.model.on("change:active",this.toggleClass,this),this.model.on("change:unread",this.updateReadState,this),this.model.on("change:checked",this.bulkSelect,this),this.model.on("remove",this.cleanView,this)},toggleClass:function(e){!0===e.get("active")?s(this.el).addClass("selected"):s(this.el).removeClass("selected")},updateReadState:function(e,t){!1===t?s(this.el).removeClass("unread"):s(this.el).addClass("unread")},bulkSelect:function(e){s("#bp-message-thread-"+e.get("id")).length&&s("#bp-message-thread-"+e.get("id")).prop("checked",e.get("checked"))},singleSelect:function(e){var t=s(e.currentTarget).prop("checked");this.model.set("checked",t,{silent:!0});var a=!1;_.each(this.model.collection.models,function(e){!0===e.get("checked")&&(a=!0)}),a?(s("#user-messages-bulk-actions").closest(".bulk-actions-wrap").removeClass("bp-hide"),bp.Nouveau.Messages.displayFeedback(BP_Nouveau.messages.howtoBulk,"info")):(s("#user-messages-bulk-actions").closest(".bulk-actions-wrap").addClass("bp-hide"),bp.Nouveau.Messages.removeFeedback())},cleanView:function(){this.views.view.remove()}}),bp.Views.previewThread=bp.Nouveau.Messages.View.extend({tagName:"div",id:"thread-preview",template:bp.template("bp-messages-preview"),events:{"click .actions button":"doAction","click .actions a":"doAction"},initialize:function(){this.collection.on("change:active",this.setPreview,this),this.collection.on("change:is_starred",this.updatePreview,this),this.collection.on("reset",this.emptyPreview,this),this.collection.on("remove",this.emptyPreview,this)},render:function(){_.isUndefined(this.model)||!0!==this.model.get("active")||bp.Nouveau.Messages.View.prototype.render.apply(this,arguments)},setPreview:function(e){var s=this;this.model=e,!0===e.get("unread")&&this.model.updateReadState().done(function(){s.model.set("unread",!1)}),this.render()},updatePreview:function(e){!0===e.get("active")&&this.render()},emptyPreview:function(){s(this.el).html("")},doAction:function(e){var t,a=s(e.currentTarget).data("bp-action"),i=this,n={},o=BP_Nouveau.messages.doingAction;if(!a)return e;e.preventDefault();var d=this.collection.findWhere({active:!0});d.get("id")&&(t=d.get("id"),"view"!==a?("star"!==a&&"unstar"!==a||(n.data={star_nonce:d.get("star_nonce")},t=d.get("starred_id")),_.isUndefined(o[a])||bp.Nouveau.Messages.displayFeedback(o[a],"loading"),this.collection.doAction(a,t,n).done(function(e){bp.Nouveau.Messages.removeFeedback(),bp.Nouveau.Messages.displayFeedback(e.feedback,e.type),"delete"===a||"starred"===i.collection.options.box&&"unstar"===a?(i.collection.remove(d.get("id")),i.collection.fetch({data:_.pick(i.collection.options,["box","search_terms","page"])})):"unstar"===a||"star"===a?(_.each(e.messages,function(e){d.set(e)}),d.set(_.first(e.messages))):e.messages&&d.set(_.first(e.messages))}).fail(function(e){bp.Nouveau.Messages.removeFeedback(),bp.Nouveau.Messages.displayFeedback(e.feedback,e.type)})):bp.Nouveau.Messages.router.navigate("view/"+t+"/",{trigger:!0}))}}),bp.Views.Pagination=bp.Nouveau.Messages.View.extend({tagName:"li",className:"last filter",template:bp.template("bp-messages-paginate")}),bp.Views.BulkActions=bp.Nouveau.Messages.View.extend({tagName:"div",template:bp.template("bp-bulk-actions"),events:{"click #user_messages_select_all":"bulkSelect","click .bulk-apply":"doBulkAction"},bulkSelect:function(e){var t=s(e.currentTarget).prop("checked");t?(s(this.el).find(".bulk-actions-wrap").removeClass("bp-hide").addClass("bp-show"),bp.Nouveau.Messages.displayFeedback(BP_Nouveau.messages.howtoBulk,"info")):(s(this.el).find(".bulk-actions-wrap").addClass("bp-hide"),bp.Nouveau.Messages.removeFeedback()),_.each(this.collection.models,function(e){e.set("checked",t)})},doBulkAction:function(e){var t,a=this,i={},n="id",o=BP_Nouveau.messages.doingAction;e.preventDefault();var d=s("#user-messages-bulk-actions").val();if(d){var r=this.collection.where({checked:!0}),c=_.map(r,function(e){return e.get("id")});t=c,"star"!==d&&"unstar"!==d||(1===(t=_.map(r,function(e){return e.get("starred_id")})).length&&(i.data={star_nonce:r[0].get("star_nonce")}),n="starred_id");var l=_.object(_.map(r,function(e){return[e.get(n),e.get("id")]}));_.isUndefined(o[d])||bp.Nouveau.Messages.displayFeedback(o[d],"loading"),this.collection.doAction(d,t,i).done(function(e){bp.Nouveau.Messages.removeFeedback(),bp.Nouveau.Messages.displayFeedback(e.feedback,e.type),"delete"===d||"starred"===a.collection.options.box&&"unstar"===d?(a.collection.remove(c),a.collection.fetch({data:_.pick(a.collection.options,["box","search_terms","page"])})):e.messages&&_.each(e.messages,function(e,s){a.collection.get(l[s]).set(e)})}).fail(function(e){bp.Nouveau.Messages.removeFeedback(),bp.Nouveau.Messages.displayFeedback(e.feedback,e.type)})}}}),bp.Views.messageFilters=bp.Nouveau.Messages.View.extend({tagName:"ul",template:bp.template("bp-messages-filters"),events:{"search #user_messages_search":"resetSearchTerms","submit #user_messages_search_form":"setSearchTerms","click #bp-messages-next-page":"nextPage","click #bp-messages-prev-page":"prevPage"},initialize:function(){this.model.on("change",this.filterThreads,this),this.options.threads.on("sync",this.addPaginatation,this)},addPaginatation:function(e){_.each(this.views._views,function(e){_.isUndefined(e)||_.first(e).remove()}),this.views.add(new bp.Views.Pagination({model:new Backbone.Model(e.options)})),this.views.add(".user-messages-bulk-actions",new bp.Views.BulkActions({model:new Backbone.Model(BP_Nouveau.messages.bulk_actions),collection:e}))},filterThreads:function(){bp.Nouveau.Messages.displayFeedback(BP_Nouveau.messages.loading,"loading"),this.options.threads.reset(),_.extend(this.options.threads.options,_.pick(this.model.attributes,["box","search_terms"])),this.options.threads.fetch({data:_.pick(this.model.attributes,["box","search_terms","page"]),success:this.threadsFiltered,error:this.threadsFilterError})},threadsFiltered:function(){bp.Nouveau.Messages.removeFeedback()},threadsFilterError:function(e,s){bp.Nouveau.Messages.displayFeedback(s.feedback,s.type)},resetSearchTerms:function(e){e.preventDefault(),s(e.target).val()?s(e.target).closest("form").find("[type=submit]").addClass("bp-show").removeClass("bp-hide"):s(e.target).closest("form").submit()},setSearchTerms:function(e){e.preventDefault(),this.model.set({search_terms:s(e.target).find("input[type=search]").val()||"",page:1})},nextPage:function(e){e.preventDefault(),this.model.set("page",this.model.get("page")+1)},prevPage:function(e){e.preventDefault(),this.model.set("page",this.model.get("page")-1)}}),bp.Views.userMessagesHeader=bp.Nouveau.Messages.View.extend({tagName:"div",template:bp.template("bp-messages-single-header"),events:{"click .actions a":"doAction","click .actions button":"doAction"},doAction:function(e){var t=s(e.currentTarget).data("bp-action"),a=this,i={},n=BP_Nouveau.messages.doingAction;if(!t)return e;if(e.preventDefault(),this.model.get("id")){if("star"===t||"unstar"===t){var o={star:"unstar",unstar:"star"};i.data={star_nonce:this.model.get("star_nonce")},s(e.currentTarget).addClass("bp-hide"),s(e.currentTarget).parent().find('[data-bp-action="'+o[t]+'"]').removeClass("bp-hide")}_.isUndefined(n[t])||bp.Nouveau.Messages.displayFeedback(n[t],"loading"),bp.Nouveau.Messages.threads.doAction(t,this.model.get("id"),i).done(function(e){"delete"===t?bp.Nouveau.Messages.clearViews():e.messages&&a.model.set(_.first(e.messages)),bp.Nouveau.Messages.removeFeedback(),bp.Nouveau.Messages.displayFeedback(e.feedback,e.type)}).fail(function(e){bp.Nouveau.Messages.removeFeedback(),bp.Nouveau.Messages.displayFeedback(e.feedback,e.type)})}}}),bp.Views.userMessagesEntry=bp.Views.userMessagesHeader.extend({tagName:"li",template:bp.template("bp-messages-single-list"),events:{"click [data-bp-action]":"doAction"},initialize:function(){this.model.on("change:is_starred",this.updateMessage,this)},updateMessage:function(e){this.model.get("id")===e.get("id")&&this.render()}}),bp.Views.userMessages=bp.Nouveau.Messages.View.extend({tagName:"div",template:bp.template("bp-messages-single"),initialize:function(){this.requestMessages(),this.reply=new bp.Models.messageThread,this.collection.on("add",this.addMessage,this),this.views.add("#bp-message-content",new bp.Views.messageEditor)},events:{"click #send_reply_button":"sendReply"},requestMessages:function(){var e={};this.collection.reset(),bp.Nouveau.Messages.displayFeedback(BP_Nouveau.messages.loading,"loading"),_.isUndefined(this.options.thread.attributes)?e.id=this.options.thread.id:(e.id=this.options.thread.get("id"),e.js_thread=!_.isEmpty(this.options.thread.get("subject"))),this.collection.fetch({data:e,success:_.bind(this.messagesFetched,this),error:this.messagesFetchError})},messagesFetched:function(e,s){_.isUndefined(s.thread)||(this.options.thread=new Backbone.Model(s.thread)),bp.Nouveau.Messages.removeFeedback(),this.views.add("#bp-message-thread-header",new bp.Views.userMessagesHeader({model:this.options.thread}))},messagesFetchError:function(e,s){s.feedback&&s.type&&bp.Nouveau.Messages.displayFeedback(s.feedback,s.type)},addMessage:function(e){this.views.add("#bp-message-thread-list",new bp.Views.userMessagesEntry({model:e}))},addEditor:function(){this.views.add("#bp-message-content",new bp.Views.messageEditor)},sendReply:function(e){e.preventDefault(),!0!==this.reply.get("sending")&&(this.reply.set({thread_id:this.options.thread.get("id"),content:tinyMCE.activeEditor.getContent(),sending:!0}),this.collection.sync("create",_.pick(this.reply.attributes,["thread_id","content"]),{success:_.bind(this.replySent,this),error:_.bind(this.replyError,this)}))},replySent:function(e){var s=this.collection.parse(e);tinyMCE.activeEditor.setContent(""),this.reply.set("sending",!1),this.collection.add(_.first(s))},replyError:function(e){e.feedback&&e.type&&bp.Nouveau.Messages.displayFeedback(e.feedback,e.type)}}),bp.Nouveau.Messages.Router=Backbone.Router.extend({routes:{"compose/":"composeMessage","view/:id/":"viewMessage","sentbox/":"sentboxView","starred/":"starredView","inbox/":"inboxView","":"inboxView"},composeMessage:function(){bp.Nouveau.Messages.composeView()},viewMessage:function(e){if(e){var s=bp.Nouveau.Messages.threads.get(e);void 0===s&&((s={}).id=e),bp.Nouveau.Messages.singleView(s)}},sentboxView:function(){bp.Nouveau.Messages.box="sentbox",bp.Nouveau.Messages.threadsView()},starredView:function(){bp.Nouveau.Messages.box="starred",bp.Nouveau.Messages.threadsView()},inboxView:function(){bp.Nouveau.Messages.box="inbox",bp.Nouveau.Messages.threadsView()}}),bp.Nouveau.Messages.start())}(bp,jQuery);