import _ from 'underscore';


let getPercentOrText = function(txt) {
        if (txt == null) return '';
        if (_.isFinite(txt)) txt = txt.toString();
        if (txt.search && txt.search(/(\d)+/) >= 0) txt += '%';
        return txt;
    },
    typeaheadSelectListGetLIs = function($ul) {
        return _.map(
            $ul.find('li'),
            function(li){return li.getAttribute('data-value');});
    },
    getValue = function(inp) {
        var val = undefined,
            $el,
            results = [];

        // special case for our multi-select list object
        if ($(inp).hasClass('multiSelectList')) {
            $el = $(inp).parent().next();
            return typeaheadSelectListGetLIs($el);
        }

        // special case for single-reference selector
        if ($(inp).hasClass('referenceSingleSelect')) {
            $el = $(inp).parent().next();
            return $el.find('p').data('id');
        }

        // special case for multiple-reference selector
        if ($(inp).hasClass('referenceMultiSelect')) {
            $el = $(inp).parent().next();
            $el.find('li').each(function(i, li){
                results.push($(li).data('id'));
            });
            return results;
        }

        // otherwise it's a standard html input
        val = undefined;
        switch (inp.type) {
        case 'text':
        case 'hidden':
        case 'textarea':
        case 'url':
            val = inp.value.trim();
            if (val.length === 0) val = null;
            break;
        case 'number':
            val = parseFloat(inp.value, 10);
            if (isNaN(val)) val = null;
            break;
        case 'checkbox':
            val = inp.checked;
            break;
        case 'select-one':
            val = $(inp).find('option:selected').val();
            break;
        default:
            console.log('input not recognized');
        }
        return val;
    },
    newValues = function(form) {
        var obj = {}, key;
        $(form).find('select,input,textarea').each(function(i, inp){
            key = inp.name;
            if (key.length > 0) obj[key] = getValue(inp);
        });
        return obj;
    },
    capitalizeFirst = function(str){
        if ((str != null) && str.length > 0) {
            str = str[0].toUpperCase() + str.slice(1);
        }
        return str;
    };


export { getPercentOrText };
export { typeaheadSelectListGetLIs };
export { getValue };
export { newValues };
export { capitalizeFirst };

@@ -2360,16 +2360,1962 @@
 rn str;%0A
+    %7D,%0A    tabularizeHeader = function(schema, idName, omissions)%7B%0A        /*%0A        Return a header of object based on schema.%0A%0A        * @param %7Bobject%7D schema A simple-schema instance%0A        * @param %7Bstring%7D idName Name for id field%0A        * @param %7Bstring%5B%5D%7D omissions Simple-schema keys that should not be included%0A%0A        The header consists of all fields in the schema which:%0A%0A            1) include a label field in the schema%0A            2) schema key has an $ (indicates an array field)%0A            3) are not in the omissions array%0A%0A        In addition, the _id field is listed as the first index in the header,%0A        using the idName specified.%0A        */%0A        let header = _.chain(schema)%0A            .pairs()%0A            .reject((d) =%3E _.isUndefined(d%5B1%5D.label))%0A            .reject((d) =%3E d%5B0%5D.indexOf('$')%3E=0)%0A            .reject((d) =%3E _.contains(omissions, d%5B0%5D))%0A            .map((d) =%3E %7Bconsole.log(d%5B0%5D); return d%5B1%5D.label;%7D)%0A            .value();%0A%0A        if(idName)%7B%0A            header.unshift(idName);%0A        %7D%0A%0A        return header;%0A    %7D,%0A    tabularize = function(obj, schema, omissions, overrides)%7B%0A        /*%0A        Return a row of data based on an object instance and schema.%0A%0A        * @param %7Bobject%7D obj An object instance%0A        * @param %7Bobject%7D schema A simple-schema instance for this object%0A        * @param %7Bstring%5B%5D%7D omissions Simple-schema keys that should not be included%0A        * @param %7Bobject%7D overrides Override function for data presentation in tab%0A%0A        */%0A        let data = _.chain(schema)%0A            .pairs()%0A            .reject((d) =%3E _.isUndefined(d%5B1%5D.label))%0A            .reject((d) =%3E d%5B0%5D.indexOf('$')%3E=0)%0A            .reject((d) =%3E _.contains(omissions, d%5B0%5D))%0A            .map((d) =%3E d%5B0%5D)%0A            .map((k) =%3E (overrides%5Bk%5D)? overrides%5Bk%5D(obj): obj%5Bk%5D)%0A            .value();%0A%0A        if(obj._id)%7B%0A            data.unshift(obj._id);%0A        %7D%0A%0A        return data;%0A
     %7D;%0A%0A
@@ -4449,12 +4449,64 @@
 izeFirst %7D;%0A
+export %7B tabularizeHeader %7D;%0Aexport %7B tabularize %7D;%0A

create tabularize utility methods