templates: Simplify nested Handlebars conditionals using {{else if}}.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-06-29 15:14:58 -07:00
committed by Tim Abbott
parent 2e2cd3eb49
commit 706d96b22e
13 changed files with 41 additions and 65 deletions

View File

@@ -963,8 +963,8 @@ test("initialize", ({override, override_rewire, mock_template}) => {
fake_this = {completing: "mention", token: "othello"};
actual_value = options.highlighter.call(fake_this, othello);
expected_value =
` <span class="user_circle_empty user_circle"></span>\n` +
` <img class="typeahead-image" src="http://zulip.zulipdev.com/avatar/${othello.user_id}?s&#x3D;50" />\n` +
` <span class="user_circle_empty user_circle"></span>\n` +
` <img class="typeahead-image" src="http://zulip.zulipdev.com/avatar/${othello.user_id}?s&#x3D;50" />\n` +
`<strong>Othello, the Moor of Venice</strong>&nbsp;&nbsp;\n` +
`<small class="autocomplete_secondary">othello@zulip.com</small>\n`;
assert.equal(actual_value, expected_value);
@@ -972,7 +972,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
fake_this = {completing: "mention", token: "hamletcharacters"};
actual_value = options.highlighter.call(fake_this, hamletcharacters);
expected_value =
' <i class="typeahead-image icon fa fa-group no-presence-circle" aria-hidden="true"></i>\n<strong>hamletcharacters</strong>&nbsp;&nbsp;\n<small class="autocomplete_secondary">Characters of Hamlet</small>\n';
' <i class="typeahead-image icon fa fa-group no-presence-circle" aria-hidden="true"></i>\n<strong>hamletcharacters</strong>&nbsp;&nbsp;\n<small class="autocomplete_secondary">Characters of Hamlet</small>\n';
assert.equal(actual_value, expected_value);
// matching

View File

@@ -2,14 +2,12 @@
<div class="message_edit_notice auto-select" title="{{#tr}}Edited ({last_edit_timestr}){{/tr}}">
{{t "SAVING" }}
</div>
{{else if moved}}
<div class="message_edit_notice auto-select" title="{{#tr}}Moved ({last_edit_timestr}){{/tr}}">
{{t "MOVED" }}
</div>
{{else}}
{{#if moved}}
<div class="message_edit_notice auto-select" title="{{#tr}}Moved ({last_edit_timestr}){{/tr}}">
{{t "MOVED" }}
</div>
{{else}}
<div class="message_edit_notice auto-select" title="{{#tr}}Edited ({last_edit_timestr}){{/tr}}">
{{t "EDITED" }}
</div>
{{/if}}
<div class="message_edit_notice auto-select" title="{{#tr}}Edited ({last_edit_timestr}){{/tr}}">
{{t "EDITED" }}
</div>
{{/if}}

View File

@@ -1,5 +1,5 @@
{{#with emoji_dict}}
<div class="emoji-popover-emoji {{#if ../message_id }}{{#if has_reacted}} reacted {{/if}} reaction {{else}} {{#if ../is_status_emoji_popover}} status_emoji {{else}} composition {{/if}} {{/if}}" data-emoji-name="{{name}}" tabindex="0" data-emoji-id="{{../type}},{{../section}},{{../index}}">
<div class="emoji-popover-emoji {{#if ../message_id }}{{#if has_reacted}} reacted {{/if}} reaction {{else if ../is_status_emoji_popover}} status_emoji {{else}} composition {{/if}}" data-emoji-name="{{name}}" tabindex="0" data-emoji-id="{{../type}},{{../section}},{{../index}}">
{{#if is_realm_emoji}}
<img src="{{url}}" class="emoji"/>
{{else}}

View File

@@ -1,12 +1,10 @@
<div class="{{this.class}}" aria-label="{{this.label}}" data-reaction-id="{{this.local_id}}">
{{#if this.emoji_alt_code}}
<div class="emoji_alt_code">&nbsp:{{this.emoji_name}}:</div>
{{else}}
{{#if this.is_realm_emoji}}
{{else if this.is_realm_emoji}}
<img src="{{this.url}}" class="emoji" />
{{else}}
{{else}}
<div class="emoji emoji-{{this.emoji_code}}"></div>
{{/if}}
{{/if}}
<div class="message_reaction_count">{{this.count}}</div>
</div>

View File

@@ -51,10 +51,8 @@
{{! edit topic pencil icon }}
{{#if always_visible_topic_edit}}
<i class="fa fa-pencil always_visible_topic_edit recipient_bar_icon hidden-for-spectators" {{#unless realm_allow_message_editing}}style="display: none"{{/unless}} data-tippy-content="{{t 'Edit topic'}}" role="button" tabindex="0" aria-label="{{t 'Edit topic' }}"></i>
{{else}}
{{#if on_hover_topic_edit}}
{{else if on_hover_topic_edit}}
<i class="fa fa-pencil on_hover_topic_edit recipient_bar_icon hidden-for-spectators" {{#unless realm_allow_message_editing}}style="display: none"{{/unless}} data-tippy-content="{{t 'Edit topic'}}" role="button" tabindex="0" aria-label="{{t 'Edit topic' }}"></i>
{{/if}}
{{/if}}
{{#if user_can_resolve_topic}}

View File

@@ -12,12 +12,10 @@
<button type="button" class="button no-style user-status-value">
{{#if emoji.emoji_alt_code}}
<div class="emoji_alt_code">&nbsp:{{emoji.emoji_name}}:</div>
{{else}}
{{#if emoji.url}}
{{else if emoji.url}}
<img src="{{emoji.url}}" class="emoji status_emoji" />
{{else}}
{{else}}
<div class="emoji status_emoji emoji-{{emoji.emoji_code}}"></div>
{{/if}}
{{/if}}
{{status_text}}
</button>

View File

@@ -1,13 +1,11 @@
{{#if is_guest}}
<div class='tip'>{{t "Guests cannot edit custom emoji." }}</div>
{{else}}
{{#if (eq realm_add_custom_emoji_policy policy_values.by_admins_only.code) }}
{{else if (eq realm_add_custom_emoji_policy policy_values.by_admins_only.code) }}
<div class='tip'>{{t "Only organization administrators can add custom emoji in this organization." }}</div>
{{else if (eq realm_add_custom_emoji_policy policy_values.by_moderators_only.code)}}
{{else if (eq realm_add_custom_emoji_policy policy_values.by_moderators_only.code)}}
<div class='tip'>{{t 'Only organization administrators and moderators can add custom emoji in this organization.'}}</div>
{{else if (eq realm_add_custom_emoji_policy policy_values.by_full_members.code)}}
{{else if (eq realm_add_custom_emoji_policy policy_values.by_full_members.code)}}
<div class='tip'>{{t 'Only organization full members can add custom emoji in this organization.'}}</div>
{{else}}
{{else}}
<div class='tip'>{{t "Any member of this organization can add custom emoji." }}</div>
{{/if}}
{{/if}}

View File

@@ -88,10 +88,8 @@
<div class="text">{{t "Custom emoji" }}</div>
{{#if is_guest}}
<i class="locked fa fa-lock" title="{{t 'Guest users cannot edit custom emoji.' }}"></i>
{{else}}
{{#if show_emoji_settings_lock}}
{{else if show_emoji_settings_lock}}
<i class="locked fa fa-lock" title="{{t 'Only organization administrators can edit these settings.'}}"></i>
{{/if}}
{{/if}}
</li>
{{#unless is_guest}}

View File

@@ -1,12 +1,10 @@
{{#if selected_emoji}}
{{#if selected_emoji.emoji_alt_code}}
<div class="emoji_alt_code">&nbsp:{{selected_emoji.emoji_name}}:</div>
{{else}}
{{#if selected_emoji.url}}
{{else if selected_emoji.url}}
<img src="{{selected_emoji.url}}" class="emoji selected_emoji" />
{{else}}
{{else}}
<div class="emoji selected_emoji emoji-{{selected_emoji.emoji_code}}"></div>
{{/if}}
{{/if}}
{{else}}
<a type="button" class="smiley_icon show fa fa-smile-o"></a>

View File

@@ -1,8 +1,8 @@
{{!-- If setting is disabled on realm level, then render setting as control-label-disabled and do not set setting value. Setting status should not change on any click handler, as it is disabled at realm level. --}}
<div id="sub_{{setting_name}}_setting"
class="sub_setting_checkbox
{{#if disabled_realm_setting}}control-label-disabled{{else}}
{{#if notification_setting}}sub_notification_setting {{#if is_muted}}muted-sub{{/if}}{{/if}}{{/if}} new-style">
{{#if disabled_realm_setting}}control-label-disabled
{{else if notification_setting}}sub_notification_setting {{#if is_muted}}muted-sub{{/if}}{{/if}} new-style">
<label class="checkbox">
<input id="{{setting_name}}_{{stream_id}}" name="{{setting_name}}"
class="sub_setting_control" type="checkbox"

View File

@@ -5,21 +5,17 @@
<span class='emoji emoji-{{ emoji_code }}'></span>
{{/if}}
&nbsp;&nbsp;
{{else}}
{{#if is_person}}
{{#if user_circle_class}}
<span class="{{user_circle_class}} user_circle"></span>
{{/if}}
{{#if has_image}}
<img class="typeahead-image" src="{{ img_src }}" />
{{else}}
<span class='typeahead-image fa fa-bullhorn no-presence-circle'></span>
{{/if}}
{{else}}
{{#if is_user_group}}
<i class="typeahead-image icon fa fa-group no-presence-circle" aria-hidden="true"></i>
{{/if}}
{{else if is_person}}
{{#if user_circle_class}}
<span class="{{user_circle_class}} user_circle"></span>
{{/if}}
{{#if has_image}}
<img class="typeahead-image" src="{{ img_src }}" />
{{else}}
<span class='typeahead-image fa fa-bullhorn no-presence-circle'></span>
{{/if}}
{{else if is_user_group}}
<i class="typeahead-image icon fa fa-group no-presence-circle" aria-hidden="true"></i>
{{/if}}
<strong>
{{~ primary ~}}

View File

@@ -35,12 +35,10 @@
{{bot_owner.full_name}}
</span>
</li>
{{else}}
{{#if is_system_bot}}
{{else if is_system_bot}}
<li>{{#tr}}System bot{{/tr}}</li>
{{else}}
{{else}}
<li>{{#tr}}Bot{{/tr}}</li>
{{/if}}
{{/if}}
{{else}}
<li>{{ user_type }}</li>
@@ -88,12 +86,10 @@
{{#if status_emoji_info}}
{{#if status_emoji_info.emoji_alt_code}}
<div class="emoji_alt_code">&nbsp:{{status_emoji_info.emoji_name}}:</div>
{{else}}
{{#if status_emoji_info.url}}
{{else if status_emoji_info.url}}
<img src="{{status_emoji_info.url}}" class="emoji status_emoji" />
{{else}}
{{else}}
<div class="emoji status_emoji emoji-{{status_emoji_info.emoji_code}}"></div>
{{/if}}
{{/if}}
{{/if}}
{{status_text}}

View File

@@ -56,12 +56,10 @@
<a href="{{this.value}}" target="_blank" rel="noopener noreferrer" class="value">{{this.value}}</a>
{{else if this.is_external_account}}
<a href="{{this.link}}" target="_blank" rel="noopener noreferrer" class="value">{{this.value}}</a>
{{else}}
{{#if this.rendered_value}}
{{else if this.rendered_value}}
<div class="value rendered_markdown">{{rendered_markdown this.rendered_value}}</div>
{{else}}
{{else}}
<div class="value">{{this.value}}</div>
{{/if}}
{{/if}}
</div>
{{/each}}