<%page args="element, widgetstyle" />
<%namespace file="../_helpers.html" import="wireElementEvents"/>
<%doc>
Maps a textfield to another textfield
[ key] = [ bar ]
Used for summary indexing fields in saved searches
</%doc>

<%

fp = element.get('fieldprefix')

elname = element['elementName']
pattern = element.get('fieldprefixregex')
if pattern and elname:
    import re
    match = re.match(pattern, elname)
    if match:
        fp = match.group(0)
    elif not elname.startswith(fp):
        raise Exception("Field regex %s defined but does not match element name: %s" % (pattern, elname))

if fp:
    fieldname = elname[len(fp):] 
else:
    fieldname = ''

%>

    <div id="item-${element['elementName'] | h}" class="widget fieldmapping" ${widgetstyle}>
        % if 'label' in element:
            <label>${_(element['label'])}</label>
        % endif
        % if 'helpText' in element:
            <p class="helpText">${_(element['helpText'])}</p>
        % endif
        <div>
            <div class="widgeterror"><form:error name="${element["elementName"] | h}"/></div>
            <input type="text" \
                class="${element['class'] if 'class' in element else 'fieldmapping left' | h}" \
                name="spl-ctrl_fmname-${element["elementName"] | h}" \
                ${'readonly="readonly"' if element.get('readonly') else ''} ${'disabled="disabled"' if element.get('disabled') else ''}\
                value="${fieldname | h}" \
                />
            =
            <input type="text" \
                class="${element['class'] if 'class' in element else 'fieldmapping right' | h}" \
                name="${element["elementName"] | h}" \
                ${'readonly="readonly"' if element.get('readonly') else ''} ${'disabled="disabled"' if element.get('disabled') else ''}\
                />
            % if element.get('deleteable'):
                <a href="#" class="delete">${_('Delete')}</a>
            % endif
            % if 'exampleText' in element:
                <p class="exampleText"><em>${_(element['exampleText']) | extract_help_links }</em></p>
            % endif
        </div>
    </div>
