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();
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();
},
});
});
}
(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);
});
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();
loading.destroy_indicator($('#admin_page_default_streams_loading_indicator'));
}());
self.remove = function (stream_id) {
if (self.row_dict.has(stream_id)) {

View File

@ -1,19 +1,28 @@
<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="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>
<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">
<tbody id="admin_default_streams_table" class="admin_default_stream_table">
<thead>
<th>{{t "Name" }}</th>
{{#if is_admin}}
<th class="actions">{{t "Actions" }}</th>
{{/if}}
</tbody>
</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}}