From f086729b97175140fd4ff54ba8a099d6199e9665 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Mon, 3 Jul 2017 22:32:09 +0200 Subject: [PATCH] Add missing JS --- js/admin.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 js/admin.js diff --git a/js/admin.js b/js/admin.js new file mode 100644 index 0000000..e911176 --- /dev/null +++ b/js/admin.js @@ -0,0 +1,53 @@ +/* + * 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: { + apiKey: $('#openweathermap-api-key').val() + } + }); + + request.done(function (data) { + $('#openweathermap-api-key').val(data.apiKey); + OC.msg.finishedSuccess('#OWMApiKeySettingsMsg', 'Saved'); + }); + + request.fail(function () { + OC.msg.finishedError('#OWMApiKeySettingsMsg', 'Error'); + }); + } + } +})(); + +$(document).ready(function() { + OCA.Weather.Admin.initialize(); +});