]> www.vanbest.org Git - motioneye-debian/commitdiff
added input js validators
authorCalin Crisan <ccrisan@gmail.com>
Fri, 16 Aug 2013 12:29:18 +0000 (15:29 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Fri, 16 Aug 2013 12:29:18 +0000 (15:29 +0300)
artwork/validation-error.svg [new file with mode: 0644]
static/css/base-site.css
static/css/ui.css
static/img/validation-error.png [new file with mode: 0644]
static/js/base.js
static/js/ui.js
templates/base-site.html

diff --git a/artwork/validation-error.svg b/artwork/validation-error.svg
new file mode 100644 (file)
index 0000000..c140f3b
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="20"
+   height="20"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.48.4 r9939"
+   sodipodi:docname="validation-error.svg"
+   inkscape:export-filename="/media/data/projects/motioneye/static/img/validation-error.png"
+   inkscape:export-xdpi="90"
+   inkscape:export-ydpi="90">
+  <defs
+     id="defs4" />
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="1"
+     inkscape:cx="12.498395"
+     inkscape:cy="8.3540951"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:window-width="1920"
+     inkscape:window-height="1027"
+     inkscape:window-x="0"
+     inkscape:window-y="25"
+     inkscape:window-maximized="1"
+     inkscape:snap-bbox="true"
+     inkscape:bbox-nodes="true"
+     inkscape:bbox-paths="true"
+     inkscape:snap-bbox-edge-midpoints="true"
+     inkscape:snap-bbox-midpoints="true"
+     inkscape:object-paths="true"
+     inkscape:object-nodes="true"
+     inkscape:snap-smooth-nodes="true"
+     inkscape:snap-midpoints="true"
+     inkscape:snap-object-midpoints="true"
+     inkscape:snap-center="true"
+     inkscape:snap-page="true"
+     inkscape:snap-intersection-paths="true"
+     showguides="true"
+     inkscape:guide-bbox="true" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(0,-1032.3622)">
+    <path
+       style="fill:#aa1900;fill-opacity:1;stroke:none"
+       d="M 7 3 C 3.1340068 3 0 6.1340067 0 10 C -5.9211895e-16 13.865993 3.1340068 17 7 17 C 10.865993 17 14 13.865993 14 10 C 14 6.1340067 10.865993 3 7 3 z M 6 5.25 L 8.125 5.25 L 8.125 8.625 L 7.8125 11.0625 L 6.3125 11.0625 L 6 8.625 L 6 5.25 z M 6 11.90625 L 8.125 11.90625 L 8.125 14 L 6 14 L 6 11.90625 z "
+       transform="translate(0,1032.3622)"
+       id="path3751" />
+    <g
+       style="font-size:13px;font-style:normal;font-weight:bold;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans Bold"
+       id="text3753" />
+  </g>
+</svg>
index 486a462762094d44385871d2650969bf971c691e..9e0541201fe2ac7a51014575123fdc5adb3b8cd9 100644 (file)
@@ -138,6 +138,11 @@ span.settings-item-label {
     font-size: 0.9em;
 }
 
+span.settings-item-unit {
+    font-size: 0.6em;
+    padding-left: 5px;
+}
+
 div.settings-item-separator {
     height: 1px;
     border-top: 1px solid #414141;
index 628fa5d93c3384ee51c677f2221fe6723a6e062d..61ea310b5a02be8aa19b0a67a23394040df8eea5 100644 (file)
@@ -97,7 +97,14 @@ input[type=text].styled:FOCUS {
 }
 
 input[type=text].number {
-    width: 50px;
+    width: 100px;
+}
+
+input[type=text].error,
+input[type=password].error {
+    background-image: url(../img/validation-error.png);
+    background-position: center right;
+    background-repeat: no-repeat;
 }
 
 
diff --git a/static/img/validation-error.png b/static/img/validation-error.png
new file mode 100644 (file)
index 0000000..b67d576
Binary files /dev/null and b/static/img/validation-error.png differ
index 6c3f0067e08df228594a34d113f22fbdf57dab3d..46a272a6bcb527c2593b178e359d6f009c4890dc 100644 (file)
@@ -31,6 +31,11 @@ function initUI() {
     makeSlider($('#movieQualitySlider'), 0, 100, 0, null, 5, 0, '%');
     makeSlider($('#frameChangeThresholdSlider'), 0, 10000, 0, null, 3, 0, 'px');
     makeSlider($('#noiseLevelSlider'), 0, 100, 0, null, 5, 0, '%');
+    
+    makeNumberValidator($('#snapshotIntervalEntry'), 1, 86400, false, false);
+    makeNumberValidator($('#gapEntry'), 1, 86400, false, false);
+    makeNumberValidator($('#preCaptureEntry'), 0, 100, false, false);
+    makeNumberValidator($('#postCaptureEntry'), 0, 100, false, false);
 }
 
 function handleDocumentReady() {
index 7e075cbbbf798283a360472b1e32822df5138803..769a560dcd67dffb4dfb237a80dbff474103a0bd 100644 (file)
@@ -215,255 +215,83 @@ function makeSlider($input, minVal, maxVal, snapMode, ticks, ticksNumber, decima
     return slider;
 }
 
-//function makeComboBox($select) {
-//    var container = $('<div class="combo-box-container"></div>');
-//    var buttonDiv = $('<div class="combo-box"></div>');
-//    var opened = false;
-//    var fading = false;
-//    var defaultCaption = null;
-//    var searchStr = '';
-//    
-//    container.append(buttonDiv);
-//
-//    var captionSpan = $('<span></span>');
-//    buttonDiv.append(captionSpan);
-//    buttonDiv.css('text-align', 'left');
-//    
-//    var arrowSpan = $('<span class="combo-box-arrow">&#x25BC;</span>');
-//    buttonDiv.append(arrowSpan);
-//    
-//    var itemContainer = $('<div class="combo-box-item-container"</div>');
-//    container.append(itemContainer);
-//    itemContainer.mousedown(function () {
-//        return false;
-//    });
-//    
-//    itemContainer[0].tabIndex = 0;
-//    
-//    var itemDivs = [];
-//    var captions = {};
-//    $select.find('option').each(function () {
-//        var option = $(this);
-//        var caption = option.html();
-//        var value = option.val();
-//        
-//        if (value == '') {
-//            defaultCaption = caption;
-//        }
-//        
-//        var itemDiv = $('<div class="combo-box-item">' + caption + '<div>');
-//        itemContainer.append(itemDiv);
-//        
-//        itemDiv.click(function () {
-//            setSelectedValue(value);
-//            close();
-//        });
-//        itemDiv.mouseover(function () {
-//            selectItemDiv(itemDiv);
-//        });
-//        
-//        itemDiv[0]._value = value;
-//        
-//        itemDivs.push(itemDiv);
-//        captions[value] = caption;
-//    });
-//    
-//    $select.after(container);
-//    buttonDiv.width(itemContainer.width() - 12);
-//    
-//    $select.change(function () {
-//        setSelectedValue($select.val(), true);
-//    }).change();
-//    
-//    function setSelectedValue(value, skipSelect) {
-//        var caption = captions[value];
-//        if (caption == null) {
-//            if (defaultCaption == null) {
-//                return;
-//            }
-//            caption = defaultCaption;
-//        }
-//        captionSpan.html(caption);
-//        if (!skipSelect) {
-//            $select.val(value);
-//        }
-//        
-//        var itemDiv = getItemDivByValue(value);
-//        if (itemDiv) {
-//            selectItemDiv(itemDiv);
-//        }
-//    }
-//    
-//    function handleKeyDown(e) {
-//        if (e.which == 13) { /* enter */
-//            var itemDiv = itemContainer.find('div.combo-box-item-selected');
-//            if (!itemDiv.length) {
-//                return;
-//            }
-//            
-//            var value = getValueByItemDiv(itemDiv);
-//            setSelectedValue(value);
-//            close();
-//        }
-//        else if (e.which == 8) { /* backspace */
-//            if (searchStr.length) {
-//                searchStr = searchStr.substring(0, searchStr.length - 1);
-//            }
-//        }
-//        else if (e.which == 27) { /* escape */
-//            close();
-//        }
-//        else if (e.which == 38) { /* up */
-//            selectPrev();
-//            return false;
-//        }
-//        else if (e.which == 40) { /* down */
-//            selectNext();
-//            return false;
-//        }
-//    }
-//    
-//    function handleKeyPress(e) {
-//        searchStr += String.fromCharCode(e.which).toLowerCase();
-//        
-//        itemContainer.find('div.combo-box-item').each(function () {
-//            var itemDiv = $(this);
-//            if (itemDiv.text().toLowerCase().startsWith(searchStr)) {
-//                selectItemDiv(itemDiv, true);
-//                return false;
-//            }
-//        });
-//    }
-//    
-//    function getValueByItemDiv(itemDiv) {
-//        return itemDiv[0]._value;
-//    }
-//    
-//    function getItemDivByValue(value) {
-//        for (var i = 0; i < itemDivs.length; i++) {
-//            var itemDiv = itemDivs[i];
-//            if (itemDiv[0]._value == value) {
-//                return itemDiv;
-//            }
-//        }
-//        
-//        return null;
-//    }
-//    
-//    function selectPrev() {
-//        var prevItemDiv = null;
-//        var itemDiv = itemContainer.find('div.combo-box-item-selected');
-//        if (!itemDiv.length) {
-//            prevItemDiv = itemDivs.slice(-1)[0];
-//        }
-//        else {
-//            for (var i = 0; i < itemDivs.length; i++) {
-//                if (i > 0 && itemDiv[0] == itemDivs[i][0]) {
-//                    prevItemDiv = itemDivs[i - 1];
-//                    break;
-//                }
-//            }
-//        }
-//        
-//        if (prevItemDiv) {
-//            selectItemDiv(prevItemDiv, true);
-//        }
-//        
-//        searchStr = '';
-//    }
-//    
-//    function selectNext() {
-//        var nextItemDiv = null;
-//        var itemDiv = itemContainer.find('div.combo-box-item-selected');
-//        if (!itemDiv.length) {
-//            nextItemDiv = itemDivs[0];
-//        }
-//        else {
-//            for (var i = 0; i < itemDivs.length; i++) {
-//                if (i < itemDivs.length - 1 && itemDiv[0] == itemDivs[i][0]) {
-//                    nextItemDiv = itemDivs[i + 1];
-//                    break;
-//                }
-//            }
-//        }
-//        
-//        if (nextItemDiv) {
-//            selectItemDiv(nextItemDiv, true);
-//        }
-//        
-//        searchStr = '';
-//    }
-//    
-//    function selectItemDiv(itemDiv, scroll) {
-//        var oldItemDiv = itemContainer.find('div.combo-box-item-selected');
-//        if (oldItemDiv.length == 0 || oldItemDiv[0] !== itemDiv[0]) {
-//            oldItemDiv.removeClass('combo-box-item-selected');
-//            itemDiv.addClass('combo-box-item-selected');
-//        }
-//        
-//        if (scroll) {
-//            var scrollTop = itemDiv.offset().top - itemContainer.offset().top + itemContainer.scrollTop();
-//            itemContainer.scrollTop(scrollTop);
-//        }
-//    }
-//    
-//    function open() {
-//        buttonDiv.unlock();
-//        buttonDiv.setActive();
-//        buttonDiv.lock();
-//        opened = true;
-//        itemContainer.css('opacity', '0');
-//        itemContainer.css('left', '0px');
-//        fading = true;
-//        itemContainer.animate({'opacity': '1'}, Reshaped.Forms.ANIM_DELAY, function () {
-//            fading = false;
-//        });
-//        //arrowSpan.html('&#x25B2;');
-//        
-//        $('html').mousedown(close);
-//        $('html').keydown(handleKeyDown);
-//        $('html').keypress(handleKeyPress);
-//        
-//        itemContainer.focus();
-//        searchStr = '';
-//
-//        var itemDiv = getItemDivByValue(select.val());
-//        if (itemDiv) {
-//            selectItemDiv(itemDiv, true);
-//        }
-//    }
-//    
-//    function close() {
-//        buttonDiv.unlock();
-//        buttonDiv.setNormal();
-//        //arrowSpan.html('&#x25BC;');
-//        opened = false;
-//        fading = true;
-//        itemContainer.animate({'opacity': '0'}, Reshaped.Forms.ANIM_DELAY, function () {
-//            itemContainer.css('left', '-9999px');
-//            fading = false;
-//        });
-//        
-//        $('html').unbind('mousedown', close);
-//        $('html').unbind('keydown', handleKeyDown);
-//        $('html').unbind('keypress', handleKeyPress);
-//        searchStr = '';
-//    }
-//    
-//    buttonDiv.click(function () {
-//        if (fading) {
-//            return;
-//        }
-//        
-//        if (opened) {
-//            close();
-//        }
-//        else {
-//            open();
-//        }
-//        
-//        return false;
-//    });
-//    
-//    return container;
-//}
+function makeNumberValidator($input, minVal, maxVal, floating, sign, required) {
+    if (minVal == null) {
+        minVal = -Infinity;
+    }
+    if (maxVal == null) {
+        maxVal = Infinity;
+    }
+    if (floating == null) {
+        floating = false;
+    }
+    if (sign == null) {
+        sign = false;
+    }
+    if (required == null) {
+        required = true;
+    }
+    
+    function isValid(strVal) {
+        if (strVal.length === 0 && !required) {
+            return true;
+        }
+        
+        var numVal = parseInt(strVal);
+        if ('' + numVal != strVal) {
+            return false;
+        }
+        
+        if (numVal < minVal || numVal > maxVal) {
+            return false;
+        }
+        
+        if (!sign && numVal < 0) {
+            return false;
+        }
+        
+        return true;
+    }
+    
+    var msg = '';
+    if (!sign) {
+        msg = 'enter a positive';
+    }
+    else {
+        msg = 'enter a'
+    }
+    if (floating) {
+        msg += ' number';
+    }
+    else {
+        msg += ' integer number';
+    }
+    if (isFinite(minVal)) {
+        if (isFinite(maxVal)) {
+            msg += ' between ' + minVal + ' and ' + maxVal;
+        }
+        else {
+            msg += ' greater than ' + minVal;
+        }
+    }
+    else {
+        if (isFinite(maxVal)) {
+            msg += ' smaller than ' + maxVal;
+        }
+    }
+    
+    function validate() {
+        var strVal = $input.val();
+        if (isValid(strVal)) {
+            $input.attr('title', '');
+            $input.removeClass('error');
+        }
+        else {
+            $input.attr('title', msg);
+            $input.addClass('error');
+        }
+    }
+    
+    $input.keyup(validate);
+    $input.change(validate);
+}
index 35811e325c5546d03a3ce36fa28a6b6d2849df0e..baddc6b1abf9927aa2b544a9fe8a1964aa0fb463 100644 (file)
                     </tr>
                     <tr class="advanced-setting">
                         <td class="settings-item-label"><span class="settings-item-label">Snapshot Interval</span></td>
-                        <td class="settings-item-value"><input type="text" class="styled number still-images" id="snapshotIntervalEntry"></td>
+                        <td class="settings-item-value"><input type="text" class="styled number still-images" id="snapshotIntervalEntry"><span class="settings-item-unit">seconds</span></td>
                         <td><span class="help-mark" title="sets the interval (in seconds) for the automated snapshots">?</span></td>
                     </tr>
                     <tr>
                     </tr>
                     <tr class="advanced-setting">
                         <td class="settings-item-label"><span class="settings-item-label">Motion Gap</span></td>
-                        <td class="settings-item-value"><input type="text" class="number styled motion-detection" id="gapEntry"></td>
+                        <td class="settings-item-value"><input type="text" class="number styled motion-detection" id="gapEntry"><span class="settings-item-unit">seconds</span></td>
                         <td><span class="help-mark" title="sets the number of seconds of silence (i.e. no motion) that mark the end of a motion event">?</span></td>
                     </tr>
                     <tr class="advanced-setting">
-                        <td class="settings-item-label"><span class="settings-item-label">Frames Captured Before</span></td>
-                        <td class="settings-item-value"><input type="text" class="number styled motion-detection" id="preCaptureEntry"></td>
+                        <td class="settings-item-label"><span class="settings-item-label">Captured Before</span></td>
+                        <td class="settings-item-value"><input type="text" class="number styled motion-detection" id="preCaptureEntry"><span class="settings-item-unit">frames</span></td>
                         <td><span class="help-mark" title="sets the number of frames to be captured (and included in the movie) before a motion event is detected">?</span></td>
                     </tr>
                     <tr class="advanced-setting">
-                        <td class="settings-item-label"><span class="settings-item-label">Frames Captured After</span></td>
-                        <td class="settings-item-value"><input type="text" class="number styled motion-detection" id="postCaptureEntry"></td>
+                        <td class="settings-item-label"><span class="settings-item-label">Captured After</span></td>
+                        <td class="settings-item-value"><input type="text" class="number styled motion-detection" id="postCaptureEntry"><span class="settings-item-unit">frames</span></td>
                         <td><span class="help-mark" title="sets the number of frames to be captured (and included in the movie) after a motion event is detected">?</span></td>
                     </tr>
                 </table>