/** @namespace config.sortArticle */ /** @namespace config.resultsSortby */ $(document).ready(function () { function populateLangSelect() { if (!$('#nameToSearch').length) return; if (1 >= $('#indexerLangSelect').find('option').length) { $.getJSON(sbRoot + '/home/addShows/getIndexerLanguages', {}, function (data) { var resultStr = '', selected = ' selected="selected"', elIndexerLang = $('#indexerLangSelect'); if (0 === data.results.length) { resultStr = ''; } else { $.each(data.results, function (index, obj) { resultStr += ''; }); } elIndexerLang.html(resultStr); elIndexerLang.change(function () { searchIndexers(); }); }); } } function cleanseText(text, toDisplay) { return (!0 == toDisplay ? text .replace(/["]/g, '"') : text .replace(/(?:["]|")/g, '') ); } var searchRequestXhr = null; function searchIndexers() { var elNameToSearch = $('#nameToSearch'); if (!elNameToSearch.val().length) return; if (searchRequestXhr) searchRequestXhr.abort(); var elTvDatabase = $('#providedIndexer'), elIndexerLang = $('#indexerLangSelect'), tvsrcName = elTvDatabase.find('option:selected').text(), tvSearchSrc = 0 < tvsrcName.length ? ' on ' + tvsrcName : ''; $('#searchResults').empty().html('' + ' searching ' + cleanseText(elNameToSearch.val(), !0) + '' + tvSearchSrc + ' in ' + elIndexerLang.val() + '...'); searchRequestXhr = $.ajax({ url: sbRoot + '/home/addShows/searchIndexersForShowName', data: { 'search_term': cleanseText(elNameToSearch.val(), !1), 'lang': elIndexerLang.val(), 'indexer': elTvDatabase.val() }, timeout: parseInt($('#indexer_timeout').val(), 10) * parseInt($('#indexer_count').val(), 2) * 1000 + 15000, dataType: 'json', error: function () { $('#searchResults').empty().html('search timed out, try again or try another database'); }, success: function (data) { var resultStr = '', attrs = '', checked = !1, rowType, row = 0, srcState = ''; if (0 === data.results.length) { resultStr += 'Sorry, no results found. Try a different search.'; } else { var result = { SrcName: 0, isInDB: 1, SrcId: 2, SrcDBId: 3, SrcUrl: 4, ShowID: 5, Title: 6, TitleHtml: 7, Aired: 8, Network: 9, Genre: 10, Overview: 11, RelSort: 12, DateSort: 13, AzSort: 14, ImgUrl: 15 }; $.each(data.results, function (index, item) { attrs = (!0 === item[result.isInDB] ? ' disabled="disabled"' : (!0 === checked ? '' : ' checked')); checked = (' checked' === attrs) ? !0 : checked; rowType = (0 == row % 2 ? '' : ' alt'); row++; var displayShowName = cleanseText(item[result.Title], !0), showstartdate = ''; if (null !== item[result.Aired]) { var startDate = new Date(item[result.Aired]); var today = new Date(); showstartdate = ' (' + (startDate > today ? 'will debut' : 'started') + ': ' + item[result.Aired] + ')'; } srcState = [ null === item[result.SrcName] ? '' : item[result.SrcName], !1 === item[result.isInDB] ? '' : 'exists in db'] .join(' - ').replace(/(^[\s-]+|[\s-]+$)/, ''); resultStr += '
' + '' + '' + (config.sortArticle ? displayShowName : displayShowName.replace(/^((?:A(?!\s+to)n?)|The)(\s)+(.*)/i, '$3$2($1)')) + '' + showstartdate + ('' === srcState ? '' : ' ' + '[' + srcState + ']' + '') + '
' + "\n"; }); } var selAttr = 'selected="selected" ', selClass = 'selected-text', classAttrSel = 'class="' + selClass + '" ', defSortby = /^az/.test(config.resultsSortby) || /^date/.test(config.resultsSortby) ? '': classAttrSel + selAttr; $('#searchResults').html( '
' + "\n" + '' + (0 < row ? row : 'No') + ' search result' + (1 == row ? '' : 's') + '...' + '' + '' + '' + "\n" + '
' + resultStr + '
' + '
' ); var container$ = $('#holder'), sortbySelect$ = $('#results-sortby'), reOrder = (function(value){ return ($('#results-sortby').find('option[value$="notop"]').hasClass(selClass) ? (1000 > value ? value + 1000 : value) : (1000 > value ? value : value - 1000))}), getData = (function(itemElem, sortby){ var position = parseInt($(itemElem).attr('data-sort-' + sortby)); return (!$(itemElem).attr('data-indb')) ? position : reOrder(position); }); sortbySelect$.find('.' + selClass).each(function(){ $(this).html('> ' + $(this).html()); }); container$.isotope({ itemSelector: '.results-item', sortBy: sortbySelect$.find('option:not([value$="top"]).' + selClass).val(), layoutMode: 'masonry', getSortData: { az: function(itemElem){ return getData(itemElem, 'az'); }, date: function(itemElem){ return getData(itemElem, 'date'); }, rel: function(itemElem){ return getData(itemElem, 'rel'); } } }).on('arrangeComplete', function(event, items){ $(items).each(function(i, item){ if (1 === i % 2){ $(item.element).addClass('alt'); } }); }); sortbySelect$.on('change', function(){ var selectedSort = String($(this).val()), sortby = selectedSort, curSortby$, curSel$, newSel$; curSortby$ = $(this).find('option:not([value$="top"])'); if (/top$/.test(selectedSort)){ sortby = curSortby$.filter('.' + selClass).val(); curSortby$ = $(this).find('option[value$="top"]'); } curSel$ = curSortby$.filter('.' + selClass); curSel$.html(curSel$.html().replace(/(?:>|>)\s/ , '')).removeClass(selClass); newSel$ = $(this).find('option[value$="' + selectedSort + '"]'); newSel$.html('> ' + newSel$.html()).addClass(selClass); $('.results-item[data-indb="1"]').each(function(){ $(this).attr(sortby, reOrder(parseInt($(this).attr(sortby), 10))); }); $('.results-item').removeClass('alt'); container$.isotope('updateSortData').isotope({sortBy: sortby}); config.resultsSortby = sortby + ($(this).find('option[value$="notop"]').hasClass(selClass) ? ' notop' : ''); $.get(sbRoot + '/config/general/saveResultPrefs', {ui_results_sortby: selectedSort}); }); updateSampleText(); myform.loadsection(0); $('.stepone-result-radio, .stepone-result-title').each(addQTip); } }); } var elNameToSearch = $('#nameToSearch'), elSearchName = $('#searchName'); elSearchName.click(function () { searchIndexers(); }); if (elNameToSearch.length && elNameToSearch.val().length) { elSearchName.click(); } $('#addShowButton, #cancelShowButton').click(function () { if (/cancel/.test(this.id)){ $('input[name=cancel_form]').val('1'); } else { // if they haven't picked a show don't let them submit if (!$('input:radio[name="whichSeries"]:checked').val() && !$('input:hidden[name="whichSeries"]').val().length) { alert('You must choose a show to continue'); return !1; } generate_bwlist(); } $('#addShowForm').submit(); }); $('#skipShowButton').click(function () { $('#skipShow').val('1'); $('#addShowForm').submit(); }); $('#qualityPreset').change(function () { myform.loadsection(2); }); /*********************************************** * jQuery Form to Form Wizard- (c) Dynamic Drive (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit http://www.dynamicdrive.com/ for this script and 100s more. ***********************************************/ var myform = new FormToWizard({ fieldsetborderwidth: 0, formid: 'addShowForm', revealfx: ['slide', 500], oninit: function () { populateLangSelect(); updateSampleText(); if ($('input:hidden[name="whichSeries"]').length && $('#fullShowPath').length) { goToStep(3); } } }); function goToStep(num) { $('.step').each(function () { if ($.data(this, 'section') + 1 == num) { $(this).click(); } }); } elNameToSearch.focus(); function updateSampleText() { if (0 === $('#displayText').length) { $('#cancelShowButton').attr('disabled', !1); $('#addShowButton').attr('disabled', 0 === $('#holder').find('.results-item').length); return; } // if something's selected then we have some behavior to figure out var show_name = '', sep_char, elRadio = $('input:radio[name="whichSeries"]:checked'), elInput = $('input:hidden[name="whichSeries"]'), elScene = $('#scene'), elRootDirs = $('#rootDirs'), elFullShowPath = $('#fullShowPath'), idxWhichShowID = 2, idxWhichTitle = 3; // if they've picked a radio button then use that if (elRadio.length) { show_name = elRadio.val().split('|')[idxWhichTitle]; elScene[0].checked = 0 <= show_scene_maps.indexOf(parseInt(elRadio.val().split('|')[idxWhichShowID], 10)); $('#scene-maps-found').css('display', elScene.is(':checked') ? 'inline' : 'None'); } // if we provided a show in the hidden field, use that else if (elInput.length && elInput.val().length) { show_name = $('#providedName').val(); } update_bwlist(show_name); var sample_text = '

Adding show ' + cleanseText(show_name, !0) + '' + ('' == show_name ? 'into
' : '
into') + ' '; // if we have a root dir selected, figure out the path if (elRootDirs.find('option:selected').length) { var root_dir_text = elRootDirs.find('option:selected').val(); if (root_dir_text.indexOf('/') >= 0) { sep_char = '/'; } else if (root_dir_text.indexOf('\\') >= 0) { sep_char = '\\'; } else { sep_char = ''; } if (root_dir_text.substr(sample_text.length - 1) != sep_char) { root_dir_text += sep_char; } root_dir_text += '||' + sep_char; sample_text += root_dir_text; } else if (elFullShowPath.length && elFullShowPath.val().length) { sample_text += elFullShowPath.val(); } else { sample_text += 'unknown dir.'; } sample_text += '

'; // if we have a show name then sanitize and use it for the dir name if (show_name.length) { $.get(sbRoot + '/home/addShows/sanitizeFileName', {name: cleanseText(show_name, !1)}, function (data) { $('#displayText').html(sample_text.replace('||', data)); }); // if not then it's unknown } else { $('#displayText').html(sample_text.replace('||', '??')); } // also toggle the add show button if ((elRootDirs.find('option:selected').length || (elFullShowPath.length && elFullShowPath.val().length)) && (elRadio.length) || (elInput.length && elInput.val().length)) { $('#addShowButton').attr('disabled', !1); } else { $('#addShowButton').attr('disabled', !0); } } $('#rootDirText').change(updateSampleText); $('#searchResults').on('click', '.stepone-result-radio', updateSampleText); elNameToSearch.keyup(function (event) { if (event.keyCode == 13) { elSearchName.click(); } }); var addQTip = (function() { $(this).css('cursor', 'help'); $(this).qtip({ show: { solo: !0 }, position: { viewport: $(window), my: 'left center', adjust: { y: -10, x: 2 } }, style: { tip: { corner: !0, method: 'polygon' }, classes: 'qtip-rounded qtip-bootstrap qtip-shadow ui-tooltip-sb' } }); }); $('#anime').change (function () { updateSampleText(); myform.loadsection(2); }); function add_option_to_pool (text) { var groupvalue = '', groupview = text, option = $('