define(['shell', 'dialogHelper', 'loading', 'layoutManager', 'connectionManager', 'embyRouter', 'globalize', 'emby-input', 'emby-checkbox', 'paper-icon-button-light', 'emby-select', 'material-icons', 'css!./../formdialog', 'emby-button'], function (shell, dialogHelper, loading, layoutManager, connectionManager, embyRouter, globalize) { function parentWithClass(elem, className) { while (!elem.classList || !elem.classList.contains(className)) { elem = elem.parentNode; if (!elem) { return null; } } return elem; } function getEditorHtml() { var html = ''; html += '
'; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += ''; html += '
'; html += globalize.translate('sharedcomponents#RefreshDialogHelp'); html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; return html; } function centerFocus(elem, horiz, on) { require(['scrollHelper'], function (scrollHelper) { var fn = on ? 'on' : 'off'; scrollHelper.centerFocus[fn](elem, horiz); }); } return function (options) { var self = this; function onSubmit(e) { loading.show(); var dlg = parentWithClass(this, 'dialog'); var apiClient = connectionManager.getApiClient(options.serverId); var replaceAllImages = dlg.querySelector('.chkReplaceImages').checked; var replaceAllMetadata = dlg.querySelector('#selectMetadataRefreshMode').value == 'all'; options.itemIds.forEach(function (itemId) { apiClient.refreshItem(itemId, { Recursive: true, ImageRefreshMode: 'FullRefresh', MetadataRefreshMode: 'FullRefresh', ReplaceAllImages: replaceAllImages, ReplaceAllMetadata: replaceAllMetadata }); }); dialogHelper.close(dlg); require(['toast'], function (toast) { toast(globalize.translate('sharedcomponents#RefreshQueued')); }); loading.hide(); e.preventDefault(); return false; } function initEditor(content, items) { content.querySelector('form').addEventListener('submit', onSubmit); } self.show = function () { var dialogOptions = { removeOnClose: true, scrollY: false }; if (layoutManager.tv) { dialogOptions.size = 'fullscreen'; } else { dialogOptions.size = 'small'; } var dlg = dialogHelper.createDialog(dialogOptions); dlg.classList.add('formDialog'); var html = ''; var title = globalize.translate('sharedcomponents#RefreshMetadata'); html += '
'; html += ''; html += '
'; html += title; html += '
'; html += '
'; html += getEditorHtml(); dlg.innerHTML = html; document.body.appendChild(dlg); initEditor(dlg); dlg.querySelector('.btnCancel').addEventListener('click', function () { dialogHelper.close(dlg); }); if (layoutManager.tv) { centerFocus(dlg.querySelector('.formDialogContent'), false, true); } return new Promise(function (resolve, reject) { if (layoutManager.tv) { centerFocus(dlg.querySelector('.formDialogContent'), false, false); } dlg.addEventListener('close', resolve); dialogHelper.open(dlg); }); }; }; });