nc-weather/js/admin.js

54 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-07-03 20:32:09 +00:00
/*
* Copyright (c) 2017
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
(function() {
if (!OCA.Weather) {
/**
* Namespace for the files app
* @namespace OCA.Weather
*/
OCA.Weather = {};
}
/**
* @namespace OCA.Weather.Admin
*/
OCA.Weather.Admin = {
initialize: function() {
$('#submitOWMApiKey').on('click', _.bind(this._onClickSubmitOWMApiKey, this));
},
_onClickSubmitOWMApiKey: function () {
OC.msg.startSaving('#OWMApiKeySettingsMsg');
var request = $.ajax({
url: OC.generateUrl('/apps/weather/settings/apikey'),
type: 'POST',
data: {
2017-07-03 21:12:50 +00:00
apikey: $('#openweathermap-api-key').val()
2017-07-03 20:32:09 +00:00
}
});
request.done(function (data) {
2017-07-03 21:12:50 +00:00
$('#openweathermap-api-key').val(data.apikey);
2017-07-03 20:32:09 +00:00
OC.msg.finishedSuccess('#OWMApiKeySettingsMsg', 'Saved');
});
request.fail(function () {
OC.msg.finishedError('#OWMApiKeySettingsMsg', 'Error');
});
}
}
})();
window.addEventListener('DOMContentLoaded', function () {
2017-07-03 20:32:09 +00:00
OCA.Weather.Admin.initialize();
});