]> www.vanbest.org Git - motioneye-debian/commitdiff
a bit of js config code
authorCalin Crisan <ccrisan@gmail.com>
Wed, 25 Sep 2013 14:58:09 +0000 (17:58 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Wed, 25 Sep 2013 14:58:09 +0000 (17:58 +0300)
static/js/base-site.js
templates/base-site.html

index b0172d884d878393cc915a5b00a8d64ccc4ce2a0..2c329a9649a5e118b79c7812262e02006f7688c1 100644 (file)
@@ -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('<option value="' + camera['@id'] + '">' + camera['@name'] + '</option>');
+        }
+        
+        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();
 });
index 68db0bb75e2318398be2d6c7685f8eb9e60a9e1d..42a74b528dcc3e4e5bc05b94d46ebb21d1ed8558 100644 (file)
@@ -18,8 +18,6 @@
             <div class="settings-top-bar">
                 <img class="settings-button" src="{{STATIC_URL}}img/settings.png" title="settings">
                 <select class="video-device styled" id="videoDeviceSelect">
-                    <option>USB Camera 2.0</option>
-                    <option>A4Tech Camera</option>
                 </select>
             </div>
             <div class="logo">
                         <td class="settings-item-label"><span class="settings-item-label">Video Resolution</span></td>
                         <td class="settings-item-value">
                             <select class="video-resolution styled device" id="resolutionSelect">
-                                <option>640 x 480</option>
-                                <option>1024 x 768</option>
                             </select>
                         </td>
                         <td><span class="help-mark" title="the video resolution (larger values yield better quality but require larger storage space and bandwidth)">?</span></td>