-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
73 lines (59 loc) · 2.26 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope, $http) {
$(".advanced-card").hide();
$scope.apiCall = function(movieTitle) {
//* Search for a single movie
if (!movieTitle) {
$('#errorModal').modal('toggle')
} else {
$(".homepage").hide();
$(".advanced-card").hide();
$http.get("http://www.omdbapi.com/?t=" + movieTitle + "&plot=full&apikey=24dbfc1d&")
.then(function(result){
$scope.details = result.data
// console.log(result.data)
})
//* Search for related titles
$http.get("http://www.omdbapi.com/?s=" + movieTitle + "&apikey=24dbfc1d&")
.then(function(result) {
$scope.related = result.data.Search
// console.log($scope.related);
})
movieTitle = "";
$(".movieTitle").val("");
$(".advanced-card").hide();
}
};
//* Run search again when related title is clicked
$scope.newSearch = function(movie) {
$http.get("http://www.omdbapi.com/?t=" + movie + "&plot=full&apikey=24dbfc1d&")
.then(function(result){
$scope.details = result.data
// console.log(result.data)
})
};
//* Advanced search using more parameters
$scope.advanced = function(user) {
var url;
var title = user.title.split(" ").join("+")
if(user.year) {
url = "http://www.omdbapi.com/?t=" + title + "&type=" + user.select + "&y=" + user.year +"&plot=full&apikey=24dbfc1d&"
} else {
url = "http://www.omdbapi.com/?t=" + title + "&type=" + user.select + "&plot=full&apikey=24dbfc1d&"
}
// console.log(user)
// console.log(url);
$http.get(url)
.then(function(result){
$scope.details = result.data
console.log(result.data)
})
$(".user-form").val("");
$(".advanced-card").hide();
$(".related-list").hide();
}
//* Event when user clicks Advanced Search
$scope.showAdvanced = function () {
$(".advanced-card").show();
}
});