list_render: Clean up initialization.

For some widgets we now avoid duplicate redraw
events from this old pattern:

    widget = list_render.create(..., {
    }).init();
    widget.sort(...);

The above code was wasteful and possibly
flicker-y due to the fact that `init` and
`sort` both render.

Now we do this:

    widget = list_render.create(..., {
        init_sort: [...],
    });

For other widgets we just clean up the need
to call `init()` right after `create()`.

We also allow widgets to pass in `sort_fields`
during initialization (since you may want to
have `init_sort` use a custom sort before the
first render.)
This commit is contained in:
Steve Howell
2020-04-11 14:23:29 +00:00
committed by Tim Abbott
parent ef749dba31
commit 0681e4ba36
12 changed files with 84 additions and 100 deletions

View File

@@ -184,7 +184,7 @@ function populate_users(realm_people_data) {
};
const $bots_table = $("#admin_bots_table");
const bot_list = list_render.create($bots_table, bots, {
list_render.create($bots_table, bots, {
name: "admin_bot_list",
modifier: function (item) {
return render_admin_user_list({
@@ -203,11 +203,11 @@ function populate_users(realm_people_data) {
onupdate: reset_scrollbar($bots_table),
},
parent_container: $("#admin-bot-list").expectOne(),
}).init();
bot_list.sort("alphabetic", "full_name");
bot_list.add_sort_function("bot_owner", sort_bot_owner);
init_sort: ['alphabetic', 'full_name'],
sort_fields: {
bot_owner: sort_bot_owner,
},
});
function get_rendered_last_activity(item) {
const today = new XDate();
@@ -222,7 +222,7 @@ function populate_users(realm_people_data) {
}
const $users_table = $("#admin_users_table");
const users_list = list_render.create($users_table, active_users, {
list_render.create($users_table, active_users, {
name: "users_table_list",
modifier: function (item) {
const $row = $(render_admin_user_list({
@@ -240,15 +240,15 @@ function populate_users(realm_people_data) {
onupdate: reset_scrollbar($users_table),
},
parent_container: $("#admin-user-list").expectOne(),
}).init();
users_list.sort("alphabetic", "full_name");
users_list.add_sort_function("role", sort_role);
users_list.add_sort_function("last_active", sort_last_active);
init_sort: ['alphabetic', 'full_name'],
sort_fields: {
role: sort_role,
last_active: sort_last_active,
},
});
const $deactivated_users_table = $("#admin_deactivated_users_table");
const deactivated_users_list = list_render.create($deactivated_users_table, deactivated_users, {
list_render.create($deactivated_users_table, deactivated_users, {
name: "deactivated_users_table_list",
modifier: function (item) {
return render_admin_user_list({
@@ -263,10 +263,11 @@ function populate_users(realm_people_data) {
onupdate: reset_scrollbar($deactivated_users_table),
},
parent_container: $("#admin-deactivated-users-list").expectOne(),
}).init();
deactivated_users_list.sort("alphabetic", "full_name");
deactivated_users_list.add_sort_function("role", sort_role);
init_sort: ['alphabetic', 'full_name'],
sort_fields: {
role: sort_role,
},
});
loading.destroy_indicator($('#admin_page_users_loading_indicator'));
loading.destroy_indicator($('#admin_page_bots_loading_indicator'));