diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index 42048fd74f..be1f729d6d 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -1062,6 +1062,64 @@ function test_with_mock_socket(test_params) { preventDefault: noop, }; + (function test_stream_name_completed_triggered() { + var handler = $(document).get_on_handler('streamname_completed.zulip'); + + var data = { + stream: { + name: 'Denmark', + }, + }; + + function test_noop_case(invite_only) { + compose_state.set_message_type('stream'); + data.stream.invite_only = invite_only; + handler({}, data); + assert.equal($('#compose_private_stream_alert').visible(), false); + } + + test_noop_case(false); + + $("#compose_private").hide(); + compose_state.set_message_type('stream'); + + var checks = [ + (function () { + var called; + templates.render = function (template_name, context) { + called = true; + assert.equal(template_name, 'compose_private_stream_alert'); + assert.equal(context.invite_only, true); + assert.equal(context.stream_name, 'Denmark'); + return 'fake-compose_private_stream_alert-template'; + }; + return function () { assert(called); }; + }()), + + (function () { + var called; + $("#compose_private_stream_alert").append = function (html) { + called = true; + assert.equal(html, 'fake-compose_private_stream_alert-template'); + }; + return function () { assert(called); }; + }()), + ]; + + data = { + stream: { + invite_only: true, + name: 'Denmark', + }, + }; + + handler({}, data); + assert.equal($('#compose_private_stream_alert').visible(), true); + + _.each(checks, function (f) { f(); }); + + }()); + (function test_attach_files_compose_clicked() { var handler = $("#compose") .get_on_handler("click", "#attach_files"); diff --git a/frontend_tests/node_tests/templates.js b/frontend_tests/node_tests/templates.js index c1fc10adb8..d8b286285e 100644 --- a/frontend_tests/node_tests/templates.js +++ b/frontend_tests/node_tests/templates.js @@ -518,6 +518,15 @@ function render(template_name, args) { assert.equal(a.text(), "Narrow to here"); }()); +(function compose_private_stream_alert() { + var args = { + name: 'Demark', + invite_only: true, + }; + var html = render('compose_private_stream_alert', args); + global.write_handlebars_output("compose_stream_alert", html); +}()); + (function dev_env_email_access() { var html = render('dev_env_email_access'); global.write_handlebars_output("dev_env_email_access", html); diff --git a/static/js/compose.js b/static/js/compose.js index 13800a64fc..9fb305c45f 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -68,6 +68,11 @@ exports.clear_invites = function () { $("#compose_invite_users").empty(); }; +exports.clear_private_stream_alert = function () { + $("#compose_private_stream_alert").hide(); + $("#compose_private_stream_alert").empty(); +}; + exports.reset_user_acknowledged_all_everyone_flag = function () { user_acknowledged_all_everyone = undefined; }; @@ -307,6 +312,7 @@ exports.enter_with_preview_open = function () { exports.finish = function () { exports.clear_invites(); + exports.clear_private_stream_alert(); if (! compose.validate()) { return false; @@ -632,6 +638,39 @@ exports.initialize = function () { } }); + // Show a warning if a private stream is linked + $(document).on('streamname_completed.zulip', function (event, data) { + if (compose_state.get_message_type() !== 'stream') { + return; + } + + if (data !== undefined && data.stream !== undefined) { + var invite_only = data.stream.invite_only; + var stream_name = data.stream.name; + + if (invite_only) { + var warning_area = $("#compose_private_stream_alert"); + var context = { stream_name: stream_name, invite_only: invite_only }; + var new_row = templates.render("compose_private_stream_alert", context); + + warning_area.append(new_row); + warning_area.show(); + } + } + + }); + + $("#compose_private_stream_alert").on('click', '.compose_private_stream_alert_close', function (event) { + var stream_alert_row = $(event.target).parents('.compose_private_stream_alert'); + var stream_alert = $("#compose_private_stream_alert"); + + stream_alert_row.remove(); + + if (stream_alert.children().length === 0) { + stream_alert.hide(); + } + }); + // Click event binding for "Attach files" button // Triggers a click on a hidden file input field diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index df6485af3c..1a1670f680 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -92,6 +92,7 @@ function clear_box() { // TODO: Better encapsulate at-mention warnings. compose.clear_all_everyone_warnings(); + compose.clear_private_stream_alert(); compose.reset_user_acknowledged_all_everyone_flag(); exports.clear_textarea(); diff --git a/static/styles/compose.css b/static/styles/compose.css index 558ea23e76..b8d015cf76 100644 --- a/static/styles/compose.css +++ b/static/styles/compose.css @@ -192,16 +192,19 @@ table.compose_table { top: 5px; } -#compose_invite_users { +#compose_invite_users, +#compose_private_stream_alert { /* Don't overlap into the compose_close × */ margin-right: 10px; } -.compose_invite_user { +.compose_invite_user, +.compose_private_stream_alert { padding: 4px 0px 4px 0px; } -.compose_invite_close { +.compose_invite_close, +.compose_private_stream_alert_close { display: inline; margin-top: 4px; @@ -209,7 +212,8 @@ table.compose_table { } .compose-all-everyone-controls, -.compose_invite_user_controls { +.compose_invite_user_controls, +.compose_private_stream_alert_controls { float: right; -webkit-transform: translateY(-13%); -ms-transform: translateY(-13%); diff --git a/static/templates/compose_private_stream_alert.handlebars b/static/templates/compose_private_stream_alert.handlebars new file mode 100644 index 0000000000..bb2c0a8377 --- /dev/null +++ b/static/templates/compose_private_stream_alert.handlebars @@ -0,0 +1,6 @@ +