'Function to be called from REST prep functions
- to add req_item & req_skill components as inline forms'

@staticmethod
def req_inline_form(type, method):

    T = current.T
    s3db = current.s3db
    table = s3db.req_req
    s3 = current.response.s3
    postprocess = s3.req_req_postprocess
    if (type == 1):
        itable = s3db.req_req_item
        itable.item_id.widget = None
        jquery_ready = s3.jquery_ready
        jquery_ready.append("\n$.filterOptionsS3({\n    'trigger':{'alias':'req_item','name':'item_id'},\n    'target':{'alias':'req_item','name':'item_pack_id'},\n    'scope':'row',\n    'lookupPrefix':'supply',\n    'lookupResource':'item_pack',\n    'msgNoRecords':i18n.no_packs,\n    'fncPrep':S3.supply.fncPrepItem,\n    'fncRepresent':S3.supply.fncRepresentItem\n})")
        settings = current.deployment_settings
        fields = ['site_id', 'requester_id', 'date', 'priority', 'date_required', S3SQLInlineComponent('req_item', label=T('Items'), fields=['item_id', 'item_pack_id', 'quantity', 'comments']), 'comments']
        if (method == 'update'):
            if settings.get_req_status_writable():
                fields.insert(7, 'fulfil_status')
                if settings.get_req_show_quantity_transit():
                    fields.insert(7, 'transit_status')
                if settings.get_req_use_commit():
                    fields.insert(7, 'commit_status')
            fields.insert(7, 'date_recv')
            if settings.get_req_requester_from_site():
                table.requester_id.widget = None
                table.requester_id.comment = S3PopupLink(c='pr', f='person', vars={'child': 'requester_id', 'parent': 'req'}, title=s3.crud_strings['pr_person'].label_create)
                jquery_ready.append(("\n$.filterOptionsS3({\n    'trigger':'site_id',\n    'target':'requester_id',\n    'lookupResource':'staff',\n    'lookupURL':S3.Ap.concat('/hrm/staff_for_site/'),\n    'msgNoRecords':'%s',\n    'optional':true,\n})" % T('No    contacts    yet    defined    for    this    site')))
                table.site_id.comment = A(T('Set    as    default    Site'), _id='req_req_site_id_link', _target='_blank', _href=URL(c='default', f='user', args=['profile']))
        if settings.get_req_items_ask_purpose():
            fields.insert(6, 'purpose')
        if (method != 'update'):
            fields.insert(1, 'is_template')
        if (settings.get_req_use_req_number() and (not settings.get_req_generate_req_number())):
            fields.insert(0, 'req_ref')
        if postprocess:
            crud_form = S3SQLCustomForm(postprocess=postprocess, *fields)
        else:
            crud_form = S3SQLCustomForm(*fields)
        s3db.configure('req_req', crud_form=crud_form)
    elif (type == 3):
        stable = s3db.req_req_skill
        stable.skill_id.label = T('Required    Skills    (optional)')
        settings = current.deployment_settings
        fields = ['site_id', 'requester_id', 'date', 'priority', 'date_required', 'date_required_until', 'purpose', S3SQLInlineComponent('req_skill', label=T('Skills'), fields=['quantity', 'skill_id', 'comments']), 'comments']
        if (method == 'update'):
            if settings.get_req_status_writable():
                fields.insert(8, 'fulfil_status')
                if settings.get_req_show_quantity_transit():
                    fields.insert(8, 'transit_status')
                if settings.get_req_use_commit():
                    fields.insert(8, 'commit_status')
            fields.insert(8, 'date_recv')
            if settings.get_req_requester_from_site():
                table.requester_id.widget = None
                table.requester_id.comment = S3PopupLink(c='pr', f='person', vars={'child': 'requester_id', 'parent': 'req'}, title=s3.crud_strings['pr_person'].label_create)
                s3.jquery_ready.append(("\n$.filterOptionsS3({\n    'trigger':'site_id',\n    'target':'requester_id',\n    'lookupResource':'staff',\n    'lookupURL':S3.Ap.concat('/hrm/staff_for_site/'),\n    'msgNoRecords':'%s',\n    'optional':true,\n})" % T('No    contacts    yet    defined    for    this    site')))
                table.site_id.comment = A(T('Set    as    default    Site'), _id='req_req_site_id_link', _target='_blank', _href=URL(c='default', f='user', args=['profile']))
        else:
            fields.insert(1, 'is_template')
        if (settings.get_req_use_req_number() and (not settings.get_req_generate_req_number())):
            fields.insert(0, 'req_ref')
        if postprocess:
            crud_form = S3SQLCustomForm(postprocess=postprocess, *fields)
        else:
            crud_form = S3SQLCustomForm(*fields)
        s3db.configure('req_req', crud_form=crud_form)
    s3.crud.submit_button = T('Save')
