define(["events", "globalize", "dom", "datetime", "userSettings", "serverNotifications", "connectionManager", "emby-button", "listViewStyle"], function (events, globalize, dom, datetime, userSettings, serverNotifications, connectionManager) { "use strict"; function getEntryHtml(entry, apiClient) { var html = ""; html += '
'; var color = "#00a4dc"; var icon = "notifications"; if ("Error" == entry.Severity || "Fatal" == entry.Severity || "Warn" == entry.Severity) { color = "#cc0000"; icon = "notification_important"; } if (entry.UserId && entry.UserPrimaryImageTag) { html += 'dvr" } else { html += '' + icon + ''; } html += '
'; html += '
'; html += entry.Name; html += "
"; html += '
'; var date = datetime.parseISO8601Date(entry.Date, true); html += datetime.toLocaleString(date).toLowerCase(); html += "
"; html += '
'; html += entry.ShortOverview || ""; html += "
"; html += "
"; if (entry.Overview) { html += ''; } return html += "
"; } function renderList(elem, apiClient, result, startIndex, limit) { elem.innerHTML = result.Items.map(function (i) { return getEntryHtml(i, apiClient); }).join(""); } function reloadData(instance, elem, apiClient, startIndex, limit) { if (null == startIndex) { startIndex = parseInt(elem.getAttribute("data-activitystartindex") || "0"); } limit = limit || parseInt(elem.getAttribute("data-activitylimit") || "7"); var minDate = new Date(); var hasUserId = "false" !== elem.getAttribute("data-useractivity"); if (hasUserId) { minDate.setTime(minDate.getTime() - 864e5); } else { minDate.setTime(minDate.getTime() - 6048e5); } ApiClient.getJSON(ApiClient.getUrl("System/ActivityLog/Entries", { startIndex: startIndex, limit: limit, minDate: minDate.toISOString(), hasUserId: hasUserId })).then(function (result) { if (elem.setAttribute("data-activitystartindex", startIndex), elem.setAttribute("data-activitylimit", limit), !startIndex) { var activityContainer = dom.parentWithClass(elem, "activityContainer"); if (activityContainer) { if (result.Items.length) { activityContainer.classList.remove("hide"); } else { activityContainer.classList.add("hide"); } } } instance.items = result.Items; renderList(elem, apiClient, result, startIndex, limit); }); } function onActivityLogUpdate(e, apiClient, data) { var options = this.options; if (options && options.serverId === apiClient.serverId()) { reloadData(this, options.element, apiClient); } } function onListClick(e) { var btnEntryInfo = dom.parentWithClass(e.target, "btnEntryInfo"); if (btnEntryInfo) { var id = btnEntryInfo.getAttribute("data-id"); var items = this.items; if (items) { var item = items.filter(function (i) { return i.Id.toString() === id; })[0]; if (item) { showItemOverview(item); } } } } function showItemOverview(item) { require(["alert"], function (alert) { alert({ text: item.Overview }); }); } function ActivityLog(options) { this.options = options; var element = options.element; element.classList.add("activityLogListWidget"); element.addEventListener("click", onListClick.bind(this)); var apiClient = connectionManager.getApiClient(options.serverId); reloadData(this, element, apiClient); var onUpdate = onActivityLogUpdate.bind(this); this.updateFn = onUpdate; events.on(serverNotifications, "ActivityLogEntry", onUpdate); apiClient.sendMessage("ActivityLogEntryStart", "0,1500"); } ActivityLog.prototype.destroy = function () { var options = this.options; if (options) { options.element.classList.remove("activityLogListWidget"); connectionManager.getApiClient(options.serverId).sendMessage("ActivityLogEntryStop", "0,1500"); } var onUpdate = this.updateFn; if (onUpdate) { events.off(serverNotifications, "ActivityLogEntry", onUpdate); } this.items = null; this.options = null; }; return ActivityLog; });