zulip/web/templates/settings/edit_bot_form.hbs

66 lines
3.4 KiB
Handlebars
Raw Normal View History

<div id="bot-edit-form" data-user-id="{{user_id}}" data-email="{{email}}">
<form class="new-style edit_bot_form name-setting">
<div class="alert" id="bot-edit-form-error"></div>
<div class="input-group name_change_container">
<label for="edit_bot_full_name" class="modal-field-label">{{t "Name" }}</label>
<input type="text" autocomplete="off" name="full_name" id="edit_bot_full_name" class="modal_text_input" value="{{ full_name }}" />
</div>
<input type="hidden" name="is_full_name" value="true" />
<div class="input-group email_change_container">
<label for="email" class="modal-field-label">{{t "Email" }}</label>
<input type="text" autocomplete="off" name="email" class="modal_text_input" value="{{ email }}" readonly/>
</div>
<div class="input-group user_id_container">
<label for="user_id" class="modal-field-label">{{t "User ID" }}</label>
<input type="text" autocomplete="off" name="user_id" class="modal_text_input" value="{{ user_id }}" readonly/>
</div>
<div class="input-group">
<label for="bot-role-select" class="modal-field-label">{{t 'Role' }}
{{> ../help_link_widget link="/help/roles-and-permissions" }}
</label>
<select name="bot-role-select" id="bot-role-select" class="modal_select bootstrap-focus-style" data-setting-widget-type="number" {{#if disable_role_dropdown}}disabled{{/if}}>
{{> dropdown_options_widget option_values=user_role_values}}
</select>
</div>
{{> ../dropdown_widget_with_label
widget_name="edit_bot_owner"
label=(t 'Owner')}}
<div id="service_data">
</div>
<div class="input-group edit-avatar-section">
<label class="modal-field-label">{{t "Avatar" }}</label>
{{!-- Shows the current avatar --}}
<img src="{{bot_avatar_url}}" id="current_bot_avatar_image" />
<input type="file" name="bot_avatar_file_input" class="notvisible edit_bot_avatar_file_input" value="{{t 'Upload profile picture' }}" />
<div class="edit_bot_avatar_file"></div>
<div class="edit_bot_avatar_preview_text">
<img class="edit_bot_avatar_preview_image" />
</div>
<button type="button" class="button white rounded edit_bot_avatar_upload_button">{{t "Change avatar" }}</button>
<button type="button" class="button white rounded edit_bot_avatar_clear_button" style="display: none;">{{t "Clear profile picture" }}</button>
<div><label for="edit_bot_avatar_file" generated="true" class="edit_bot_avatar_error text-error"></label></div>
</div>
</form>
{{#if is_incoming_webhook_bot}}
<div class="input-group new-style">
<button class="button rounded generate_url_for_integration">
{{t 'Generate URL for an integration' }}
</button>
</div>
{{/if}}
<div class="input-group new-style">
{{#if is_active}}
<button class="button rounded btn-danger deactivate_bot_button">
{{t 'Deactivate bot' }}
</button>
{{else}}
<span>
<button class="button rounded reactivate_user_button">
{{t 'Reactivate bot' }}
</button>
</span>
{{/if}}
</div>
user settings: Separate code for bot form. When editing a bot, there are only two fields that are similar to humans--full name and email--which are trivial. Before this commit we used a single codepath to build the human form and the bot form. Now we have two simple codepaths. The tricky nature of the code had already led to ugly things for the bot codepath that fortunately weren't user facing, but which were distracting: - For bots we would needlessly set things like is_admin, is_guest in the template data. - For bots we would needlessly try to update custom profile fields. The code that differs between bots and humans is nontrivial, and the code was both hard to read and hard to improve: - Humans don't have bot owners. - Bots don't have custom profile fields. The bot-owner code is nontrivial for performance reasons. In a big realm there are tens of thousands of potential bot owners. We avoid the most egregious performance problems (i.e we don't have multiple copies of the dropdown), but we may still want to refine that (at least adding a spinner). The custom-profile-fields code is nontrivial due to the dynamic nature of custom profile fields, which can bring in specialized widgets like pill fields. Now each form corresponds to a single endpoint: * human -> /json/users * bot -> /json/bots Before we had a lot of conditional logic in the template, the code to build to views, and the code to submit the data. Now everything is much flatter. The human code is still a bit messy (more work coming on that), but the bot code is fairly pristine. All three components of the bot code fit on a page, and there are no conditionals: - admin_bot_form.hbs - open_bot_form - handle_bot_form We may want to grow out the bot code a bit to allow admins to do more things, such as adding services, and this will be easier now. It would also be easier for us now to share widgets with the per-user bot settings. Note that the form for editing human data will continue to be invoked from two panels: - Users - Deactivated users There are some minor differences between users and deactivated users, but the shape of the data is the same for both, so that's still all one codepath. We eliminate `reset_edit_user` here, since it was never used. One nice thing about these forms was that they had very little custom CSS attached to them (at form-level specificity), and it turned out all the custom CSS was for the human-specific form.
2020-05-09 12:13:03 +02:00
</div>