All files / mobile.editor.overlay BlockMessageDetails.js

33.33% Statements 6/18
0% Branches 0/2
0% Functions 0/9
33.33% Lines 6/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122  1x 1x 1x 1x           1x                                                                                                                                                                                                                           1x  
'use strict';
var Button = require( '../mobile.startup/Button' ),
	View = require( '../mobile.startup/View' ),
	Icon = require( '../mobile.startup/Icon' ),
	okButton = new Button( {
		label: mw.msg( 'ok' ),
		tagName: 'button',
		progressive: true,
		additionalClassNames: 'cancel'
	} ),
	util = require( '../mobile.startup/util' );
 
/**
 * @extends View
 */
class BlockMessageDetails extends View {
	/** @inheritdoc */
	get isTemplateMode() {
		return true;
	}
	/**
	 * @inheritdoc
	 */
	get defaults() {
		return {
			createDetailsAnchorHref: function () {
				return function ( blockId, render ) {
					return mw.util.getUrl( 'Special:BlockList', { wpTarget: '#' + render( blockId ) } );
				};
			},
			createDetailsAnchorLabel: function () {
				return mw.msg( 'mobile-frontend-editor-blocked-drawer-help' );
			},
			createTitle: function () {
				return this.partial ? mw.msg( 'mobile-frontend-editor-blocked-drawer-title-partial' ) : mw.msg( 'mobile-frontend-editor-blocked-drawer-title' );
			},
			reasonHeader: mw.msg( 'mobile-frontend-editor-blocked-drawer-reason-header' ),
			creatorHeader: function () {
				// The gender is the subject (the blockee) not the object (the blocker).
				return mw.msg( 'mobile-frontend-editor-blocked-drawer-creator-header',
					mw.user.options.get( 'gender' ) );
			},
			expiryHeader: mw.msg( 'mobile-frontend-editor-blocked-drawer-expiry-header' )
		};
	}
	/**
	 * @inheritdoc
	 */
	postRender() {
		const userIcon = new Icon( {
			tagName: 'span',
			name: 'userAvatar',
			hasText: true,
			label: this.options.creator.name
		} );
 
		this.$el.find( '.block-message-creator a' ).prepend(
			userIcon.$el
		);
		this.$el.find( '.block-message-buttons' ).prepend(
			okButton.$el
		);
		this.$el.find( '.block-message-icon' ).prepend(
			( new Icon( {
				name: 'stopHand-destructive',
				additionalClassNames: 'mw-ui-icon-flush-top'
			} ) ).$el
		);
	}
	/**
	 * @inheritdoc
	 */
	get template() {
		return util.template( `
<div class="block-message">
  <div class="block-message-icon"></div>
  <div class="block-message-info">
    <div class="block-message-item block-message-title">
      <h5>{{ createTitle }}</h5>
    </div>
    <div class="block-message-data">
      {{#reason}}
        <div class="block-message-item">
          <h6>{{ reasonHeader }}</h6>
          <div><strong>{{{ reason }}}</strong></div>
        </div>
      {{/reason}}
      <div class="block-message-item block-message-creator">
        {{#creator.name}}
          <h6>{{ creatorHeader }}</h6>
          <div>
            <strong>
              {{#creator.url}}
                <a href="{{ creator.url }}"></a>
              {{/creator.url}}
              {{^creator.url}}
                {{ creator.name }}
              {{/creator.url}}
            </strong>
          </div>
        {{/creator.name}}
      </div>
      {{#expiry}}
        <div class="block-message-item">
          <h6>{{ expiryHeader }}</h6>
          <div><strong>{{#duration}}{{ duration }}{{/duration}} {{ expiry }}</strong></div>
        </div>
      {{/expiry}}
    </div>
    <div class="block-message-item block-message-buttons">
      {{#blockId}}
        <a href="{{#createDetailsAnchorHref}}{{ blockId }}{{/createDetailsAnchorHref}}">
          {{ createDetailsAnchorLabel }}
        </a>
      {{/blockId}}
    </div>
  </div>` );
	}
}
 
module.exports = BlockMessageDetails;