diff --git a/dashboard-ui/bower_components/iron-meta/.bower.json b/dashboard-ui/bower_components/iron-meta/.bower.json index 9e650790be..8119ebcf41 100644 --- a/dashboard-ui/bower_components/iron-meta/.bower.json +++ b/dashboard-ui/bower_components/iron-meta/.bower.json @@ -25,14 +25,14 @@ "web-component-tester": "*", "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0" }, - "homepage": "https://github.com/PolymerElements/iron-meta", + "homepage": "https://github.com/polymerelements/iron-meta", "_release": "1.0.3", "_resolution": { "type": "version", "tag": "v1.0.3", "commit": "91529259262b0d8f33fed44bc3fd47aedf35cb04" }, - "_source": "git://github.com/PolymerElements/iron-meta.git", + "_source": "git://github.com/polymerelements/iron-meta.git", "_target": "^1.0.0", - "_originalSource": "PolymerElements/iron-meta" + "_originalSource": "polymerelements/iron-meta" } \ No newline at end of file diff --git a/dashboard-ui/components/itemidentifier/itemidentifier.js b/dashboard-ui/components/itemidentifier/itemidentifier.js new file mode 100644 index 0000000000..90cce5f14c --- /dev/null +++ b/dashboard-ui/components/itemidentifier/itemidentifier.js @@ -0,0 +1,353 @@ +(function ($, window, document) { + + var currentItem; + var currentDeferred; + var hasChanges = false; + var currentSearchResult; + + function onIdentificationFormSubmitted() { + + var page = $(this).parents('.editorContent'); + + searchForIdentificationResults(page); + return false; + } + + function searchForIdentificationResults(page) { + + var lookupInfo = { + ProviderIds: {} + }; + + $('.identifyField', page).each(function () { + + var value = this.value; + + if (value) { + + if (this.type == 'number') { + value = parseInt(value); + } + + lookupInfo[this.getAttribute('data-lookup')] = value; + } + + }); + + var hasId = false; + + $('.txtLookupId', page).each(function () { + + var value = this.value; + + if (value) { + hasId = true; + } + lookupInfo.ProviderIds[this.getAttribute('data-providerkey')] = value; + + }); + + if (!hasId && !lookupInfo.Name) { + Dashboard.alert(Globalize.translate('MessagePleaseEnterNameOrId')); + return; + } + + if (currentItem.GameSystem) { + lookupInfo.GameSystem = currentItem.GameSystem; + } + + lookupInfo = { + SearchInfo: lookupInfo, + IncludeDisabledProviders: true + }; + + Dashboard.showLoadingMsg(); + + ApiClient.ajax({ + type: "POST", + url: ApiClient.getUrl("Items/RemoteSearch/" + currentItem.Type), + data: JSON.stringify(lookupInfo), + contentType: "application/json" + + }).done(function (results) { + + Dashboard.hideLoadingMsg(); + showIdentificationSearchResults(page, results); + }); + } + + function showIdentificationSearchResults(page, results) { + + $('.popupIdentifyForm', page).hide(); + $('.identificationSearchResults', page).show(); + $('.identifyOptionsForm', page).hide(); + $('.btnIdentifyBack', page).show(); + + var html = ''; + + for (var i = 0, length = results.length; i < length; i++) { + + var result = results[i]; + + html += getSearchResultHtml(result, i); + } + + var elem = $('.identificationSearchResultList', page).html(html).trigger('create'); + + $('.searchImage', elem).on('click', function () { + + var index = parseInt(this.getAttribute('data-index')); + + var currentResult = results[index]; + + showIdentifyOptions(page, currentResult); + }); + } + + function showIdentifyOptions(page, identifyResult) { + + $('.popupIdentifyForm', page).hide(); + $('.identificationSearchResults', page).hide(); + $('.identifyOptionsForm', page).show(); + $('.btnIdentifyBack', page).show(); + $('#chkIdentifyReplaceImages', page).checked(true); + + currentSearchResult = identifyResult; + + var lines = []; + lines.push(identifyResult.Name); + + if (identifyResult.ProductionYear) { + lines.push(identifyResult.ProductionYear); + } + + if (identifyResult.GameSystem) { + lines.push(identifyResult.GameSystem); + } + + var resultHtml = lines.join('
'); + + if (identifyResult.ImageUrl) { + var displayUrl = getSearchImageDisplayUrl(identifyResult.ImageUrl, identifyResult.SearchProviderName); + + resultHtml = '
' + resultHtml; + } + + $('.selectedSearchResult', page).html(resultHtml); + } + + function getSearchResultHtml(result, index) { + + var html = ''; + var cssClass = "card"; + + if (currentItem.Type == "Episode") { + cssClass += " backdropCard"; + } + else if (currentItem.Type == "MusicAlbum" || currentItem.Type == "MusicArtist") { + cssClass += " squareCard"; + } + else { + cssClass += " portraitCard"; + } + + html += '
'; + html += '
'; + html += '
'; + + html += ''; + + if (result.ImageUrl) { + var displayUrl = getSearchImageDisplayUrl(result.ImageUrl, result.SearchProviderName); + + html += '
'; + } else { + + html += '
'; + } + html += '
'; + html += '
'; + + html += '
'; + html += '
' + result.Name + '
'; + + html += '
'; + html += result.ProductionYear || ' '; + html += '
'; + + if (result.GameSystem) { + html += '
'; + html += result.GameSystem; + html += '
'; + } + html += '
'; + + html += '
'; + return html; + } + + function getSearchImageDisplayUrl(url, provider) { + return ApiClient.getUrl("Items/RemoteSearch/Image", { imageUrl: url, ProviderName: provider }); + } + + function onIdentificationOptionsSubmit() { + + var page = $(this).parents('.editorContent'); + + submitIdentficationResult(page); + return false; + } + + function submitIdentficationResult(page) { + + Dashboard.showLoadingMsg(); + + var options = { + ReplaceAllImages: $('#chkIdentifyReplaceImages', page).checked() + }; + + ApiClient.ajax({ + type: "POST", + url: ApiClient.getUrl("Items/RemoteSearch/Apply/" + currentItem.Id, options), + data: JSON.stringify(currentSearchResult), + contentType: "application/json" + + }).done(function () { + + hasChanges = true; + Dashboard.hideLoadingMsg(); + + PaperDialogHelper.close(document.querySelector('.identifyDialog')); + + }).fail(function () { + + Dashboard.hideLoadingMsg(); + + PaperDialogHelper.close(document.querySelector('.identifyDialog')); + }); + } + + function initEditor(page) { + + $('.popupIdentifyForm', page).off('submit', onIdentificationFormSubmitted).on('submit', onIdentificationFormSubmitted); + $('.identifyOptionsForm', page).off('submit', onIdentificationOptionsSubmit).on('submit', onIdentificationOptionsSubmit); + } + + function showIdentificationForm(page, item) { + + ApiClient.getJSON(ApiClient.getUrl("Items/" + item.Id + "/ExternalIdInfos")).done(function (idList) { + + var html = ''; + + var providerIds = item.ProviderIds || {}; + + for (var i = 0, length = idList.length; i < length; i++) { + + var idInfo = idList[i]; + + var id = "txtLookup" + idInfo.Key; + + html += '
'; + + var idLabel = Globalize.translate('LabelDynamicExternalId').replace('{0}', idInfo.Name); + + var value = providerIds[idInfo.Key] || ''; + + html += ''; + + html += '
'; + } + + $('#txtLookupName', page).val(item.Name); + + if (item.Type == "Person" || item.Type == "BoxSet") { + + $('.fldLookupYear', page).hide(); + $('#txtLookupYear', page).val(''); + } else { + + $('.fldLookupYear', page).show(); + $('#txtLookupYear', page).val(item.ProductionYear); + } + + $('.identifyProviderIds', page).html(html).trigger('create'); + + $('.identificationHeader', page).html(Globalize.translate('HeaderIdentify')); + }); + } + + function showEditor(itemId) { + + Dashboard.showLoadingMsg(); + + ApiClient.ajax({ + + type: 'GET', + url: 'components/itemidentifier/itemidentifier.template.html' + + }).done(function (template) { + + ApiClient.getItem(Dashboard.getCurrentUserId(), itemId).done(function (item) { + + currentItem = item; + + var dlg = PaperDialogHelper.createDialog(); + + var html = ''; + html += '

'; + html += ''; + html += '
' + Globalize.translate('HeaderIdentifyItem') + '
'; + html += '

'; + + html += '
'; + html += Globalize.translateDocument(template); + html += '
'; + + dlg.innerHTML = html; + document.body.appendChild(dlg); + + // Has to be assigned a z-index after the call to .open() + $(dlg).on('iron-overlay-closed', onDialogClosed); + + PaperDialogHelper.openWithHash(dlg, 'itemidentifier'); + + var editorContent = dlg.querySelector('.editorContent'); + initEditor(editorContent); + + $('.btnCloseDialog', dlg).on('click', function () { + + PaperDialogHelper.close(dlg); + }); + + dlg.classList.add('identifyDialog'); + + showIdentificationForm(dlg, item); + Dashboard.hideLoadingMsg(); + }); + }); + } + + function onDialogClosed() { + + $(this).remove(); + Dashboard.hideLoadingMsg(); + currentDeferred.resolveWith(null, [hasChanges]); + } + + window.ItemIdentifier = { + show: function (itemId) { + + var deferred = DeferredBuilder.Deferred(); + + currentDeferred = deferred; + hasChanges = false; + + require(['components/paperdialoghelper'], function () { + + showEditor(itemId); + }); + return deferred.promise(); + } + }; + +})(jQuery, window, document); \ No newline at end of file diff --git a/dashboard-ui/components/itemidentifier/itemidentifier.template.html b/dashboard-ui/components/itemidentifier/itemidentifier.template.html new file mode 100644 index 0000000000..4e8ad52c79 --- /dev/null +++ b/dashboard-ui/components/itemidentifier/itemidentifier.template.html @@ -0,0 +1,38 @@ +
+ +

${HeaderIdentifyItemHelp}

+ +
+ +
+
+ +
+ +
+
+ +

+ +

+
+ + + diff --git a/dashboard-ui/css/images/items/list/remotesearch.png b/dashboard-ui/css/images/items/list/remotesearch.png deleted file mode 100644 index 979ba2e8e7..0000000000 Binary files a/dashboard-ui/css/images/items/list/remotesearch.png and /dev/null differ diff --git a/dashboard-ui/edititemmetadata.html b/dashboard-ui/edititemmetadata.html index 736b32d655..82783a368b 100644 --- a/dashboard-ui/edititemmetadata.html +++ b/dashboard-ui/edititemmetadata.html @@ -334,64 +334,6 @@ -