From 52d8539e25b18497ed0f87437366921c4d658942 Mon Sep 17 00:00:00 2001
From: Adam <adam111316@users.noreply.github.com>
Date: Mon, 23 Nov 2015 19:11:38 +0800
Subject: [PATCH] Change to move JavaScript out of editShow.tmpl into separate
 file

---
 gui/slick/interfaces/default/editShow.tmpl | 105 ++-------------------
 gui/slick/js/editShow.js                   |  97 +++++++++++++++++++
 2 files changed, 103 insertions(+), 99 deletions(-)
 create mode 100644 gui/slick/js/editShow.js

diff --git a/gui/slick/interfaces/default/editShow.tmpl b/gui/slick/interfaces/default/editShow.tmpl
index 0564cf7e..413fb1d7 100644
--- a/gui/slick/interfaces/default/editShow.tmpl
+++ b/gui/slick/interfaces/default/editShow.tmpl
@@ -14,43 +14,13 @@
 #include $os.path.join($sickbeard.PROG_DIR, 'gui/slick/interfaces/default/inc_top.tmpl')
 
 <script type="text/javascript" src="$sbRoot/js/qualityChooser.js?v=$sbPID"></script>
-<script type="text/javascript" charset="utf-8">
-<!--
-\$(document).ready(function(){
-
-	\$.getJSON('$sbRoot/home/addShows/getIndexerLanguages', {}, function(data) {
-		var resultStr = '';
-
-		if (data.results.length == 0) {
-			flag = ' class="flag" style="background-image:url($sbRoot/images/flags/${show.lang}.png)"';
-			resultStr = '<option value="$show.lang" selected="selected" + flag>$show.lang</option>';
-		} else {
-			var current_lang_added = false;
-			\$.each(data.results, function(index, obj) {
-
-				if (obj == '$show.lang') {
-					selected = ' selected="selected"';
-					current_lang_added = true;
-				}
-				else {
-					selected = '';
-				}
-
-				flag = ' class="flag" style="background-image:url($sbRoot/images/flags/' + obj + '.png);"';
-				resultStr += '<option value="' + obj + '"' + selected + flag + '>' + obj + '</option>';
-			});
-
-			if (!current_lang_added)
-				resultStr += '<option value="$show.lang" selected="selected">$show.lang</option>';
-
-		}
-		\$('#indexerLangSelectEdit').html(resultStr)
-
-	});
-});
-//-->
+<script type="text/javascript" src="$sbRoot/js/editShow.js?v=$sbPID"></script>
+<script>
+	var config = {
+		show_lang: "$show.lang",
+		show_isanime: #echo ['!1','!0'][$show.is_anime]#
+	}
 </script>
-
 #if $varExists('header')
 	<h1 class="header">$header</h1>
 #else
@@ -252,69 +222,6 @@
 #end if
 		<input type="submit" id="submit" value="Submit" class="btn btn-primary" />
 	</form>
-
-<script type="text/javascript" charset="utf-8">
-<!--
-	var all_exceptions = new Array;
-
-	jQuery('#location').fileBrowser({ title: 'Select Show Location' });
-
-	\$('#submit').click(function(){
-		all_exceptions = []
-
-		\$('#exceptions_list option').each  ( function() {
-			all_exceptions.push( \$(this).val() );
-		});
-
-		\$('#exceptions_list').val(all_exceptions);
-#if $show.is_anime:
-		generate_bwlist()
-#end if
-	});
-
-	\$('#addSceneName').click(function() {
-		var scene_ex = \$('#SceneName').val()
-		var option = \$('<option>')
-		all_exceptions = []
-
-		\$('#exceptions_list option').each  ( function() {
-		   all_exceptions.push( \$(this).val() )
-		});
-
-		\$('#SceneName').val('')
-
-		if (jQuery.inArray(scene_ex, all_exceptions) > -1 || (scene_ex == ''))
-			return
-
-		\$('#SceneException').show()
-
-		option.attr('value',scene_ex)
-		option.html(scene_ex)
-		return option.appendTo('#exceptions_list');
-	});
-
-	\$('#removeSceneName').click(function() {
-		\$('#exceptions_list option:selected').remove();
-
-		\$(this).toggle_SceneException()
-	});
-
-	$.fn.toggle_SceneException = function() {
-		all_exceptions = []
-
-		\$('#exceptions_list option').each  ( function() {
-			all_exceptions.push( \$(this).val() );
-		});
-
-		if ('' == all_exceptions)
-			\$('#SceneException').hide();
-		else
-			\$('#SceneException').show();
-	}
-
-	\$(this).toggle_SceneException();
-//-->
-</script>
 </div>
 
 #include $os.path.join($sickbeard.PROG_DIR, 'gui/slick/interfaces/default/inc_bottom.tmpl')
diff --git a/gui/slick/js/editShow.js b/gui/slick/js/editShow.js
new file mode 100644
index 00000000..d88b2486
--- /dev/null
+++ b/gui/slick/js/editShow.js
@@ -0,0 +1,97 @@
+/*globals $, config, sbRoot, generate_bwlist*/
+
+$(document).ready(function () {
+
+	$.getJSON(sbRoot + '/home/addShows/getIndexerLanguages', {}, function (data) {
+		var resultStr, flag, selected, current_lang_added = '';
+
+		if (data.results.length === 0) {
+			flag = ' class="flag" style="background-image:url(' + sbRoot + '/images/flags/' + config.show_lang + '.png)"';
+			resultStr = '<option value="' + config.show_lang + '" selected="selected"' + flag + '>' + config.show_lang + '</option>';
+		} else {
+			current_lang_added = false;
+			$.each(data.results, function (index, obj) {
+
+				if (obj === config.show_lang) {
+					selected = ' selected="selected"';
+					current_lang_added = true;
+				}
+				else {
+					selected = '';
+				}
+
+				flag = ' class="flag" style="background-image:url(' + sbRoot + '/images/flags/' + obj + '.png);"';
+				resultStr += '<option value="' + obj + '"' + selected + flag + '>' + obj + '</option>';
+			});
+
+			if (!current_lang_added) {
+				resultStr += '<option value=" ' + config.show_lang + '" selected="selected"> ' + config.show_lang + '</option>';
+			}
+
+		}
+		$('#indexerLangSelectEdit').html(resultStr);
+
+	});
+
+
+	var all_exceptions = [];
+
+	$('#location').fileBrowser({title: 'Select Show Location'});
+
+	$('#submit').click(function () {
+		all_exceptions = [];
+
+		$('#exceptions_list').find('option').each  (function () {
+			all_exceptions.push($(this).val());
+		});
+
+		$('#exceptions_list').val(all_exceptions);
+		if (config.show_isanime) {
+			generate_bwlist();
+		}
+	});
+
+	$('#addSceneName').click(function () {
+		var scene_ex = $('#SceneName').val();
+		var option = $('<option>');
+		all_exceptions = [];
+
+		$('#exceptions_list').find('option').each  (function () {
+			all_exceptions.push($(this).val());
+		});
+
+		$('#SceneName').val('');
+
+		if ($.inArray(scene_ex, all_exceptions) > -1 || (scene_ex === '')) {
+			return;
+		}
+		$('#SceneException').show();
+
+		option.attr('value', scene_ex);
+		option.html(scene_ex);
+		return option.appendTo('#exceptions_list');
+	});
+
+	$('#removeSceneName').click(function () {
+		$('#exceptions_list').find('option:selected').remove();
+
+		$(this).toggle_SceneException();
+	});
+
+	$.fn.toggle_SceneException = function () {
+		all_exceptions = [];
+
+		$('#exceptions_list').find('option').each  (function () {
+			all_exceptions.push($(this).val());
+		});
+
+		if ('' === all_exceptions) {
+			$('#SceneException').hide();
+		}
+		else {
+			$('#SceneException').show();
+		}
+	};
+
+	$(this).toggle_SceneException();
+});
\ No newline at end of file