ReceiptRptCriteria

by Jake Wolpert

HTML

<h1>Receipt Report Criteria</h1>
<form>
    <fieldset>
        <legend>Date Range</legend>
        <label for="BeginDate" class="staticLabel">Begin Date</label>
        <input id="BeginDate" />
        <label for="BeginTime" class="staticLabel">Begin Time</label>
        <input id="BeginTime" />
        <br/>
        <label for="EndDate" class="staticLabel">End Date</label>
        <input id="EndDate" />
        <label for="EndTime" class="staticLabel">End Time</label>
        <input id="EndTime" />
    </fieldset>
        <br/>
        <label for="UPC" class="staticLabel">UPC Starts with</label>
        <input id="UPC" />
        <br/>
        <br/>
        <div id="accordion">
            <h3 id="deptHeader">Departments( <span>all selected by default</span>)</h3>
            <div id="depts" class="checkboxGroups4Col">
            </div>
            <h3 id="sitesHeader">Sites ( <span>all selected by default </span>)</h3>
            <div id="sites" class="checkboxGroups4Col">
           </div>
        </div>
        <br/>
        <input type="button" class="submitButton" value="ViewButton" id="submitButton" />
</form>

CSS

h1 {
    color: chocolate;
    font-family:'Segoe UI Light';
}
body {
    background-color: oldlace;
}
form {
    background-color: antiquewhite;
}
legend {
    font-family:'Century Gothic', Verdana, Georgia, sans-serif;
    font-size: 1.2em;
    color: navy;
}
.staticLabel {
    display: inline-block;
    width: 140px;
    margin-right: 2px;
    text-align: right;
    font-family: Consolas, Candara, sans-serif;
}
.checkboxGroups1Col { width: 200px; margin-bottom: 10px; border: 1px solid chocolate; }
.checkboxGroups2Col { width: 400px; margin-bottom: 10px; border: 1px solid chocolate; }
.checkboxGroups3Col { width: 600px; margin-bottom: 10px; border: 1px solid chocolate; }
.checkboxGroups4Col { width: 800px; margin-bottom: 10px; border: 1px solid chocolate; }
.checkboxGroups5Col { width: 1000px; margin-bottom: 10px; border: 1px solid chocolate; }
label { display: inline-block; width: 200px; }

#depts, #sites {
    min-height: 200px;
}
.submitButton {
    background-color: SkyBlue;
    color: white;
    font-size: 1.2em;
    margin-top: 15px;
}

JavaScript

// plugin code for creating list of checkboxes with "select all" and "deselect all" buttons
// created primarily by Brad Christie (http://stackoverflow.com/questions/17754047/is-there-a-jquery-plugin-that-will-populate-an-element-with-an-array-of-checkbox) and "Jake Cigar" (http://jsfiddle.net/jakecigar/ktPWK/7/)
(function ($) {
    $.fn.extend({
        appendAllCheck: function () {
            var selectors = $('<div class="selectors"></div>').appendTo(this)
                .append('<button>Select all</button><button>Deselect all</button>');
            selectors.find('button').click(function () {
                var checked = $(this).text() == 'Select all';
                $(this).closest('.selectors').parent()
                    .find('[name]:checkbox').prop('checked', checked);
                $(this).prop('checked', false);
                return false;
            });
            return this;
        },
        appendCheckboxes: function (name, labels) {
            var container = this;
            $.each(labels, function (i, l) {
                var label = $.isPlainObject(labels) ? i : l,
                    value = $.isPlainObject(labels) ? l : i;
                $('<label>').append(
                $('<input>', {
                    'type': 'checkbox',
                        'name': name
                }).val(value),
                label).appendTo(container);
            });
            return this;
        },
        checkedBoxes: function () {
            return this.find(':checked').map(function () {
                return $(this).parent().text();
            }).get();
        }
    });
})(jQuery);

var deptsArray = [];
for (var i = 2; i < 100; i++) {
    deptsArray.push(i);
}

var sitesArray = [];
for (var i = 1; i < 7; i++) {
    sitesArray.push(i);
}

$('#BeginDate, #EndDate').datepicker();
$('#accordion').accordion();
$('button').button();
$('#depts').appendAllCheck().appendCheckboxes('deptsCheckboxList',...