From: Calin Crisan Date: Wed, 25 Sep 2013 14:58:09 +0000 (+0300) Subject: a bit of js config code X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=7a91b8c32eea1911777b091902bc0918114560fd;p=motioneye-debian a bit of js config code --- diff --git a/static/js/base-site.js b/static/js/base-site.js index b0172d8..2c329a9 100644 --- a/static/js/base-site.js +++ b/static/js/base-site.js @@ -1,4 +1,22 @@ + + /* Ajax */ + +function ajax(method, url, data, success) { + $.ajax({ + type: method, + url: url, + data: data, + success: success, + failure: function (request, options, error) { + alert('Request failed with code: ' + request.status); + } + }); +} + + + /* UI */ + function initUI() { $('input[type=checkbox].styled').each(function () { makeCheckBox($(this)); @@ -67,6 +85,8 @@ function initUI() { $('#motionMoviesSwitch').change(updateSettingsUI); $('#motionNotificationsSwitch').change(updateSettingsUI); $('#workingScheduleSwitch').change(updateSettingsUI); + + $('#videoDeviceSwitch').change(fetchCameraSettings); } function updateSettingsUI() { @@ -170,6 +190,43 @@ function updateSettingsUI() { }); } +function cameraUi2Dict() { + +} + +function dict2CameraUi(dict) { + +} + +function fetchCurrentConfig() { + ajax('GET', '/config/list/', null, function (data) { + var i, cameras = data.cameras; + var videoDeviceSelect = $('#videoDeviceSelect'); + videoDeviceSelect.html(''); + for (i = 0; i < cameras.length; i++) { + var camera = cameras[i]; + videoDeviceSelect.append(''); + } + + if (cameras.length) { + videoDeviceSelect[0].selectedIndex = 0; + fetchCameraSettings(); + } + }); +} + +function fetchCameraSettings() { + var cameraId = $('#videoDeviceSelect').val(); + if (cameraId != null) { + ajax('GET', '/config/' + cameraId + '/get/', null, function (data) { + dict2CameraUi(data); + }); + } + else { + dict2CameraUi({}); + } +} + $(document).ready(function () { /* open/close settings */ $('img.settings-button').click(function () { @@ -198,4 +255,5 @@ $(document).ready(function () { initUI(); updateSettingsUI(); + fetchCurrentConfig(); }); diff --git a/templates/base-site.html b/templates/base-site.html index 68db0bb..42a74b5 100644 --- a/templates/base-site.html +++ b/templates/base-site.html @@ -18,8 +18,6 @@