mirror of
https://github.com/flarum/framework.git
synced 2025-01-12 06:24:00 +08:00
cde8a2e87a
Includes transpiled JS/TS. [skip ci]
2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
(()=>{var t={n:a=>{var o=a&&a.__esModule?()=>a.default:()=>a;return t.d(o,{a:o}),o},d:(a,o)=>{for(var s in o)t.o(o,s)&&!t.o(a,s)&&Object.defineProperty(a,s,{enumerable:!0,get:o[s]})},o:(t,a)=>Object.prototype.hasOwnProperty.call(t,a),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},a={};(()=>{"use strict";function o(){return o=Object.assign||function(t){for(var a=1;a<arguments.length;a++){var o=arguments[a];for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(t[s]=o[s])}return t},o.apply(this,arguments)}t.r(a);const s=flarum.core.compat.app;var e=t.n(s);const r=flarum.core.compat.Model;var n=t.n(r);function l(t,a){t.prototype=Object.create(a.prototype),t.prototype.constructor=t,t.__proto__=a}var i=function(t){function a(){return t.apply(this,arguments)||this}return l(a,t),a}(n());o(i.prototype,{type:n().attribute("type"),reason:n().attribute("reason"),reasonDetail:n().attribute("reasonDetail"),createdAt:n().attribute("createdAt",n().transformDate),post:n().hasOne("post"),user:n().hasOne("user")});const c=i,p=flarum.core.compat["components/Page"];var u=t.n(p);const f=flarum.core.compat.Component;var g=t.n(f);const d=flarum.core.compat["components/Link"];var h=t.n(d);const v=flarum.core.compat["components/LoadingIndicator"];var _=t.n(v);const y=flarum.core.compat["helpers/avatar"];var b=t.n(y);const N=flarum.core.compat["helpers/username"];var F=t.n(N);const x=flarum.core.compat["helpers/icon"];var k=t.n(x);const w=flarum.core.compat["helpers/humanTime"];var C=t.n(w),D=function(t){function a(){return t.apply(this,arguments)||this}l(a,t);var o=a.prototype;return o.oninit=function(a){t.prototype.oninit.call(this,a),this.state=this.attrs.state},o.view=function(){var t=this.state.cache||[];return m("div",{className:"NotificationList FlagList"},m("div",{className:"NotificationList-header"},m("h4",{className:"App-titleControl App-titleControl--text"},app.translator.trans("flarum-flags.forum.flagged_posts.title"))),m("div",{className:"NotificationList-content"},m("ul",{className:"NotificationGroup-content"},t.length?t.map((function(t){var a=t.post();return m("li",null,m(h(),{href:app.route.post(a),className:"Notification Flag",onclick:function(t){app.flags.index=a,t.redraw=!1}},b()(a.user()),k()("fas fa-flag",{className:"Notification-icon"}),m("span",{className:"Notification-content"},app.translator.trans("flarum-flags.forum.flagged_posts.item_text",{username:F()(a.user()),em:m("em",null),discussion:a.discussion().title()})),C()(t.createdAt()),m("div",{className:"Notification-excerpt"},a.contentPlain())))})):this.state.loading?_().component({className:"LoadingIndicator--block"}):m("div",{className:"NotificationList-empty"},app.translator.trans("flarum-flags.forum.flagged_posts.empty_text")))))},a}(g()),P=function(t){function a(){return t.apply(this,arguments)||this}l(a,t);var o=a.prototype;return o.oninit=function(a){t.prototype.oninit.call(this,a),app.history.push("flags"),app.flags.load(),this.bodyClass="App--flags"},o.view=function(){return m("div",{className:"FlagsPage"},m(D,{state:app.flags}))},a}(u()),A=function(){function t(t){this.app=t,this.loading=!1}return t.prototype.load=function(){var t=this;this.cache&&!this.app.session.user.attribute("newFlagCount")||(this.loading=!0,m.redraw(),this.app.store.find("flags").then((function(a){t.app.session.user.pushAttributes({newFlagCount:0}),t.cache=a.sort((function(t,a){return a.createdAt()-t.createdAt()}))})).catch((function(){})).then((function(){t.loading=!1,m.redraw()})))},t}();const M=flarum.core.compat.extend,O=flarum.core.compat["utils/PostControls"];var L=t.n(O);const B=flarum.core.compat["components/Button"];var T=t.n(B);const j=flarum.core.compat["components/Modal"];var S=t.n(j);const E=flarum.core.compat["utils/Stream"];var I=t.n(E);const H=flarum.core.compat["utils/withAttr"];var R=t.n(H),U=function(t){function a(){return t.apply(this,arguments)||this}l(a,t);var o=a.prototype;return o.oninit=function(a){t.prototype.oninit.call(this,a),this.success=!1,this.reason=I()(""),this.reasonDetail=I()("")},o.className=function(){return"FlagPostModal Modal--medium"},o.title=function(){return app.translator.trans("flarum-flags.forum.flag_post.title")},o.content=function(){if(this.success)return m("div",{className:"Modal-body"},m("div",{className:"Form Form--centered"},m("p",{className:"helpText"},app.translator.trans("flarum-flags.forum.flag_post.confirmation_message")),m("div",{className:"Form-group"},m(T(),{className:"Button Button--primary Button--block",onclick:this.hide.bind(this)},app.translator.trans("flarum-flags.forum.flag_post.dismiss_button")))));var t=app.forum.attribute("guidelinesUrl");return m("div",{className:"Modal-body"},m("div",{className:"Form Form--centered"},m("div",{className:"Form-group"},m("div",null,m("label",{className:"checkbox"},m("input",{type:"radio",name:"reason",checked:"off_topic"===this.reason(),value:"off_topic",onclick:R()("value",this.reason)}),m("strong",null,app.translator.trans("flarum-flags.forum.flag_post.reason_off_topic_label")),app.translator.trans("flarum-flags.forum.flag_post.reason_off_topic_text"),"off_topic"===this.reason()?m("textarea",{className:"FormControl",placeholder:app.translator.trans("flarum-flags.forum.flag_post.reason_details_placeholder"),value:this.reasonDetail(),oninput:R()("value",this.reasonDetail)}):""),m("label",{className:"checkbox"},m("input",{type:"radio",name:"reason",checked:"inappropriate"===this.reason(),value:"inappropriate",onclick:R()("value",this.reason)}),m("strong",null,app.translator.trans("flarum-flags.forum.flag_post.reason_inappropriate_label")),app.translator.trans("flarum-flags.forum.flag_post.reason_inappropriate_text",{a:t?m("a",{href:t,target:"_blank"}):void 0}),"inappropriate"===this.reason()?m("textarea",{className:"FormControl",placeholder:app.translator.trans("flarum-flags.forum.flag_post.reason_details_placeholder"),value:this.reasonDetail(),oninput:R()("value",this.reasonDetail)}):""),m("label",{className:"checkbox"},m("input",{type:"radio",name:"reason",checked:"spam"===this.reason(),value:"spam",onclick:R()("value",this.reason)}),m("strong",null,app.translator.trans("flarum-flags.forum.flag_post.reason_spam_label")),app.translator.trans("flarum-flags.forum.flag_post.reason_spam_text"),"spam"===this.reason()?m("textarea",{className:"FormControl",placeholder:app.translator.trans("flarum-flags.forum.flag_post.reason_details_placeholder"),value:this.reasonDetail(),oninput:R()("value",this.reasonDetail)}):""),m("label",{className:"checkbox"},m("input",{type:"radio",name:"reason",checked:"other"===this.reason(),value:"other",onclick:R()("value",this.reason)}),m("strong",null,app.translator.trans("flarum-flags.forum.flag_post.reason_other_label")),"other"===this.reason()?m("textarea",{className:"FormControl",value:this.reasonDetail(),oninput:R()("value",this.reasonDetail)}):""))),m("div",{className:"Form-group"},m(T(),{className:"Button Button--primary Button--block",type:"submit",loading:this.loading,disabled:!this.reason()},app.translator.trans("flarum-flags.forum.flag_post.submit_button")))))},o.onsubmit=function(t){var a=this;t.preventDefault(),this.loading=!0,app.store.createRecord("flags").save({reason:"other"===this.reason()?null:this.reason(),reasonDetail:this.reasonDetail(),relationships:{user:app.session.user,post:this.attrs.post}},{errorHandler:this.onerror.bind(this)}).then((function(){return a.success=!0})).catch((function(){})).then(this.loaded.bind(this))},a}(S());function G(){(0,M.extend)(L(),"userControls",(function(t,a){!a.isHidden()&&"comment"===a.contentType()&&a.canFlag()&&t.add("flag",m(T(),{icon:"fas fa-flag",onclick:function(){return e().modal.show(U,{post:a})}},e().translator.trans("flarum-flags.forum.post_controls.flag_button")))}))}const q=flarum.core.compat["components/HeaderSecondary"];var z=t.n(q);const V=flarum.core.compat["components/NotificationsDropdown"];var J=function(t){function a(){return t.apply(this,arguments)||this}l(a,t),a.initAttrs=function(a){a.label=a.label||app.translator.trans("flarum-flags.forum.flagged_posts.tooltip"),a.icon=a.icon||"fas fa-flag",t.initAttrs.call(this,a)};var o=a.prototype;return o.getMenu=function(){return m("div",{className:"Dropdown-menu "+this.attrs.menuClassName,onclick:this.menuClick.bind(this)},this.showing?D.component({state:this.attrs.state}):"")},o.goToRoute=function(){m.route.set(app.route("flags"))},o.getUnreadCount=function(){return app.flags.cache?app.flags.cache.length:app.forum.attribute("flagCount")},o.getNewCount=function(){return app.session.user.attribute("newFlagCount")},a}(t.n(V)());function K(){(0,M.extend)(z().prototype,"items",(function(t){e().forum.attribute("canViewFlags")&&t.add("flags",m(J,{state:e().flags}),15)}))}const Q=flarum.core.compat["components/Post"];var W=t.n(Q);const X=flarum.core.compat["utils/ItemList"];var Y=t.n(X);const Z=flarum.core.compat["utils/humanTime"];var $=t.n(Z);function tt(){(0,M.extend)(W().prototype,"elementAttrs",(function(t){this.attrs.post.flags().length&&(t.className+=" Post--flagged")})),W().prototype.dismissFlag=function(t){var a=this.attrs.post;return delete a.data.relationships.flags,this.subtree.invalidate(),e().flags.cache&&e().flags.cache.some((function(t,o){if(t.post()===a){if(e().flags.cache.splice(o,1),e().flags.index===a){var s=e().flags.cache[o];if(s||(s=e().flags.cache[0]),s){var r=s.post();e().flags.index=r,m.route.set(e().route.post(r))}}return!0}})),e().request({url:e().forum.attribute("apiUrl")+a.apiEndpoint()+"/flags",method:"DELETE",body:t})},W().prototype.flagActionItems=function(){var t=this,a=new(Y()),o=L().destructiveControls(this.attrs.post);return Object.keys(o.items).forEach((function(a){var s=o.get(a).attrs;s.className="Button",(0,M.extend)(s,"onclick",(function(){return t.dismissFlag()}))})),a.add("controls",m("div",{className:"ButtonGroup"},o.toArray())),a.add("dismiss",m(T(),{className:"Button",icon:"far fa-eye-slash",onclick:this.dismissFlag.bind(this)},e().translator.trans("flarum-flags.forum.post.dismiss_flag_button")),-100),a},(0,M.extend)(W().prototype,"content",(function(t){var a=this,o=this.attrs.post,s=o.flags();s.length&&(o.isHidden()&&(this.revealContent=!0),t.unshift(m("div",{className:"Post-flagged"},m("div",{className:"Post-flagged-flags"},s.map((function(t){return m("div",{className:"Post-flagged-flag"},a.flagReason(t))}))),m("div",{className:"Post-flagged-actions"},this.flagActionItems().toArray()))))})),W().prototype.flagReason=function(t){if("user"===t.type()){var a=t.user(),o=t.reason(),s=t.reasonDetail(),r=$()(t.createdAt());return[e().translator.trans(o?"flarum-flags.forum.post.flagged_by_with_reason_text":"flarum-flags.forum.post.flagged_by_text",{time:r,user:a,reason:o}),s?m("span",{className:"Post-flagged-detail"},s):""]}}}const at={"flags/addFlagsToPosts":tt,"flags/addFlagControl":G,"flags/addFlagsDropdown":K,"flags/models/Flag":c,"flags/components/FlagList":D,"flags/components/FlagPostModal":U,"flags/components/FlagsPage":P,"flags/components/FlagsDropdown":J},ot=flarum.core;e().initializers.add("flarum-flags",(function(){e().store.models.posts.prototype.flags=n().hasMany("flags"),e().store.models.posts.prototype.canFlag=n().attribute("canFlag"),e().store.models.flags=c,e().routes.flags={path:"/flags",component:P},e().flags=new A(e()),G(),K(),tt()})),o(ot.compat,at)})(),module.exports=a})();
|
|
//# sourceMappingURL=forum.js.map
|