Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

streams: Eliminate content-editable to change stream info.

m-e-l-u-h-a-n9cb8e1b286bf
diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js
index ccd593e98ca..1c3d9f9c45c 100644
--- a/frontend_tests/node_tests/hotkey.js
+++ b/frontend_tests/node_tests/hotkey.js
@@ -255,10 +255,6 @@ run_test("allow normal typing when processing text", ({override}) => {
assert_unmapped("bfmoyz");
assert_unmapped("BEFHILNOQTUWXYZ");
- // We have to skip some checks due to the way the code is
- // currently organized for mapped keys.
- override(hotkey, "in_content_editable_widget", () => false);
-
// All letters should return false if we are composing text.
override(hotkey, "processing_text", () => true);
@@ -478,11 +474,6 @@ run_test("motion_keys", () => {
assert_mapping("right_arrow", lightbox, "next");
overlays.lightbox_open = () => false;
- hotkey.__Rewire__("in_content_editable_widget", () => true);
- assert_unmapped("down_arrow");
- assert_unmapped("up_arrow");
- hotkey.__Rewire__("in_content_editable_widget", () => false);
-
overlays.settings_open = () => true;
assert_unmapped("end");
assert_unmapped("home");
diff --git a/frontend_tests/puppeteer_tests/subscriptions.ts b/frontend_tests/puppeteer_tests/subscriptions.ts
index 5dd0909a247..590c27c3587 100644
--- a/frontend_tests/puppeteer_tests/subscriptions.ts
+++ b/frontend_tests/puppeteer_tests/subscriptions.ts
@@ -174,11 +174,11 @@ async function create_stream(page: Page): Promise<void> {
await page.waitForFunction(() => $(".stream-name").is(':contains("Puppeteer")'));
const stream_name = await common.get_text_from_selector(
page,
- ".stream-header .stream-name .stream-name-editable",
+ ".stream-header .stream-name .sub-stream-name",
);
const stream_description = await common.get_text_from_selector(
page,
- ".stream-description-editable ",
+ ".stream-description .sub-stream-description",
);
const subscriber_count_selector = "[data-stream-name='Puppeteer'] .subscriber-count";
assert.strictEqual(stream_name, "Puppeteer");
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index b6cfb80c621..8cc1a194e37 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -34,7 +34,6 @@ import * as rows from "./rows";
import * as server_events from "./server_events";
import * as settings_panel_menu from "./settings_panel_menu";
import * as settings_toggle from "./settings_toggle";
-import * as stream_edit from "./stream_edit";
import * as stream_list from "./stream_list";
import * as stream_popover from "./stream_popover";
import * as topic_list from "./topic_list";
@@ -712,84 +711,6 @@ export function initialize() {
// Don't focus links on context menu.
$("body").on("contextmenu", "a", (e) => e.target.blur());
- {
- const map = {
- ".stream-description-editable": {
- on_start: stream_edit.set_raw_description,
- on_save: stream_edit.change_stream_description,
- },
- ".stream-name-editable": {
- on_start: null,
- on_save: stream_edit.change_stream_name,
- },
- };
-
- $(document).on("keydown", ".editable-section", function (e) {
- e.stopPropagation();
- // Cancel editing description if Escape key is pressed.
- if (e.key === "Escape") {
- $("[data-finish-editing='.stream-description-editable']").hide();
- $(this).attr("contenteditable", false);
- $(this).text($(this).attr("data-prev-text"));
- $("[data-make-editable]").html("");
- } else if (e.key === "Enter") {
- $(this).siblings(".checkmark").trigger("click");
- }
- });
-
- $(document).on("drop", ".editable-section", () => false);
-
- $(document).on("input", ".editable-section", function () {
- // if there are any child nodes, inclusive of <br> which means you
- // have lines in your description or title, you're doing something
- // wrong.
- for (let x = 0; x < this.childNodes.length; x += 1) {
- if (this.childNodes[x].nodeType !== 3) {
- this.textContent = this.textContent.replace(/\n/, "");
- break;
- }
- }
- });
-
- $("body").on("click", "[data-make-editable]", function () {
- const selector = $(this).attr("data-make-editable");
- const edit_area = $(this).parent().find(`${selector}`);
- $(selector).removeClass("stream-name-edit-box");
- if (edit_area.attr("contenteditable") === "true") {
- $(`[data-finish-editing='${CSS.escape(selector)}']`).hide();
- edit_area.attr("contenteditable", false);
- edit_area.text(edit_area.attr("data-prev-text"));
- $(this).html("");
- } else {
- $(`[data-finish-editing='${CSS.escape(selector)}']`).show();
-
- $(selector).addClass("stream-name-edit-box");
- edit_area
- .attr("data-prev-text", edit_area.text().trim())
- .attr("contenteditable", true);
-
- if (map[selector].on_start) {
- map[selector].on_start(this, edit_area);
- }
-
- ui_util.place_caret_at_end(edit_area[0]);
-
- $(this).html("&times;");
- }
- });
-
- $("body").on("click", "[data-finish-editing]", function (e) {
- const selector = $(this).attr("data-finish-editing");
- $(selector).removeClass("stream-name-edit-box");
- if (map[selector].on_save) {
- map[selector].on_save(e);
- $(this).hide();
- $(this).parent().find(`${selector}`).attr("contenteditable", false);
- $(`[data-make-editable='${CSS.escape(selector)}']`).html("");
- }
- });
- }
-
// HOTSPOTS
// open
diff --git a/static/js/hotkey.js b/static/js/hotkey.js
index 8275ed8044e..13a54dbd4e1 100644
--- a/static/js/hotkey.js
+++ b/static/js/hotkey.js
@@ -211,7 +211,6 @@ export function processing_text() {
$focused_elt.is("input") ||
$focused_elt.is("select") ||
$focused_elt.is("textarea") ||
- $focused_elt.hasClass("editable-section") ||
$focused_elt.parents(".pill-container").length >= 1 ||
$focused_elt.attr("id") === "compose-send-button"
);
@@ -234,10 +233,6 @@ export function process_escape_key(e) {
return true;
}
- if (in_content_editable_widget(e)) {
- return false;
- }
-
if (feedback_widget.is_open()) {
feedback_widget.dismiss();
return true;
@@ -400,11 +395,6 @@ export function process_enter_key(e) {
return emoji_picker.navigate("enter", e);
}
- if (in_content_editable_widget(e)) {
- $(e.target).parent().find(".checkmark").trigger("click");
- return false;
- }
-
if (handle_popover_events("enter")) {
return true;
}
@@ -630,12 +620,6 @@ export function process_hotkey(e, hotkey) {
return subs.switch_rows(event_name);
}
- if (in_content_editable_widget(e)) {
- // We handle the Enter key in process_enter_key().
- // We ignore all other keys.
- return false;
- }
-
if (event_name === "up_arrow" && list_util.inside_list(e)) {
list_util.go_up(e);
return true;
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index b358eea8af3..e9a074542a8 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -1,5 +1,6 @@
import $ from "jquery";
+import render_change_stream_info_modal from "../templates/change_stream_info_modal.hbs";
import render_settings_deactivation_stream_modal from "../templates/confirm_dialog/confirm_deactivate_stream.hbs";
import render_unsubscribe_private_stream_modal from "../templates/confirm_dialog/confirm_unsubscribe_private_stream.hbs";
import render_stream_member_list_entry from "../templates/stream_member_list_entry.hbs";
@@ -153,7 +154,7 @@ function set_stream_message_retention_setting_dropdown(stream) {
}
function get_stream_id(target) {
- const row = $(target).closest(".stream-row, .subscription_settings");
+ const row = $(target).closest(".stream-row, .subscription_settings, .save-button");
return Number.parseInt(row.attr("data-stream-id"), 10);
}
@@ -209,14 +210,14 @@ function get_subscriber_list(sub_row) {
export function update_stream_name(sub, new_name) {
const sub_settings = settings_for_sub(sub);
sub_settings.find(".email-address").text(sub.email_address);
- sub_settings.find(".stream-name-editable").text(new_name);
+ sub_settings.find(".sub-stream-name").text(new_name);
}
export function update_stream_description(sub) {
const stream_settings = settings_for_sub(sub);
stream_settings.find("input.description").val(sub.description);
stream_settings
- .find(".stream-description-editable")
+ .find(".sub-stream-description")
.html(util.clean_user_content_links(sub.rendered_description));
}
@@ -529,6 +530,7 @@ export function show_settings_for(node) {
const sub_settings = settings_for_sub(sub);
$(".nothing-selected").hide();
+ $("#subscription_overlay .stream_change_property_info").hide();
sub_settings.addClass("show");
@@ -687,96 +689,6 @@ function change_stream_privacy(e) {
});
}
-export function change_stream_name(e) {
- e.preventDefault();
- const sub_settings = $(e.target).closest(".subscription_settings");
- const stream_id = get_stream_id(e.target);
- const new_name_box = sub_settings.find(".stream-name-editable");
- const new_name = new_name_box.text().trim();
- const old_name = stream_data.maybe_get_stream_name(stream_id);
-
- $(".stream_change_property_info").hide();
-
- if (old_name === new_name) {
- return;
- }
-
- channel.patch({
- url: "/json/streams/" + stream_id,
- data: {new_name},
- success() {
- new_name_box.val("");
- ui_report.success(
- $t_html({defaultMessage: "The stream has been renamed!"}),
- $(".stream_change_property_info"),
- );
- },
- error(xhr) {
- new_name_box.text(old_name);
- ui_report.error(
- $t_html({defaultMessage: "Error"}),
- xhr,
- $(".stream_change_property_info"),
- );
- },
- });
-}
-
-export function set_raw_description(target, destination) {
- const sub = get_sub_for_target(target);
- if (!sub) {
- blueslip.error("set_raw_description() fails");
- return;
- }
- destination.text(sub.description);
-}
-
-export function change_stream_description(e) {
- e.preventDefault();
-
- const sub_settings = $(e.target).closest(".subscription_settings");
- const sub = get_sub_for_target(e.target);
- if (!sub) {
- blueslip.error("change_stream_description() fails");
- return;
- }
-
- const stream_id = sub.stream_id;
- const description = sub_settings.find(".stream-description-editable").text().trim();
- $(".stream_change_property_info").hide();
-
- if (description === sub.description) {
- sub_settings
- .find(".stream-description-editable")
- .html(util.clean_user_content_links(sub.rendered_description));
- return;
- }
-
- channel.patch({
- url: "/json/streams/" + stream_id,
- data: {
- description,
- },
- success() {
- // The event from the server will update the rest of the UI
- ui_report.success(
- $t_html({defaultMessage: "The stream description has been updated!"}),
- $(".stream_change_property_info"),
- );
- },
- error(xhr) {
- sub_settings
- .find(".stream-description-editable")
- .html(util.clean_user_content_links(sub.rendered_description));
- ui_report.error(
- $t_html({defaultMessage: "Error"}),
- xhr,
- $(".stream_change_property_info"),
- );
- },
- });
-}
-
export function archive_stream(stream_id, alert_element, stream_row) {
channel.del({
url: "/json/streams/" + stream_id,
@@ -835,12 +747,66 @@ export function initialize() {
$("#subscriptions_table").on("click", "#change-stream-privacy-button", change_stream_privacy);
- $("#subscriptions_table").on("click", ".close-modal-btn", (e) => {
- // This fixes a weird bug in which, subscription_settings hides
- // unexpectedly by clicking the cancel button in a modal on top of it.
+ $("#subscriptions_table").on("click", "#open_stream_info_modal", (e) => {
+ e.preventDefault();
e.stopPropagation();
+ const stream_id = get_stream_id(e.target);
+ const stream = sub_store.get(stream_id);
+ const template_data = {
+ stream_id,
+ stream_name: stream.name,
+ stream_description: stream.description,
+ };
+ const change_stream_info_modal = render_change_stream_info_modal(template_data);
+ $("#change_stream_info_modal").remove();
+ $("#subscriptions_table").append(change_stream_info_modal);
+ overlays.open_modal("#change_stream_info_modal");
});
+ $("#subscriptions_table").on("keypress", "#change_stream_description", (e) => {
+ // Stream descriptions can not be multiline, so disable enter key
+ // to prevent new line
+ if (e.key === "Enter") {
+ return false;
+ }
+ return true;
+ });
+
+ $("#subscriptions_table").on("click", "#save_stream_info", (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ const sub = get_sub_for_target(e.currentTarget);
+
+ const url = `/json/streams/${sub.stream_id}`;
+ const data = {};
+ const new_name = $("#change_stream_name").val().trim();
+ const new_description = $("#change_stream_description").val().trim();
+
+ if (new_name === sub.name && new_description === sub.description) {
+ return;
+ }
+ if (new_name !== sub.name) {
+ data.new_name = new_name;
+ }
+ if (new_description !== sub.description) {
+ data.description = new_description;
+ }
+
+ const status_element = $(".stream_change_property_info");
+ overlays.close_modal("#change_stream_info_modal");
+ settings_ui.do_settings_change(channel.patch, url, data, status_element);
+ });
+
+ $("#subscriptions_table").on(
+ "click",
+ ".close-modal-btn, .close-change-stream-info-modal",
+ (e) => {
+ // This fixes a weird bug in which, subscription_settings hides
+ // unexpectedly by clicking the cancel button in a modal on top of it.
+ e.stopPropagation();
+ },
+ );
+
$("#subscriptions_table").on(
"change",
"#sub_is_muted_setting .sub_setting_control",
diff --git a/static/styles/subscriptions.css b/static/styles/subscriptions.css
index 9d25c70abc8..dbcd56d5e65 100644
--- a/static/styles/subscriptions.css
+++ b/static/styles/subscriptions.css
@@ -759,9 +759,7 @@
}
}
-#subscription_overlay
- .stream-description
- .stream-description-editable:empty::after,
+#subscription_overlay .stream-description .sub-stream-description:empty::after,
.stream-row .sub-info-box .description:empty::after {
content: attr(data-no-description);
font-style: italic;
@@ -829,21 +827,17 @@
font-size: 1.5em;
font-weight: 600;
margin-left: -3px;
+ margin-top: -5px;
white-space: nowrap;
max-width: 260px;
- .stream-name-editable {
+ .sub-stream-name {
display: block;
max-width: 20ch;
overflow: hidden;
text-overflow: ellipsis;
float: left;
}
-
- .stream-name-edit-box {
- text-overflow: clip;
- border-style: groove;
- }
}
.button-group {
@@ -852,8 +846,9 @@
.subscribe-button,
#preview-stream-button,
+ #open_stream_info_modal,
.deactivate {
- margin-right: 5px;
+ margin-right: 3px;
text-decoration: none;
}
}
@@ -871,59 +866,25 @@
display: inline-block;
vertical-align: top;
margin-right: 5px;
+ margin-top: -5px;
font-size: 1.5em;
&.hash::after {
top: 1px;
}
}
- }
-
- .stream-description {
- margin-bottom: 5px;
- }
-
- .editable-section {
- position: relative;
- display: inline;
- min-width: 10px;
- max-width: 100%;
- &[contenteditable="true"] {
- display: inline-block;
- color: hsl(170, 48%, 54%);
-
- &:focus {
- outline: none;
- }
+ .stream_change_property_info {
+ vertical-align: top;
+ margin: -5px 0 0 0;
}
}
- .editable {
- position: relative;
- top: -1px;
- margin-left: 5px;
- color: hsl(0, 0%, 67%);
- cursor: pointer;
- font-size: 1.4rem;
- font-weight: 300;
-
- transition: all 0.3s ease;
-
- &:empty::before {
- content: "\f040";
- font-family: FontAwesome;
- font-size: 0.8rem;
- font-weight: normal;
- }
-
- &:not(:empty) {
- position: relative;
- top: 3px;
- }
-
- &:hover {
- color: hsl(0, 0%, 27%);
+ .stream-description {
+ margin-bottom: 5px;
+ .no-description {
+ font-style: italic;
+ color: hsl(0, 0%, 67%);
}
}
@@ -983,11 +944,6 @@
margin-bottom: 5px;
}
- .alert-notification:not(:empty) {
- vertical-align: unset;
- margin-top: 10px;
- }
-
.loading_indicator_text {
font-weight: 400;
line-height: 20px;
@@ -1055,6 +1011,18 @@
}
}
}
+#change_stream_info_modal {
+ .modal-header h3 {
+ text-overflow: ellipsis;
+ overflow: hidden;
+ }
+
+ #change_stream_description {
+ width: 80%;
+ max-width: 500px;
+ box-sizing: border-box;
+ }
+}
@media (width < $lg_min) {
.subscriptions-container {
@@ -1154,6 +1122,21 @@
float: unset;
margin-top: 10px;
}
+
+ #subscription_overlay .subscription_settings .stream_change_property_info {
+ /* For small widths where there is not enough space
+ to show alert beside stream name we set its display
+ to block so it is shown in new line. But to avoid
+ it covering whole screen width we set max-width
+ so that it does not losses inline-block appearence. */
+
+ /* TODO: This will probably be not required once
+ we have tabbed navigation as button group width
+ will be smaller. */
+ display: block;
+ max-width: max-content;
+ white-space: nowrap;
+ }
}
#stream-creation #invites-warning-modal .modal-footer {
diff --git a/static/templates/change_stream_info_modal.hbs b/static/templates/change_stream_info_modal.hbs
new file mode 100644
index 00000000000..6bd964cca81
--- /dev/null
+++ b/static/templates/change_stream_info_modal.hbs
@@ -0,0 +1,34 @@
+<div id="change_stream_info_modal" class="modal modal-bg hide fade new-style" tabindex="-1"
+ role="dialog" aria-labelledby="change_stream_info_label" aria-hidden="true">
+ <div class="modal-header">
+ <button type="button" class="close close-change-stream-info-modal" data-dismiss="modal" aria-label="{{t 'Close' }}">
+ <span aria-hidden="true">&times;</span>
+ </button>
+ <h3 id="change_stream_info_label">
+ {{#tr}}Edit #{stream_name}{{/tr}}
+ <span class="email"></span>
+ </h3>
+ </div>
+ <div class="modal-body">
+ <div class="input-group">
+ <label for="change_stream_name">
+ {{t 'Change stream name' }}
+ </label>
+ <input type="text" id="change_stream_name" value="{{ stream_name }}" />
+ </div>
+ <div class="input-group">
+ <label for="change_stream_description">
+ {{t 'Change stream description' }}
+ </label>
+ <textarea id="change_stream_description" maxlength="1000">{{ stream_description }}</textarea>
+ </div>
+ </div>
+
+ <div class="modal-footer">
+ <button class=" button rounded close-change-stream-info-modal" data-dismiss="modal">{{t "Cancel" }}</button>
+ <button class="button rounded btn-danger save-button" id="save_stream_info"
+ tabindex="-1" data-stream-id="{{stream_id}}">
+ {{t "Save changes"}}
+ </button>
+ </div>
+</div>
diff --git a/static/templates/subscription_settings.hbs b/static/templates/subscription_settings.hbs
index 04c6cfad289..c01d68ec254 100644
--- a/static/templates/subscription_settings.hbs
+++ b/static/templates/subscription_settings.hbs
@@ -1,6 +1,5 @@
<div class="subscription_settings" data-stream-id="{{sub.stream_id}}">
<div class="inner-box">
- <div class="alert stream_change_property_info"></div>
{{#with sub}}
<div class="stream-header">
@@ -8,13 +7,13 @@
invite_only=invite_only
is_web_public=is_web_public }}
<div class="stream-name">
- <span title="{{name}}" class="stream-name-editable editable-section" >{{name}}</span>
- {{#if can_change_name_description}}
- <span class="editable" data-make-editable=".stream-name-editable"></span>
- <span class="checkmark" data-finish-editing=".stream-name-editable">✓</span>
- {{/if}}
+ <span class="sub-stream-name" title="{{name}}">{{name}}</span>
</div>
+ <div class="stream_change_property_info alert-notification"></div>
<div class="button-group">
+ <button id="open_stream_info_modal" class="button rounded small btn-warning" title="{{t 'Change stream info' }}">
+ <i class="fa fa-pencil" aria-hidden="true"></i>
+ </button>
<div class="sub_unsub_button_wrapper inline-block">
<button class="button small rounded subscribe-button sub_unsub_button {{#unless subscribed }}unsubscribed{{/unless}}" type="button" name="button" {{#if should_display_subscription_button}}title="{{t 'Toggle subscription'}} (S)" {{else}}disabled="disabled"{{/if}}>
{{#if subscribed }}{{t "Unsubscribe"}}{{else}}{{t "Subscribe"}}{{/if}}</button>
@@ -28,11 +27,9 @@
</div>
</div>
<div class="stream-description">
- <span class="stream-description-editable editable-section description rendered_markdown" data-no-description="{{t 'No description.' }}">{{rendered_markdown rendered_description}}</span>
- {{#if can_change_name_description}}
- <span class="editable" data-make-editable=".stream-description-editable"></span>
- <span class="checkmark" data-finish-editing=".stream-description-editable">✓</span>
- {{/if}}
+ <span class="sub-stream-description rendered_markdown" data-no-description="{{t 'No description.' }}">
+ {{rendered_markdown rendered_description}}
+ </span>
</div>
<div class="subscription-type">
<div class="subscription-type-text">