Change admin default streams list to render progressively.

This commit is contained in:
Brock Whittaker 2017-04-20 12:49:12 -07:00 committed by Tim Abbott
parent 6c3606cf36
commit 0e4f2f732d
3 changed files with 74 additions and 59 deletions

View File

@ -415,6 +415,28 @@ $(function () {
window.location.hash = "streams/all";
});
$("body").on("click", ".default_stream_row .remove-default-stream", function () {
var row = $(this).closest(".default_stream_row");
var stream_name = row.attr("id");
channel.del({
url: "/json/default_streams" + "?" + $.param({ stream_name: stream_name }),
error: function (xhr) {
var button = row.find("button");
if (xhr.status.toString().charAt(0) === "4") {
button.closest("td").html(
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
);
} else {
button.text(i18n.t("Failed!"));
}
},
success: function () {
row.remove();
},
});
});
// FEEDBACK
// Keep these 2 feedback bot triggers separate because they have to

View File

@ -31,40 +31,24 @@ exports.build_default_stream_table = function (streams_data) {
self.row_dict = new Dict();
function set_up_remove_click_hander(row, stream_name) {
row.on("click", ".remove-default-stream", function (e) {
e.preventDefault();
e.stopPropagation();
var table = $("#admin_default_streams_table").expectOne();
channel.del({
url: '/json/default_streams'+ '?' + $.param({stream_name: stream_name}),
error: function (xhr) {
var button = row.find("button");
if (xhr.status.toString().charAt(0) === "4") {
button.closest("td").html(
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg)
);
} else {
button.text(i18n.t("Failed!"));
}
},
success: function () {
row.remove();
},
});
});
}
list_render(table, streams_data, {
name: "default_streams_list",
modifier: function (item) {
var row = $(templates.render("admin_default_streams_list", { stream: item, can_modify: page_params.is_admin }));
self.row_dict.set(item.stream_id, row);
return row;
},
filter: {
element: table.closest(".settings-section").find(".search"),
callback: function (item, value) {
return item.name.toLowerCase().match(value);
},
},
}).init();
(function () {
var table = $("#admin_default_streams_table").expectOne();
_.each(streams_data, function (stream) {
var row = $(templates.render("admin_default_streams_list", {stream: stream, can_modify: page_params.is_admin}));
set_up_remove_click_hander(row, stream.name);
self.row_dict.set(stream.stream_id, row);
table.append(row);
});
loading.destroy_indicator($('#admin_page_default_streams_loading_indicator'));
}());
loading.destroy_indicator($('#admin_page_default_streams_loading_indicator'));
self.remove = function (stream_id) {
if (self.row_dict.has(stream_id)) {

View File

@ -1,30 +1,39 @@
<div id="admin-default-streams-list" class="settings-section" data-name="default-streams-list">
<div class="settings-section-title"><i class="icon-vector-exchange settings-section-icon"></i>
{{t "Default streams"}}</div>
<div class="side-padded-container">
<p>{{#tr this}}Configure the default streams new users are subscribed to when joining your organization.{{/tr}}</p>
</div>
<table class="table table-condensed table-striped">
<tbody id="admin_default_streams_table" class="admin_default_stream_table">
<th>{{t "Name" }}</th>
{{#if is_admin}}
<th class="actions">{{t "Actions" }}</th>
{{/if}}
</tbody>
</table>
<div id="admin_page_default_streams_loading_indicator"></div>
{{#if is_admin}}
<form class="form-horizontal default-stream-form">
<div class="add-new-default-stream-box grey-bg">
<div class="new-default-stream-section-title">{{t "Add new default stream" }}</div>
<div class="control-group" id="default_stream_inputs">
<label for="default_stream_name" class="control-label">{{t "Stream name" }}</label>
<input class="create_default_stream" type="text" placeholder="{{t "Stream name" }}" name="stream_name" autocomplete="off"></input>
</div>
<div class="settings-section-title">
<div class="table-title">
<i class="icon-vector-exchange settings-section-icon"></i>
{{t "Default streams" }}
</div>
<input type="text" class="search" placeholder="{{t 'Search streams' }}" />
<div class="clear-float"></div>
</div>
</form>
{{/if}}
<div class="side-padded-container">
<p>{{#tr this}}Configure the default streams new users are subscribed to when joining your organization.{{/tr}}</p>
</div>
<div class="progressive-table-wrapper">
<table class="table table-condensed table-striped">
<thead>
<th>{{t "Name" }}</th>
{{#if is_admin}}
<th class="actions">{{t "Actions" }}</th>
{{/if}}
</thead>
<tbody id="admin_default_streams_table" class="admin_default_stream_table"></tbody>
</table>
</div>
<div id="admin_page_default_streams_loading_indicator"></div>
{{#if is_admin}}
<form class="form-horizontal default-stream-form">
<div class="add-new-default-stream-box grey-bg">
<div class="new-default-stream-section-title">{{t "Add new default stream" }}</div>
<div class="control-group" id="default_stream_inputs">
<label for="default_stream_name" class="control-label">{{t "Stream name" }}</label>
<input class="create_default_stream" type="text" placeholder="{{t "Stream name" }}" name="stream_name" autocomplete="off"></input>
</div>
</div>
</form>
{{/if}}
</div>