|
72 | 72 | // Insert Ajax loader icon |
73 | 73 | $('<div id="ajax-loader-container"><img src="http://mics.fim.uni-passau.de/wp-content/uploads/2014/10/ajax-loader.gif" width="16px" height="16px" alt="ajax loader"/></div>').insertAfter("#eexcess-recommendations-list"); |
74 | 74 |
|
| 75 | + var responded = false; |
| 76 | + var timeout = false; |
| 77 | + |
| 78 | + setTimeout(function() { |
| 79 | + if(!responded) { |
| 80 | + timeout = true; |
| 81 | + removeAjaxLoader(); |
| 82 | + showError("The server timed out waiting for the request.", $('#button-bar')); |
| 83 | + $('#get-recommendations').removeAttr("disabled"); |
| 84 | + } |
| 85 | + }, 20000); |
| 86 | + |
75 | 87 | google.script.run |
76 | 88 | .withSuccessHandler( |
77 | 89 | function(recommendations, element) { |
78 | | - |
79 | | - removeAjaxLoader(); |
80 | | - var container = $("#eexcess-recommendations-list"); |
81 | | - // Parsing the JSON string |
82 | | - var o = JSON.parse(recommendations); |
| 90 | + if(!timeout) { |
| 91 | + responded = true; |
| 92 | + removeAjaxLoader(); |
| 93 | + var container = $("#eexcess-recommendations-list"); |
| 94 | + // Parsing the JSON string |
| 95 | + var o = JSON.parse(recommendations); |
83 | 96 |
|
84 | | - if(o.totalResults > 0) { |
85 | | - // iterate the results and append the list elements |
86 | | - $.each(o.result, function() { |
87 | | - container.append("<li><a href='" + this.uri + "' target='_blank'>" + this.title + "</a></li>"); |
88 | | - }) |
89 | | - } else { |
90 | | - showError("No results found", $('#button-bar')); |
| 97 | + if(o.totalResults > 0) { |
| 98 | + // iterate the results and append the list elements |
| 99 | + $.each(o.result, function() { |
| 100 | + container.append("<li><a href='" + this.uri + "' target='_blank'>" + this.title + "</a></li>"); |
| 101 | + }) |
| 102 | + } else { |
| 103 | + showError("No results found", $('#button-bar')); |
| 104 | + } |
| 105 | + element.disabled = false; |
91 | 106 | } |
92 | | - |
93 | | - element.disabled = false; |
94 | 107 | }) |
95 | 108 | .withFailureHandler( |
96 | 109 | function(msg, element) { |
97 | | - removeAjaxLoader(); |
98 | | - showError(msg, $('#button-bar')); |
99 | | - element.disabled = false; |
| 110 | + if(!timeout) { |
| 111 | + removeAjaxLoader(); |
| 112 | + showError(msg, $('#button-bar')); |
| 113 | + element.disabled = false; |
| 114 | + } |
100 | 115 | }) |
101 | 116 | .withUserObject(this) |
102 | 117 | .getRecommendations(); |
|
0 commit comments