2017-04-08 21:02:08 +02:00
|
|
|
var settings_streams = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var meta = {
|
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
2017-04-17 16:51:27 +02:00
|
|
|
exports.reset = function () {
|
|
|
|
meta.loaded = false;
|
|
|
|
};
|
|
|
|
|
2018-12-08 17:37:57 +01:00
|
|
|
exports.maybe_disable_widgets = function () {
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".organization-box [data-name='default-streams-list']")
|
|
|
|
.find("input:not(.search), button, select").attr("disabled", true);
|
|
|
|
};
|
|
|
|
|
2017-04-08 21:02:08 +02:00
|
|
|
exports.build_default_stream_table = function (streams_data) {
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
self.row_dict = new Dict();
|
|
|
|
|
2017-04-20 21:49:12 +02:00
|
|
|
var table = $("#admin_default_streams_table").expectOne();
|
|
|
|
|
2018-06-20 18:32:39 +02:00
|
|
|
list_render.create(table, streams_data, {
|
2017-04-20 21:49:12 +02:00
|
|
|
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) {
|
2017-08-25 03:30:54 +02:00
|
|
|
return item.name.toLowerCase().indexOf(value) >= 0;
|
2017-04-20 21:49:12 +02:00
|
|
|
},
|
2017-09-15 23:01:36 +02:00
|
|
|
onupdate: function () {
|
2019-01-09 14:30:35 +01:00
|
|
|
ui.reset_scrollbar(table);
|
2017-09-15 23:01:36 +02:00
|
|
|
},
|
2017-04-20 21:49:12 +02:00
|
|
|
},
|
|
|
|
}).init();
|
|
|
|
|
2017-09-15 23:01:36 +02:00
|
|
|
ui.set_up_scrollbar(table.closest(".progressive-table-wrapper"));
|
|
|
|
|
2017-04-20 21:49:12 +02:00
|
|
|
loading.destroy_indicator($('#admin_page_default_streams_loading_indicator'));
|
2017-04-08 21:02:08 +02:00
|
|
|
|
|
|
|
self.remove = function (stream_id) {
|
|
|
|
if (self.row_dict.has(stream_id)) {
|
|
|
|
var row = self.row_dict.get(stream_id);
|
|
|
|
row.remove();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
};
|
|
|
|
|
|
|
|
var default_stream_table;
|
|
|
|
|
|
|
|
exports.remove_default_stream = function (stream_id) {
|
|
|
|
if (default_stream_table) {
|
|
|
|
default_stream_table.remove(stream_id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_default_streams_table = function () {
|
|
|
|
if (/#*organization/.test(window.location.hash) ||
|
|
|
|
/#*settings/.test(window.location.hash)) {
|
|
|
|
$("#admin_default_streams_table").expectOne().find("tr.default_stream_row").remove();
|
|
|
|
default_stream_table = exports.build_default_stream_table(
|
|
|
|
page_params.realm_default_streams);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function make_stream_default(stream_name) {
|
|
|
|
var data = {
|
|
|
|
stream_name: stream_name,
|
|
|
|
};
|
2017-03-28 06:44:02 +02:00
|
|
|
var default_stream_status = $("#admin-default-stream-status");
|
|
|
|
default_stream_status.hide();
|
2017-04-08 21:02:08 +02:00
|
|
|
|
|
|
|
channel.post({
|
|
|
|
url: '/json/default_streams',
|
|
|
|
data: data,
|
|
|
|
error: function (xhr) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
2017-06-04 19:42:41 +02:00
|
|
|
ui_report.error(i18n.t("Failed"), xhr, default_stream_status);
|
2017-04-08 21:02:08 +02:00
|
|
|
} else {
|
2017-06-04 19:42:41 +02:00
|
|
|
ui_report.error(i18n.t("Failed"), default_stream_status);
|
2017-04-08 21:02:08 +02:00
|
|
|
}
|
2017-03-28 06:44:02 +02:00
|
|
|
default_stream_status.show();
|
2017-04-08 21:02:08 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-07 13:31:23 +01:00
|
|
|
exports.delete_default_stream = function (stream_name, default_stream_row, alert_element) {
|
|
|
|
channel.del({
|
|
|
|
url: "/json/default_streams" + "?" + $.param({ stream_name: stream_name }),
|
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.generic_row_button_error(xhr, alert_element);
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
default_stream_row.remove();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-04-08 21:02:08 +02:00
|
|
|
exports.set_up = function () {
|
2018-12-08 18:16:37 +01:00
|
|
|
exports.build_page();
|
|
|
|
exports.maybe_disable_widgets();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.build_page = function () {
|
2017-04-08 21:02:08 +02:00
|
|
|
meta.loaded = true;
|
|
|
|
|
|
|
|
exports.update_default_streams_table();
|
|
|
|
|
|
|
|
$('.create_default_stream').keypress(function (e) {
|
|
|
|
if (e.which === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-04-26 22:32:37 +02:00
|
|
|
var default_stream_input = $(".create_default_stream");
|
|
|
|
make_stream_default(default_stream_input.val());
|
|
|
|
default_stream_input[0].value = "";
|
2017-04-08 21:02:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.create_default_stream').typeahead({
|
|
|
|
items: 5,
|
|
|
|
fixed: true,
|
|
|
|
source: function () {
|
2017-08-22 20:00:09 +02:00
|
|
|
return stream_data.get_non_default_stream_names();
|
2017-04-08 21:02:08 +02:00
|
|
|
},
|
2017-06-12 19:15:57 +02:00
|
|
|
highlighter: function (item) {
|
|
|
|
return typeahead_helper.render_typeahead_item({ primary: item });
|
|
|
|
},
|
2017-04-08 21:02:08 +02:00
|
|
|
updater: function (stream_name) {
|
|
|
|
make_stream_default(stream_name);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-03-28 06:41:26 +02:00
|
|
|
$(".default-stream-form").on("click", "#do_submit_stream", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var default_stream_input = $(".create_default_stream");
|
|
|
|
make_stream_default(default_stream_input.val());
|
|
|
|
// Clear value inside input box
|
|
|
|
default_stream_input[0].value = "";
|
|
|
|
});
|
|
|
|
|
2018-03-25 19:57:38 +02:00
|
|
|
$("body").on("click", ".default_stream_row .remove-default-stream", function (e) {
|
|
|
|
var row = $(this).closest(".default_stream_row");
|
|
|
|
var stream_name = row.attr("id");
|
2018-03-07 13:31:23 +01:00
|
|
|
exports.delete_default_stream(stream_name, row, $(e.target));
|
2018-03-25 19:57:38 +02:00
|
|
|
});
|
2018-02-14 14:56:46 +01:00
|
|
|
};
|
2017-04-08 21:02:08 +02:00
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings_streams;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.settings_streams = settings_streams;
|