From 76138ae93f049275880f1831e2e1b945e41c15ad Mon Sep 17 00:00:00 2001 From: LupusUmbrae Date: Sun, 17 Apr 2016 19:48:35 +0100 Subject: [PATCH] Bug fixes - Unique id added to radio boxes, without which they affected other tabs - watch added on loading of data, not just when adding a new tab --- static/javascript/kdm.js | 32 ++++++++++++++++-------- static/templates/char/courage.html | 6 ++--- static/templates/char/name.html | 4 +-- static/templates/char/understanding.html | 6 ++--- templates/index.html | 5 ++-- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/static/javascript/kdm.js b/static/javascript/kdm.js index 6823d5e..cec2f81 100644 --- a/static/javascript/kdm.js +++ b/static/javascript/kdm.js @@ -22,6 +22,11 @@ function load(scope, json) { var parsed = JSON.parse(json); scope.tabs = parsed; + + parsed.forEach(function(kdm, index) { + watchTab(scope, kdm, index); + }) + scope.$apply(); } @@ -160,6 +165,11 @@ $('#clearAll').click(function() { $("#clear-dialog").dialog("open"); }); + + $('.nav-tabs a').click(function(e) { + e.preventDefault() + $(this).tab('show') + }); }); @@ -194,20 +204,20 @@ tabs.push(kdm); var lastIndex = tabs.length - 1; + watchTab(scope, kdm, lastIndex); + } + + function watchTab(scope, kdm, tabIndex) { if (kdm.type === "char") { - scope.$watch('tabs[' + lastIndex + '].courage.levels', watchCheckboxArray, true); - scope.$watch('tabs[' + lastIndex + '].understanding.levels', watchCheckboxArray, true); - scope.$watch('tabs[' + lastIndex + '].age', watchCheckboxArray, true); - scope.$watch('tabs[' + lastIndex + '].weapon.levels', watchCheckboxArray, true); + scope.$watch('tabs[' + tabIndex + '].courage.levels', watchCheckboxArray, true); + scope.$watch('tabs[' + tabIndex + '].understanding.levels', watchCheckboxArray, true); + scope.$watch('tabs[' + tabIndex + '].age', watchCheckboxArray, true); + scope.$watch('tabs[' + tabIndex + '].weapon.levels', watchCheckboxArray, true); } else if (kdm.type === "settlement") { - scope.$watch('tabs[' + lastIndex + '].population.lost', watchCheckboxArray, true); - scope.$watch('tabs[' + lastIndex + '].deathCount', watchCheckboxArray, true); - scope.$watch('tabs[' + lastIndex + '].timeline', watchCheckboxArray, true); + scope.$watch('tabs[' + tabIndex + '].population.lost', watchCheckboxArray, true); + scope.$watch('tabs[' + tabIndex + '].deathCount', watchCheckboxArray, true); + scope.$watch('tabs[' + tabIndex + '].timeline', watchCheckboxArray, true); } - - $('.nav-tabs li a').click(function(e) { - e.preventDefault(); - }); } function watchCheckboxArray(newVal, oldVal) { diff --git a/static/templates/char/courage.html b/static/templates/char/courage.html index 5b78031..33d081a 100644 --- a/static/templates/char/courage.html +++ b/static/templates/char/courage.html @@ -39,7 +39,7 @@
- +
Stalwart: can't be knocked down by brain trauma or intimidate. @@ -47,7 +47,7 @@
- +

@@ -56,7 +56,7 @@
- +

diff --git a/static/templates/char/name.html b/static/templates/char/name.html index 0bc4126..6930666 100644 --- a/static/templates/char/name.html +++ b/static/templates/char/name.html @@ -10,8 +10,8 @@
- - + +
diff --git a/static/templates/char/understanding.html b/static/templates/char/understanding.html index 6f7762a..814e98d 100644 --- a/static/templates/char/understanding.html +++ b/static/templates/char/understanding.html @@ -39,7 +39,7 @@
- +
Analyze: Look at top AI card and return it to the top of the deck. @@ -47,7 +47,7 @@
- +

@@ -56,7 +56,7 @@
- +

diff --git a/templates/index.html b/templates/index.html index 8ce7d96..1b9f8ad 100644 --- a/templates/index.html +++ b/templates/index.html @@ -85,9 +85,10 @@

Kingdom Death Monster

- - + + +