erroneous cameras can now be disabled using the UI switch
authorCalin Crisan <ccrisan@gmail.com>
Sat, 11 Jan 2014 17:09:55 +0000 (19:09 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 11 Jan 2014 17:09:55 +0000 (19:09 +0200)
src/handlers.py
static/css/base.css [deleted file]
static/css/main.css
static/js/base.js [deleted file]
static/js/main.js
templates/base.html

index fe48233532da0a9390df9964a50bb9d28cc60d10..9cd5a4ec16630a85543ccad33b4b68ca78bae4d6 100644 (file)
@@ -251,25 +251,32 @@ class ConfigHandler(BaseHandler):
                 camera_config['@enabled'] = ui_config['enabled']
                 config.set_camera(camera_id, camera_config)
                 
-                # remove the fields that should not get to the remote side
-                del ui_config['device']
-                del ui_config['proto']
-                del ui_config['enabled']
-                
-                try:
-                    remote.set_config(
-                            camera_config.get('@host'),
-                            camera_config.get('@port'),
-                            camera_config.get('@username'),
-                            camera_config.get('@password'),
-                            camera_config.get('@remote_camera_id'),
-                            ui_config)
-                    
-                except Exception as e:
-                    logging.error('failed to set remote camera config: %(msg)s' % {'msg': unicode(e)})
+                # when the camera_config supplied has only the enabled state,
+                # the camera was probably disabled due to errors
+
+                if camera_config.has_key('device'):
+                    # remove the fields that should not get to the remote side
+                    del ui_config['device']
+                    del ui_config['proto']
+                    del ui_config['enabled']
                     
-                    if not no_finish:
-                        return self.finish_json({'error': unicode(e)})       
+                    try:
+                        remote.set_config(
+                                camera_config.get('@host'),
+                                camera_config.get('@port'),
+                                camera_config.get('@username'),
+                                camera_config.get('@password'),
+                                camera_config.get('@remote_camera_id'),
+                                ui_config)
+                        
+                    except Exception as e:
+                        logging.error('failed to set remote camera config: %(msg)s' % {'msg': unicode(e)})
+                        
+                        if not no_finish:
+                            return self.finish_json({'error': unicode(e)})
+                
+                elif not no_finish:
+                    return self.finish_json({'error': unicode(e)})       
 
         else:
             logging.debug('setting main config')
diff --git a/static/css/base.css b/static/css/base.css
deleted file mode 100644 (file)
index a50ba03..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-    /* basic */
-
-* {
-    padding: 0px;
-    border: 0px solid black;
-    margin: 0px;
-    outline: 0px;
-    border-spacing: 0px;
-    border-collapse: separate;
-}
-
-html {
-    height: 100%;
-}
-
-body {
-    height: 100%;
-    color: #dddddd;
-    font-size: 22px;
-    background-color: #212121;
-}
-
index 6d14543f236c7b9c232c3e7e93c107e205c2119a..32812e291dab5ba2043874d413c89cbe2d4f6395 100644 (file)
@@ -1,5 +1,28 @@
 
 
+    /* basic */
+
+* {
+    padding: 0px;
+    border: 0px solid black;
+    margin: 0px;
+    outline: 0px;
+    border-spacing: 0px;
+    border-collapse: separate;
+}
+
+html {
+    height: 100%;
+}
+
+body {
+    height: 100%;
+    color: #dddddd;
+    font-size: 22px;
+    background-color: #212121;
+}
+
+
     /* fonts */
 
 @font-face {
diff --git a/static/js/base.js b/static/js/base.js
deleted file mode 100644 (file)
index e69de29..0000000
index dc383b0c862fb5e0b6ae3e3dcc26d6b7bf1bb6b9..00dd7eeb3f0660807fd9f5fa0e85ac5f59551aa4 100644 (file)
@@ -342,13 +342,15 @@ function updateConfigUi() {
         objs.not($('#motionEyeSwitch').parents('div').get(0)).each(markHide);
     }
     
-    if (($('#videoDeviceSelect').find('option').length < 2) /* no camera configured */ || 
-        $('#videoDeviceSwitch')[0].disabled /* device disabled for some reason (config error) */) {
-        
+    if ($('#videoDeviceSelect').find('option').length < 2) { /* no camera configured */
         $('#videoDeviceSwitch').parent().each(markHide);
         $('#videoDeviceSwitch').parent().nextAll('div.settings-section-title, table.settings').each(markHide);
     }
     
+    if ($('#videoDeviceSwitch')[0].error) { /* config error */
+        $('#videoDeviceSwitch').parent().nextAll('div.settings-section-title, table.settings').each(markHide);
+    }
+        
     /* advanced settings */
     var showAdvanced = $('#showAdvancedSwitch').get(0).checked;
     if (!showAdvanced) {
@@ -500,6 +502,12 @@ function dict2MainUi(dict) {
 }
 
 function cameraUi2Dict() {
+    if ($('#videoDeviceSwitch')[0].error) { /* config error */
+        return {
+            'enabled': $('#videoDeviceSwitch')[0].checked,
+        };
+    }
+    
     var dict = {
         /* video device */
         'enabled': $('#videoDeviceSwitch')[0].checked,
@@ -601,13 +609,16 @@ function cameraUi2Dict() {
 
 function dict2CameraUi(dict) {
     if (dict == null) {
-        $('#videoDeviceSwitch')[0].disabled = true;
+        /* errors while getting the configuration */
+        
+        $('#videoDeviceSwitch')[0].error = true;
+        $('#videoDeviceSwitch')[0].checked = true;
         updateConfigUi();
         
         return;
     }
     else {
-        $('#videoDeviceSwitch')[0].disabled = false;
+        $('#videoDeviceSwitch')[0].error = false;
     }
     
     /* video device */
@@ -919,8 +930,9 @@ function fetchCurrentConfig(onFetch) {
                 }
                 videoDeviceSelect.append('<option value="add">add camera...</option>');
                 
-                if (cameras.length > 0) {
-                    videoDeviceSelect[0].selectedIndex = 0;
+                var enabledCameras = cameras.filter(function (camera) {return camera['enabled'];});
+                if (enabledCameras.length > 0) {
+                    videoDeviceSelect[0].selectedIndex = cameras.indexOf(enabledCameras[0]);
                     fetchCurrentCameraConfig();
                 }
                 else {
index ddab2afaefdb6b00fc2f718e719f064771ec04f1..085a04719943f0008040038ff99576320dce84df 100644 (file)
@@ -9,7 +9,6 @@
         <title>{% block title %}{% endblock %}</title>
         {% block style %}
             <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}css/jquery.timepicker.css" />
-            <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}css/base.css" />
             <link rel="shortcut icon" href="/static/img/favicon.ico" />
         {% endblock %}
         {% block script %}
@@ -17,7 +16,6 @@
             <script type="text/javascript" src="{{STATIC_URL}}js/jquery.min.js"></script>
             <script type="text/javascript" src="{{STATIC_URL}}js/jquery.timepicker.min.js"></script>
             <script type="text/javascript" src="{{STATIC_URL}}js/jquery.mousewheel.js"></script>
-            <script type="text/javascript" src="{{STATIC_URL}}js/base.js"></script>
             
             <script type="text/javascript">
                 var staticUrl = '{{STATIC_URL}}';