         fn = share.evidenceType[key].excel_fn
         Meteor.call method, tbl_id, (err, response) ->
             share.returnExcelFile(response, fn)
+
+share.abstractRowHelpers =
+
+    getChildren: ->
+        key = Session.get('evidenceType')
+        NestedCollection = share.evidenceType[key].nested_collection
+        return NestedCollection.find({parent_id: @_id}, {sort: {sortIdx: 1}})
 
 share.abstractRowEvents =
 

Session.setDefault('evidenceShowNew', false)
Session.setDefault('evidenceEditingId', null)
Session.setDefault('evidenceShowAll', false)
Session.setDefault('evidenceType', null)


        collection_name = share.evidenceType[key].collection_name
        Meteor.call 'adminToggleQAd', this._id, collection_name, (err, response) ->
            if response then share.toggleQA(tmpl, response.QAd)

share.abstractNestedTableHelpers =

    showRow: (isHidden) ->
        Session.get('evidenceShowAll') or !isHidden

share.abstractNestedTableEvents =

    'click #inner-show-edit': (evt, tmpl) ->
        div = tmpl.find('#nestedModalHolder')
        key = Session.get('evidenceType')
        NestedTemplate = share.evidenceType[key].nested_template
        Session.set('nestedEvidenceEditingId', tmpl.data._id)
        Blaze.renderWithData(NestedTemplate, {}, div)

    'click #inner-toggle-hidden': (evt, tmpl) ->
        key = Session.get('evidenceType')
        NestedCollection = share.evidenceType[key].nested_collection
        data = tmpl.view.parentView.dataVar.curValue
        NestedCollection.update(data._id, {$set: {isHidden: !data.isHidden}})

    'click #inner-copy-as-new': (evt, tmpl) ->
        key = Session.get('evidenceType')
        NestedTemplate = share.evidenceType[key].nested_template
        data = tmpl.view.parentView.dataVar.curValue
        data.parent = {_id: data.parent_id}
        div = tmpl.find('#nestedModalHolder')
        Blaze.renderWithData(NestedTemplate, data, div)

share.abstractNestedFormHelpers =

    isNew: ->
        return Session.get('nestedEvidenceEditingId') is null

    getObject: () ->
        # get data to render into form, either using a reactive data-source if
        # editing an existing result, or by using initial-data specified from
        # a creation view
        key = Session.get('evidenceType')
        NestedCollection = share.evidenceType[key].nested_collection
        initial = @
        existing = NestedCollection.findOne({_id: Session.get('nestedEvidenceEditingId')})
        return existing || initial

removeModal = (tmpl, options) ->

    onHidden = () ->
        # remove template from DOM completely
        key = Session.get('evidenceType')
        NestedCollection = share.evidenceType[key].nested_collection
        $(tmpl.view._domrange.members).remove()
        Blaze.remove(tmpl.view)
        if options? and options.remove?
            NestedCollection.remove(options.remove)

    $(tmpl.find('#nestedModalDiv'))
        .on('hidden.bs.modal', onHidden)
        .modal('hide')

share.abstractNestedFormEvents =

    'click #inner-create': (evt, tmpl) ->
        key = Session.get('evidenceType')
        NestedCollection = share.evidenceType[key].nested_collection
        obj = share.newValues(tmpl.find('#nestedModalForm'))
        obj['tbl_id'] = Session.get('Tbl')._id
        obj['parent_id'] = tmpl.data.parent._id
        obj['sortIdx'] = 1e10  # temporary, make sure to place at bottom
        obj['isHidden'] = false
        isValid = NestedCollection.simpleSchema().namedContext().validate(obj)
        if isValid
            NestedCollection.insert(obj)
            removeModal(tmpl)
        else
            errorDiv = share.createErrorDiv(NestedCollection.simpleSchema().namedContext())
            $(tmpl.find("#errors")).html(errorDiv)

    'click #inner-create-cancel': (evt, tmpl) ->
        removeModal(tmpl)

    'click #inner-update': (evt, tmpl) ->
        key = Session.get('evidenceType')
        NestedCollection = share.evidenceType[key].nested_collection
        vals = share.updateValues(tmpl.find('#nestedModalForm'), @)
        modifier = {$set: vals}
        isValid = NestedCollection.simpleSchema().namedContext().validate(modifier, {modifier: true})
        if isValid
            NestedCollection.update(@_id, modifier)
            Session.set("nestedEvidenceEditingId", null)
            removeModal(tmpl)
        else
            errorDiv = share.createErrorDiv(NestedCollection.simpleSchema().namedContext())
            $(tmpl.find("#errors")).html(errorDiv)

    'click #inner-update-cancel': (evt, tmpl) ->
        Session.set("nestedEvidenceEditingId", null)
        removeModal(tmpl)

    'click #inner-delete': (evt, tmpl) ->
        Session.set("nestedEvidenceEditingId", null)
        removeModal(tmpl, {"remove": @_id})

    'click #setQA,#unsetQA': (evt, tmpl) ->
        key = Session.get('evidenceType')
        nested_collection_name = share.evidenceType[key].nested_collection_name
        Meteor.call 'adminToggleQAd', this._id, nested_collection_name, (err, response) ->
            if response then share.toggleQA(tmpl, response.QAd)

