| OLD | NEW |
| 1 // Copyright 2014 The Swarming Authors. All rights reserved. | 1 // Copyright 2014 The Swarming Authors. All rights reserved. |
| 2 // Use of this source code is governed by the Apache v2.0 license that can be | 2 // Use of this source code is governed by the Apache v2.0 license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var config_page = (function() { | 5 var config_page = (function() { |
| 6 var exports = {}; | 6 var exports = {}; |
| 7 | 7 |
| 8 | 8 |
| 9 // Fetches the importer config from the server. | 9 // Fetches the importer config from the server. |
| 10 var readImporterConfig = function() { | 10 var readImporterConfig = function() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // Show alert box with operation result, enable back UI. | 24 // Show alert box with operation result, enable back UI. |
| 25 var showResult = function(type, title, message) { | 25 var showResult = function(type, title, message) { |
| 26 $('#import-config-alerts').html( | 26 $('#import-config-alerts').html( |
| 27 common.getAlertBoxHtml(type, title, message)); | 27 common.getAlertBoxHtml(type, title, message)); |
| 28 common.setInteractionDisabled($('#import-config'), false); | 28 common.setInteractionDisabled($('#import-config'), false); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 // Handle 'Save' button. | 31 // Handle 'Save' button. |
| 32 $('#import-config').submit(function(event) { | 32 $('#import-config').submit(function(event) { |
| 33 event.preventDefault(); | 33 event.preventDefault(); |
| 34 var config = null; | 34 var config = $('#import-config textarea[name="config"]').val(); |
| 35 try { | |
| 36 config = JSON.parse($('#import-config textarea[name="config"]').val()) | |
| 37 } catch(err) { | |
| 38 showResult('error', 'Bad JSON.', err.message); | |
| 39 return; | |
| 40 } | |
| 41 common.setInteractionDisabled($('#import-config'), true); | 35 common.setInteractionDisabled($('#import-config'), true); |
| 42 writeImporterConfig({'config': config}).then(function(response) { | 36 writeImporterConfig({'config': config}).then(function(response) { |
| 43 showResult('success', 'Config updated.'); | 37 showResult('success', 'Config updated.'); |
| 44 }, function(error) { | 38 }, function(error) { |
| 45 showResult('error', 'Oh snap!', error.text); | 39 showResult('error', 'Oh snap!', error.text); |
| 46 }); | 40 }); |
| 47 }); | 41 }); |
| 48 | 42 |
| 49 | 43 |
| 50 // Read the config, show the page only when it's available. | 44 // Read the config, show the page only when it's available. |
| 51 readImporterConfig().then(function(response) { | 45 readImporterConfig().then(function(response) { |
| 52 var str = JSON.stringify(response.data['config'], undefined, 2); | 46 $('#import-config textarea[name="config"]').val(response.data['config']); |
| 53 $('#import-config textarea[name="config"]').val(str); | |
| 54 common.presentContent(); | 47 common.presentContent(); |
| 55 }, function(error) { | 48 }, function(error) { |
| 56 common.presentError(error.text); | 49 common.presentError(error.text); |
| 57 }); | 50 }); |
| 58 }; | 51 }; |
| 59 | 52 |
| 60 | 53 |
| 61 return exports; | 54 return exports; |
| 62 }()); | 55 }()); |
| OLD | NEW |