diff --git a/app/Http/Controllers/SubjectController.php b/app/Http/Controllers/SubjectController.php index 0ccc83e..55cd433 100755 --- a/app/Http/Controllers/SubjectController.php +++ b/app/Http/Controllers/SubjectController.php @@ -86,17 +86,23 @@ public function destroy(Subject $subject) /** * Find the levels for a given subject encoded in Json * - * @param int $subjectId + * @param string $name optional, if given, find by subject name instead of ID */ - public function getSubjectLevelsAsJson($subjectId = 1) + public function getSubjectLevelsAsJson($subjectName = null) { - $subject = Subject::find($subjectId); + $subjectName = urldecode($subjectName); + $subject = Subject::where('name', $subjectName)->get()->first(); $levels = $subject->getAttributes(); unset($levels['id'], $levels['created_at'], $levels['updated_at'], $levels['name']); - return response()->json($levels); - } - + $parsedSubjects = array(); + foreach($levels as $level => $available) { + if ($available) { + $parsedSubjects[] = $this->parseSubject($level); + } + } + return response()->json($parsedSubjects); + } /** * Find the levels for a given subject encoded in Json @@ -108,4 +114,26 @@ public function getSubjectsJson() $subjects = Subject::all(); return response()->json($subjects); } + + private function parseSubject($subject) + { + switch ($subject) { + case "primary": + return "Primary"; + case "secondary": + return "Secondary"; + case "gcse": + return "GCSE"; + case "alevel": + return "A-Level"; + case "university_bachelors": + return "University - Bachelor's"; + case "university_masters": + return "University - Master's"; + case "adult_casual": + return "Adult/Casual Learner"; + default: + break; + } + } } diff --git a/public/js/app.js b/public/js/app.js index 0a6a266..2320a2c 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -63,7 +63,7 @@ /******/ __webpack_require__.p = "./"; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 39); +/******/ return __webpack_require__(__webpack_require__.s = 40); /******/ }) /************************************************************************/ /******/ ([ @@ -10640,7 +10640,7 @@ return jQuery; /* WEBPACK VAR INJECTION */(function(process) { var utils = __webpack_require__(0); -var normalizeHeaderName = __webpack_require__(26); +var normalizeHeaderName = __webpack_require__(27); var PROTECTION_PREFIX = /^\)\]\}',?\n/; var DEFAULT_CONTENT_TYPE = { @@ -10731,7 +10731,7 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { module.exports = defaults; -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(8))) +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9))) /***/ }), /* 3 */ @@ -10741,12 +10741,12 @@ module.exports = defaults; /* WEBPACK VAR INJECTION */(function(process) { var utils = __webpack_require__(0); -var settle = __webpack_require__(18); -var buildURL = __webpack_require__(21); -var parseHeaders = __webpack_require__(27); -var isURLSameOrigin = __webpack_require__(25); +var settle = __webpack_require__(19); +var buildURL = __webpack_require__(22); +var parseHeaders = __webpack_require__(28); +var isURLSameOrigin = __webpack_require__(26); var createError = __webpack_require__(6); -var btoa = (typeof window !== 'undefined' && window.btoa && window.btoa.bind(window)) || __webpack_require__(20); +var btoa = (typeof window !== 'undefined' && window.btoa && window.btoa.bind(window)) || __webpack_require__(21); module.exports = function xhrAdapter(config) { return new Promise(function dispatchXhrRequest(resolve, reject) { @@ -10842,7 +10842,7 @@ module.exports = function xhrAdapter(config) { // This is only done if running in a standard browser environment. // Specifically not if we're in a web worker, or react-native. if (utils.isStandardBrowserEnv()) { - var cookies = __webpack_require__(23); + var cookies = __webpack_require__(24); // Add xsrf header var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ? @@ -10916,7 +10916,7 @@ module.exports = function xhrAdapter(config) { }); }; -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(8))) +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9))) /***/ }), /* 4 */ @@ -10963,7 +10963,7 @@ module.exports = function isCancel(value) { "use strict"; -var enhanceError = __webpack_require__(17); +var enhanceError = __webpack_require__(18); /** * Create an Error with the specified message, config, error code, and response. @@ -11000,6 +11000,38 @@ module.exports = function bind(fn, thisArg) { /***/ }), /* 8 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function($) {var setup = function setup() { + + $('.splash-subject-selector').change(function () { + var subjectName = $(this).val(), + $this = $(this); + + $.ajax({ + url: "/subjects/get-levels/" + encodeURI(subjectName), + success: function success(data) { + var levels = data, + $levelSelector = $this.parent().parent().parent().find('.splash-level-selector'); + + $levelSelector.find('option').remove().end().append($('