diff --git a/webpage/js/main.js b/webpage/js/main.js index 41cd967..72de79a 100644 --- a/webpage/js/main.js +++ b/webpage/js/main.js @@ -1,9 +1,14 @@ + function getUrlParameter(name) { + name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); + var regex = new RegExp('[\\?&]' + name + '=([^]*)'); + var results = regex.exec(location.search); + return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); +}; function getURLId() { var sPageURL = window.location.search.substring(1); var sParameterName = sPageURL.split('='); if (sParameterName[0] == 'id') { - console.log(sParameterName[1]); var query_id = document.getElementById('title').innerHTML = sParameterName[1]; return query_id; @@ -17,15 +22,16 @@ $(document).ready(function() { // this is the id of the form $("#searchForm").submit(function(e) { - var url = env_variables.url + 'verify/' + getURLId(); + var url = env_variables.url + 'verify/' + getUrlParameter('id'); $.ajax({ url: url, type: 'POST', success: function (data) { Materialize.toast('Verification successfully sent!', 4000); }, - error: function() { - console.log('erorr'); + error: function(data) { + console.log(data.responseJSON.error); + e.preventDefault(); // avoid to execute the actual submit of the form. } }); e.preventDefault(); // avoid to execute the actual submit of the form. @@ -41,8 +47,12 @@ function foo(id) { } } +var toType = function(obj) { + return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() +} + function getShow() { - var url = env_variables.url + getURLId(); + var url = env_variables.url + getUrlParameter('id'); $.ajax({ url: url, dataType: "json", @@ -51,14 +61,26 @@ function getShow() { $('#name').val(data['name']); $('#season').val(data['season']); $('#episode').val(data['episode']); - $('#video_files').val(data['video_files']); - $('#subtitles').val(data['subtitles']); - $('#trash').val(data['trash']); + var itemList= JSON.parse(data['video_files']); + for (item in itemList) { + $('#video_files').append('
' + itemList[item][0] + '
'); + $('#video_files').append('' + itemList[item][1] + '
'); + } + var itemList= JSON.parse(data['subtitles']); + for (item in itemList) { + $('#subtitles').append('' + itemList[item][0] + '
'); + $('#subtitles').append('' + itemList[item][1] + '
'); + } + + var itemList= JSON.parse(data['trash']); + for (item in itemList) { + $('#trash').append('' + itemList[item] + '
'); + } console.log(data); }, - error: function() { - console.log('erorr'); + error: function(data) { + console.log(data.responseJSON.error); } }); } \ No newline at end of file diff --git a/webpage/verify.html b/webpage/verify.html index 528ae36..ba93e52 100644 --- a/webpage/verify.html +++ b/webpage/verify.html @@ -38,16 +38,25 @@