<%-jsh.RenderView('jsh_embed.js',ejsparams)%>

<div class="xbodyhead xelem<%=model.class%>">
<% if(model.topmost) { %><!--%%%EJSPREPEND%%%--><% } %>
<% if(!model.topmost && (model.title !== undefined)) { %>
<h1 class="xtitle xelem<%=model.class%> xtitle<%=model.class%>" style="display:inline-block;"><%=model.title%></h1>
<% }

var xactiontype = 'secondarygrid';
if(model.topmost) xactiontype = 'top';
else if(parent && (parent.topmost) && ('tabpos' in parent) && (parent.tabpos=='top')) xactiontype = 'auxtop';
%>
<h1 class="xtitlecaption xtitlecaption<%=model.class%>" style="display:inline-block;"><a href="#" onclick="<%-instance%>.xd('.xsearch_<%=model.class%>').animate.height(); return false;">(Search)</a></h1>
<div class="xactions <%=xactiontype%> xelem<%=model.class%>">
  <%-jsh.RenderView('jsh_buttons',ejsparams)%>
  <% if(model.inlinepopup){ %><a href="#" onclick="<%-instance%>.XExt.popupClear('<%=model.id%>',this); return false;" style="<%-xejs.visible(xejs.showSystemButton(model,'clear'))%>"><img src="<%-jsh._PUBLICURL%>images/icon_delete.png" alt="Clear" title="Clear" />Clear</a><% } %>
  <% if(model.topmost && (model.commitlevel) && (model.commitlevel != 'none')){ %><a href="#" class="save <%=xactiontype%>" onclick="<%-instance%>.XPage.Save();return false;" style="display:none;"><img src="<%-jsh._PUBLICURL%>images/icon_save.png" alt="Save" title="Save" />Save</a><% } %>
  <% if(!model.templates.grid && !model.grid_static && xejs.showSystemButton(model,'add')){ %><a href="#" onclick="<%-js('xmodel.controller.AddRow();')%>" class="xbuttoninsert" style="<%-xejs.visible(xejs.showSystemButton(model,'insert') && model.commitlevel && (model.commitlevel != 'none') && XExt.hasAction(model.actions,'I'))%>"><img src="<%-jsh._PUBLICURL%>images/icon_insert.png" alt="Add" title="Add" />Add</a><% } %>
  <a href="#" class="xsearchbutton xsearchbutton<%=model.class%>" onclick="<%-js('xmodel.controller.SearchButtonClick();')%>" style="<%-xejs.visible(xejs.showSystemButton(model,'search'))%>"><img src="<%-jsh._PUBLICURL%>images/icon_search.png" alt="Search" title="Search" /><span>Search</span></a>
  <a href="/" onclick="<%-js('jsh.XPage.Print();')%>" style="<%-xejs.visible(model.topmost && xejs.showSystemButton(model,'print'))%>"><img src="<%-jsh._PUBLICURL%>images/icon_print.png" alt="Print" title="Print" />Print</a>
  <a href="#" onclick="<%-js('xmodel.controller.Export();')%>" style="<%-xejs.visible(xejs.showSystemButton(model,'export')&&!model.disable_csv_export)%>"><img src="<%-jsh._PUBLICURL%>images/icon_export.png" alt="Export" title="Export" />Export</a>
  <a href="<%-model.helpurl%>" onclick="<%-js(model.helpurl_onclick)%>" style="<%-xejs.visible(model.topmost && xejs.showSystemButton(model,'help'))%>"><img src="<%-jsh._PUBLICURL%>images/icon_help.png" alt="Help" title="Help" />Help</a>
</div>
<%-jsh.RenderEJS(model.header,ejsparams)%>
<div data-id="<%=model.id%>" class="xsearch xsearch_<%=model.class%>"></div>
<script class="xsearch_template_<%=model.class%>" type="text/x-ejs-template">
  <%%
    var comparison_string = [];
    <%-instance%>.XExt.pushLOV(comparison_string,'contains','Contains');
    <%-instance%>.XExt.pushLOV(comparison_string,'notcontains','Does Not Contain');
    <%-instance%>.XExt.pushLOV(comparison_string,'=','Equals');
    <%-instance%>.XExt.pushLOV(comparison_string,'<>','Does Not Equal');
    <%-instance%>.XExt.pushLOV(comparison_string,'beginswith','Begins With');
    <%-instance%>.XExt.pushLOV(comparison_string,'endswith','Ends With');
    <%-instance%>.XExt.pushLOV(comparison_string,'null','Is Blank');
    <%-instance%>.XExt.pushLOV(comparison_string,'notnull','Is Not Blank');
    var comparison_numeric = [];
    <%-instance%>.XExt.pushLOV(comparison_numeric,'=','Equals');
    <%-instance%>.XExt.pushLOV(comparison_numeric,'<>','Does Not Equal');
    <%-instance%>.XExt.pushLOV(comparison_numeric,'>','>');
    <%-instance%>.XExt.pushLOV(comparison_numeric,'>=','>=');
    <%-instance%>.XExt.pushLOV(comparison_numeric,'<','<');
    <%-instance%>.XExt.pushLOV(comparison_numeric,'<=','<=');
    <%-instance%>.XExt.pushLOV(comparison_numeric,'null','Is Blank');
    <%-instance%>.XExt.pushLOV(comparison_numeric,'notnull','Is Not Blank');
    var comparison_date = comparison_numeric;
    var comparison_object = [];
    <%-instance%>.XExt.pushLOV(comparison_object,'=','Equals');
    <%-instance%>.XExt.pushLOV(comparison_object,'<>','Does Not Equal');
    <%-instance%>.XExt.pushLOV(comparison_object,'null','Is Blank');
    <%-instance%>.XExt.pushLOV(comparison_object,'notnull','Is Not Blank');
    var comparison_sound = function(comparison,search_sound){
      var rslt = comparison.slice(0);
      if(search_sound){ <%-instance%>.XExt.pushLOV(rslt,'soundslike','Sounds Like'); }
      return rslt;
    }
  %%>
  <%% for(var i=0;i<data.Items.length;i++){ var selected_column = null; %%>
    <div class="xsearch_expression xsearch_expression_<%%=i%%>">
      <input type="button" class="xsearch_menu_button" value="&#x2bc8;" onclick="<%-js("event.preventDefault(); event.stopPropagation(); XExt.ShowContextMenu('.search_context_"+model.class+"', this, event, { top: jsh.XDom.calc.topFromDocument(this), left: jsh.XDom.calc.leftFromDocument(this)+jsh.XDom.calc.widthToBorder(this)-1 });" )%>" />
      Search: &nbsp;<select autocomplete="off" class="xsearch_column" onchange="<%-js('xmodel.controller.SearchColumnChange();')%>"><option value="ALL">Any field...</option><%% for(var j=0;j<data.Fields.length;j++){ if(!data.Fields[j].caption || data.Fields[j].unbound) continue; %%><option value="<%%=data.Fields[j].name%%>" <%% if(data.Fields[j].name==data.Items[i].Column){ selected_column = data.Fields[j]; %%>selected="Selected"<%% } %%>><%%=data.Fields[j].caption%%></option><%% } %%></select>&nbsp; 
      <div class="xsearch_comparison_div" style="display:inline-block;width:140px;">
        <%% if(selected_column && (selected_column.comparison_type=='string')){ %%>
          <select autocomplete="off" class="xsearch_comparison" onchange="<%-js('xmodel.controller.SearchComparisonChange();')%>">
            <%%-xejs.renderLOV(comparison_sound(comparison_string,selected_column.search_sound),data.Items[i].Comparison)%%>
          </select>
        <%% } else if(selected_column && (selected_column.comparison_type=='numeric')){ %%>
          <select autocomplete="off" class="xsearch_comparison" onchange="<%-js('xmodel.controller.SearchComparisonChange();')%>">
            <%%-xejs.renderLOV(comparison_sound(comparison_numeric,selected_column.search_sound),data.Items[i].Comparison)%%>
          </select>
        <%% } else if(selected_column && (selected_column.comparison_type=='date')){ %%>
          <select autocomplete="off" class="xsearch_comparison" onchange="<%-js('xmodel.controller.SearchComparisonChange();')%>">
            <%%-xejs.renderLOV(comparison_sound(comparison_date,selected_column.search_sound),data.Items[i].Comparison)%%>
          </select>
        <%% } else if(selected_column && (selected_column.comparison_type=='object')){ %%>
          <select autocomplete="off" class="xsearch_comparison" onchange="<%-js('xmodel.controller.SearchComparisonChange();')%>">
            <%%-xejs.renderLOV(comparison_sound(comparison_object,selected_column.search_sound),data.Items[i].Comparison)%%>
          </select>
        <%% } else { %%>
          containing the value
          <select autocomplete="off" class="xsearch_comparison" onchange="<%-js('xmodel.controller.SearchComparisonChange();')%>" style="display:none;">
          </select>
        <%% } %%>
      </div>&nbsp;
      <input autocomplete="off" type="text" class="xsearch_value <%%=xejs.iif((selected_column && (selected_column.comparison_type=='date')),'datepicker')%%>" value="<%%=xejs.iif((data.Items[i].Comparison=='null')||(data.Items[i].Comparison=='notnull'),'',data.Items[i].Value)%%>" onkeyup="<%-js('xmodel.controller.SearchKeyUp(event);')%>" style="<%%=xejs.iif((data.Items[i].Comparison=='null')||(data.Items[i].Comparison=='notnull'),'visibility:hidden;')%%>" />
        <%% if(i==(data.Items.length-1)){ %%>
        <a class="xsearch_apply" href="#" style="width:80px;" onclick="<%-js('xmodel.controller.RunSearch();')%>"><img src="<%-jsh._PUBLICURL%>images/icon_search.png" alt="Search" title="Search" />GO</a>
        <%% } else { %%>
        <select autocomplete="off" name="xsearch_join" id="xsearch_join" class="xsearch_join" onchange="<%-js('xmodel.controller.SearchJoinChange(event);')%>" >
            <option value="and" <%% if(data.Items[i+1].Join == 'and' ) { %%>selected<%% } %%>>and</option>
            <option value="or" <%% if(data.Items[i+1].Join == 'or') { %%>selected<%% } %%>>or</option>
        </select>
        <%% } %%>
    </div>
  <%% } %%>
</script>
<script class="xgrid_template_manage_columns_<%=model.class%>" type="text/x-ejs-template">
  <div class="xdialogbox xpromptbox xgrid_manage_columns_<%=model.class%>" style="width:260px;">
    <h3>Display columns:</h3>
    <div align="left" style="padding-top:8px;">
      <div class="display_layout_columns" style="max-height: 170px; overflow: auto;">
        <%%
        var current_display_layout = xmodel.controller.GetDisplayLayout();
        var current_display_layout_column_names = [];
        _.each(current_display_layout.columns, function(column){ current_display_layout_column_names[column.name] = 1; });
        _.each(xmodel.fields, function(field){
          if (!XExt.hasAction(field.actions,'B') || (field.control == 'hidden')) return;
          %%>
          <label><input autocomplete="off" type="checkbox" name="<%%=field.name%%>" value="<%%=field.name%%>" <%% if(current_display_layout_column_names[field.name]){ %%> checked <%% } %%>> <%%=field.caption_ext||field.caption||field.name%%></label><br>
          <%%
        });
        %%>
      </div>
      <div style="text-align:center;"><input type="button" value="Apply" class="button_ok" style="margin-right:15px;" /> <input type="button" value="Cancel" class="button_cancel" /></div>
    </div>
  </div>
</script>
<div class="xcontext_menu search_context_<%=model.class%>">
  <a onclick="<%-js('jsh.xd(\'.xcontext_menu\').display = false; xmodel.controller.SearchAdd(jsh.xContextMenuItemData); return false;')%>"><img src="<%-jsh._PUBLICURL%>images/icon_add.png" />Add Search Item</a>
  <a onclick="<%-js('jsh.xd(\'.xcontext_menu\').display = false; xmodel.controller.SearchRemove(jsh.xContextMenuItemData); return false;')%>"><img src="<%-jsh._PUBLICURL%>images/icon_remove.png" />Remove</a>
</div>
<div class="xcontext_menu xgrid_column_header_context_<%=model.class%>">
  <a onclick="<%-js('jsh.xd(\'.xcontext_menu\').display = false; xmodel.controller.HideColumn(jsh.xContextMenuItem); return false;')%>"><img src="<%-jsh._PUBLICURL%>images/icon_design2.png" />Hide this column</a>
  <a onclick="<%-js('jsh.xd(\'.xcontext_menu\').display = false; xmodel.controller.ManageColumns(); return false;')%>"><img src="<%-jsh._PUBLICURL%>images/icon_design.png" />Manage Columns</a>
</div>
</div><!-- .xbodyhead -->
  <% if(!model.templates.grid){ %>
  <table class="xtbl xelem<%=model.class%> xform<%=model.class%> <%=model.tableclass||''%>" data-id="<%=model.id%>" style="<%=model.tablestyle%>">
    <thead>
      <tr>
        <% if(model.inlinepopup){ %><th class="xgrid_select_item" style="text-align:center;" nowrap>Select</th><% } %>
        <% for(var i=0;i<model.fields.length;i++){ var field = model.fields[i];
          if(!('caption' in field)) continue;
          if(('actions' in field)){
            if(!XExt.hasAction(field.actions,'BIU')) continue;
          }
          else if (!('html' in field)) continue; 
          var fieldclass = '';
          if(field.control=='hidden'){ fieldclass += ' static tdhidden '; }
          else if((field.control=='html') && ('value' in field)){ fieldclass += ' static '; }
          else if(model.current_display_layout_name && XExt.isDisplayLayoutColumnHidden(field.name, model.display_layouts[model.current_display_layout_name])){ fieldclass += ' tdhidden '; }
          %>
        <th nowrap class="<%=field.sortclass%> thead<%=field.name%> <%=field.captionclass%> <%=fieldclass%>" style="<%=field.captionstyle%>" data-field="<%=field.name%>"><% if(field.disable_sort||(field.type=='file')||field.unbound){ %><%=field.caption%><% } else { %><a href="#" onClick="<%-js('return xmodel.controller.Sort(this, \''+XExt.escapeHTML((field.lov && !field.lov.showcode)?('__'+jsh.uimap.code_txt+'__'+field.name):field.name)+'\');')%>"><%=field.caption%></a><% } %></th>
        <% } %>
        <%-xejs.iif(model.duplicate && model.commitlevel && (model.commitlevel != 'none') && XExt.hasAction(model.actions,'I'),'<th class="xgrid_action_thead duplicate static"></th>')%>
        <%-xejs.iif(model.commitlevel && (model.commitlevel != 'none') && XExt.hasAction(model.actions,'D'),'<th class="xgrid_action_thead delete static"></th>')%>
      </tr>
    </thead>
    <tbody class="xgrid_<%=model.class%>_placeholder"></tbody>
    <script class="xgrid_<%=model.class%>_template" type="text/x-ejs-template" data-target=".xgrid_<%=model.class%>_placeholder">
      <%% for(var j=0;j<datatable.length;j++){ var datarow=datatable[j]; var data = datarow; if((typeof startrowid == 'undefined') || (startrowid === null)) startrowid = j; var rowid = startrowid + j;  %%>
      <tr class="<%%=(rowid%2==1?'even':'odd')%%> <%-model.rowclass%> xrow_<%=model.class%> xrow" style="<%-model.rowstyle%>" data-id="<%%=rowid%%>">
        <% if(model.inlinepopup){ %><td class="xgrid_select_item" align="center"><a href="#" onclick="<%-instance%>.XExt.popupSelect('<%=model.id%>',this); return false;">Select</a></td><% } %>
        <% for(var i=0;i<model.fields.length;i++){ var field = model.fields[i];
          if(!('caption' in field)) continue;
          if(('actions' in field)){
            if(!XExt.hasAction(field.actions,'BIU')) continue;
          }
          else if (!('html' in field)) continue;
          var format = 'undefined';
          if('format' in field) format = JSON.stringify(field.format);
          var fieldclass = '';
          if(field.control && (field.control=='hidden')) fieldclass += 'tdhidden';
          var maxlength = XExt.getMaxLength(field);
          %>
          <td style="<%-field.cellstyle%><%-(field.nowrap ? 'white-space:nowrap;' : '')%>" class="<%-field.cellclass%> <%=xejs.iif(field.control=='checkbox','xcheckbox_column')%> <%=xejs.iif(field.popuplov,'xpopuplov_column')%> <%=xejs.iif(field.hints,'xhints_column')%> <%=fieldclass%>  <%% if(XExt.isDisplayLayoutColumnHidden('<%=field.name%>', xmodel.controller.GetDisplayLayout(), xmodel.fields)) { %%> tdhidden  <%% } %%>"><% 
        if((field.control=='label') || (field.control=='html')){
          if(('link' in field) && (XExt.beginsWith(field.link,'#select'))){ %><a class="xform_link" href="<%-field.link%>" onclick="<%-instance%>.XExt.popupSelect('<%=model.id%>',this);return false;" ><% }
          else if('link' in field){ %><a data-url="<%-field.link%>" href="<%-XExt.replaceTempEJSTags(field.link)%>" class="xform_link" onclick="<%-js(field.link_onclick)%>"><% }
          if((field.control=='html') && ('value' in field)){
            %><%-XExt.replaceTempEJSTags(field.value)%><%
          } else if(field.control=='html'){
            %><div data-id="<%=field.name%>" style="<%-field.controlstyle%>" class="<%-field.controlclass%> <%=field.name%> xform_ctrl xelem<%=model.class%> xform_html" onclick="return (function(){<%-jslocals%><%-field.onclick%>}).call(this);"></div><%
          } else if(field.control=='label'){
            %><div data-id="<%=field.name%>" style="<%-field.controlstyle%>" class="<%-field.controlclass%> <%=field.name%> xform_ctrl xelem<%=model.class%> xform_label <%=xejs.iif(field.value,'xform_label_static')%>" onclick="return (function(){<%-jslocals%><%-field.onclick%>}).call(this);"><%
            if(field.value && (field.value.indexOf('<#')>=0)){  }
            else if(field.value){ %><%-field.value%><% }
            else { %><%-xejs.GetValue(field, model)%><% }
            %></div><%
          }
          if('link' in field){ %></a><% }
        }
        else if(field.control=='textbox'){ %><input autocomplete="off" type="<%=xejs.getInputType(field)%>" data-id="<%=field.name%>" value="<%-xejs.GetValue(field, model)%>" style="<%-field.controlstyle%>" class="<%=field.name%> xform_ctrl xelem<%=model.class%> <%-field.controlclass%>" <% if(field.controlparams.placeholder){ %>placeholder="<%=field.controlparams.placeholder%>"<% } %> <%-xejs.iif(maxlength >= 0,'maxlength="'+maxlength+'"')%> /><% }
        else if(field.control=='textzoom'){ %><div class="xform_ctrl_textzoom_container"><textarea autocomplete="off" data-id="<%=field.name%>" name="<%=field.name%>" style="<%-field.controlstyle%>" class="<%=field.name%> xform_ctrl xform_ctrl_textzoom xelem<%=model.class%> <%-field.controlclass%>"><%-xejs.GetValue(field, model)%></textarea><a href="#" class="xform_ctrl xtextzoom icon" onclick="var ctrl = <%-instance%>.XDom.previousSibling(this, '.<%=field.name%>')[0]; <%-instance%>.XExt.ZoomEdit(ctrl.value,'<%=field.caption_ext||field.caption%>',{readonly:!<%-instance%>.XDom.class.contains(ctrl, 'editable')},function(rslt){ <%-instance%>.XExt.setFormControl(<%-instance%>.XExt.getForm('<%=model.id%>'),'<%=field.name%>',rslt); ctrl.focus(); }); return false;"><img src="<%-jsh._PUBLICURL%>images/icon_<%=(field.controlparams&&field.controlparams.icon)||'search'%>.png" height="14" /></a></div><% }
        else if(field.control=='tagbox'){ %><div style="<%-field.controlstyle%>" class="<%=field.name%>_editor xtagbox xform_ctrl xelem<%=model.class%> <%-field.controlclass%>"></div><input autocomplete="off" type="text" data-id="<%=field.name%>" class="<%=field.name%> xform_ctrl xelem<%=model.class%> xtagbox_base" value="<%-xejs.GetValue(field, model)%>" /><% }
        else if(field.control=='password'){ %><input autocomplete="new-password" type="password" data-id="<%=field.name%>" value="<%-xejs.GetValue(field, model)%>" style="<%-field.controlstyle%>" class="<%=field.name%> xform_ctrl xelem<%=model.class%> <%-field.controlclass%>" <%-xejs.iif(maxlength >= 0,'maxlength="'+maxlength+'"')%> /><% }
        else if(field.control=='date'){ %><input autocomplete="off" data-id="<%=field.name%>" style="<%-field.controlstyle%>" class="<%=field.name%> xform_ctrl xelem<%=model.class%> datepicker <%-field.controlclass%>" value="<%-xejs.GetValue(field, model)%>" <% if(field.controlparams.placeholder){ %>placeholder="<%=field.controlparams.placeholder%>"<% } %> maxlength="10" /><a href="#" onclick="return false;" class="xform_ctrl xelem<%=model.class%> datepicker_handle nofocus" tabindex="-1"><img src="<%-jsh._PUBLICURL%>images/spacer.gif" /></a><% }
        else if(field.control=='textarea'){ %><textarea autocomplete="off" data-id="<%=field.name%>" style="<%-field.controlstyle%>" class="<%=field.name%> xform_ctrl xelem<%=model.class%> <%-field.controlclass%>"><%-xejs.GetValue(field, model)%></textarea><% }
        else if(field.control=='dropdown'){ %><select autocomplete="off" data-id="<%=field.name%>" style="<%-field.controlstyle%>" class="<%=field.name%> xform_ctrl xelem<%=model.class%> dropdown <%-field.controlclass%>"><option><%-xejs.GetValue(field, model)%></option></select><% }
        else if(field.control=='hidden'){ %><input autocomplete="off" type="hidden" data-id="<%=field.name%>" value="<%-xejs.GetValue(field, model)%>" class="<%=field.name%> xform_ctrl xelem<%=model.class%> <%-field.controlclass%>" /><% }
        else if(field.control=='checkbox'){ %><div class="xform_ctrl xform_checkbox_container xelem<%=model.class%>"><input autocomplete="off" data-id="<%=field.name%>" type="checkbox" style="<%-field.controlstyle%>" class="<%=field.name%> xform_ctrl checkbox xelem<%=model.class%> <%-field.controlclass%>" /></div><% }
        else if(field.control=='button'){ 
          if('link' in field){ %><input data-id="<%=field.name%>" type="button" class="xform_ctrl xform_ctrl_button xelem<%=model.class%> <%=field.name%> <%-field.controlclass%>" style="<%-field.controlstyle%>" value="<%-xejs.escapeHTMLN(field.value)%>" data-url="<%-field.link%>" onclick="<%-js(field.onclick)%>" /><% }
          else{ %><input data-id="<%=field.name%>" type="button" data-model="<%=model.id%>" class="xform_ctrl xform_ctrl_button xelem<%=model.class%> <%=field.name%> <%-field.controlclass%>" style="<%-field.controlstyle%>" value="<%-xejs.escapeHTMLN(field.value)%>" onclick="<%-js(field.onclick)%>" /><% }
        }
        else if(field.control=='linkbutton'){ 
          if('link' in field){ %><a data-id="<%=field.name%>" href="#" class="xform_ctrl xelem<%=model.class%> <%=field.name%> <%-field.controlclass%> xform_label <%=xejs.iif(field.value,'xform_label_static')%>" style="<%-field.controlstyle%>" data-url="<%-field.link%>" onclick="<%-js(field.onclick)%>"><%=xejs.ifnull(field.value,'')%></a><% }
          else { %><a data-id="<%=field.name%>" data-model="<%=model.id%>" href="#" style="<%-field.controlstyle%>" class="xform_ctrl xelem<%=model.class%> <%=field.name%> <%-field.controlclass%> xform_label <%=xejs.iif(field.value,'xform_label_static')%>" onclick="<%-js(field.onclick)%>"><%=xejs.ifnull(field.value,'')%></a><% }
        }
        else if(field.control=='file_download'){ %>
            <div data-id="<%=field.name%>" class="<%=field.name%> xform_file_download xelem<%=model.class%> <%-field.controlclass%>" style="<%-field.controlstyle%>">
              <% if(field.controlparams.download_button){ %><a class="<%=field.name%>_download linkbutton xform_file_download_button" href="#" onclick="<%-js('xmodel.controller.DownloadFile(\''+XExt.escapeHTML(field.name)+'\',\''+XExt.escapeHTML(field.caption_ext||field.caption)+'\','+XExt.ejsDelimiter.open+'=rowid'+XExt.ejsDelimiter.close+');')%>"><img src="<%-jsh._PUBLICURL%>images/icon_download.png" /><%=field.controlparams.download_button%></a><% } %>
              <input autocomplete="off" type="hidden" data-id="<%=field.name%>_dbexists" class="<%=field.name%>_dbexists xform_file_dbexists xform_ctrl xelem<%=model.class%> <%-field.controlclass%>" value="<%-xejs.GetValue(field, model)%>" />
            </div>
        <% }
        else if(field.control=='image'){ %>
            <% if(field.controlparams.preview_on_click){ %><a class="<%=field.name%>_preview xform_image_preview xelem<%=model.class%>" href="#" onclick="<%-js('xmodel.controller.FilePreview(\''+XExt.escapeHTML(field.name)+'\',\''+XExt.escapeHTML(field.caption_ext||field.caption)+'\','+XExt.ejsDelimiter.open+'=rowid'+XExt.ejsDelimiter.close+');')%>"><% } %>
            <img data-id="<%=field.name%>" class="<%=field.name%> xform_image xelem<%=model.class%> <%=field.name%>_thumbnail xform_file_thumbnail <%-field.controlclass%>" style="<%-field.controlstyle%>" />
            <% if(field.controlparams.preview_on_click){ %></a><% } %>
            <input autocomplete="off" type="hidden" data-id="<%=field.name%>_dbexists" class="<%=field.name%>_dbexists xform_file_dbexists xform_ctrl xelem<%=model.class%> <%-field.controlclass%>" value="<%-xejs.GetValue(field, model)%>" />
        <% }
        //Add a hidden field for field value if it is both static and updatable
        if(XExt.hasAction(field.actions,'IU') && _.includes(['html','label','linkbutton','button'],field.control)){
          %><input autocomplete="off" data-id="<%=field.name%>_field_value" type="hidden" class="<%=field.name%>_field_value xform_ctrl xelem<%=model.class%>" value="<%-xejs.GetValue(field, model)%>" /><%
        }
        if(field.popuplov){ %><a href="#" data-id="<%=field.name%>_xlookup" class="xform_ctrl xlookup icon <%=field.name%>_xlookup" style="<%=field.controlparams.popupiconstyle%>" data-code_val="<%=field.controlparams.code_val%>" data-model="<%=model.id%>" onclick="<%-instance%>.XExt.popupShow('<%=field.model.id%>','<%=field.name%>','<%=field.caption_ext||field.caption%> Selection',<%-instance%>.XDom(this).previousSibling('.<%=field.name%>').element,this,{rowid: <%%=rowid%%>,OnControlUpdate:function(obj,e){ <%-instance%>.XModels['<%=model.id%>'].controller.editablegrid.ControlUpdate(obj,e); }})"><img src="<%-jsh._PUBLICURL%>images/icon_search.png" height="14" /></a><% }
        if(field.hints){ %><a href="#" data-id="<%=field.name%>_xhints" class="xform_ctrl xhints icon <%=field.name%>_xhints" data-model="<%=model.id%>" onclick="(function(){<%-jslocals%> var ctrl = <%-instance%>.XDom.previousSibling(this, '.<%=field.name%>')[0] <%-instance%>.XExt.ShowHints(xmodel.controller.getLOV('<%=field.name%>'),'<%=(field.hints&&field.hints.caption)||('Add '+(field.caption_ext||field.caption))%>',{readonly:!<%-instance%>.XDom.class.contains(ctrl, 'editable')},function(rslt){ if(!rslt || !rslt.length) return; var prevval = ctrl.value.trim();  if(prevval) rslt.unshift(ctrl.value); <%-instance%>.XExt.setFormControl(<%-instance%>.XExt.getForm('<%=model.id%>'),'<%=field.name%>',rslt.join('<%=field.hints.separator%>')); ctrl.focus(); }); }).call(this); return false;"><img src="<%-jsh._PUBLICURL%>images/icon_wand.png" /></a> <% }
          %></td>
        <% } %>
        <% if(model.duplicate && model.commitlevel && (model.commitlevel != 'none') && XExt.hasAction(model.actions,'I')){
          %><td align="center" class="xgrid_action_cell duplicate"><a href="#" class="xgrid_action duplicate" data-model="<%=model.id%>" data-actions="I" class="row_independent" onclick="<%-js('xmodel.controller.DuplicateRow(\''+XExt.escapeJS(model.duplicate.model.id)+'\','+XExt.ejsDelimiter.open+'=rowid'+XExt.ejsDelimiter.close+', this, '+(model.duplicate.bindings?JSON.stringify(model.duplicate.bindings):'{}')+');')%>" style="<%-xejs.visible(XExt.hasAction(model.actions,'I'))%>"><img src="<%-jsh._PUBLICURL%>images/icon_copy.png" height="14" alt="Duplicate" title="Duplicate" /><%=(model.duplicate.button_text?' '+model.duplicate.button_text.toString():'')%></a></td><%
        } %>
        <% if(model.commitlevel && (model.commitlevel != 'none') && XExt.hasAction(model.actions,'D')){%><td align="center" class="xgrid_action_cell delete"><a href="#" class="xgrid_action delete" onclick="<%-js('xmodel.controller.DeleteRow('+XExt.ejsDelimiter.open+'=rowid'+XExt.ejsDelimiter.close+');')%>" style="<%-xejs.visible(XExt.hasAction(model.actions,'D'))%>"><img src="<%-jsh._PUBLICURL%>images/icon_delete2.png" height="14" alt="Delete" title="Delete" /></a></td><%}%>
      </tr>
      <%% } %%>
    </script>
  </table>
  <% 
  }
  for(var i=0;i<model.fields.length;i++){ var field = model.fields[i]; 
    if(field.popuplov){
      var popup_model = null;
      if(_.isString(field.model)) popup_model = field.model;
      else {
        popup_model = _.extend({},field.model);
        popup_model.hide_system_buttons = _.union(popup_model.hide_system_buttons,['export']); 
        popup_model.inlinepopup = 1;
      }
      %>
      <div style="display:none;">
        <div class="xsubform xpopup xelem<%=model.class%> popup_<%=field.name%>">
          <div class="xpanel" style="<%=field.controlparams.popupstyle%>">
            <%-jsh.Render(popup_model,model,field)%>
          </div>
        </div>
      </div>
      <%
          }
  }
%>
<% if(model.duplicate){
  var popup_model = null;
  if(_.isString(model.duplicate.model)) popup_model = model.duplicate.model;
  else {
    popup_model = _.extend({},model.duplicate.model);
    popup_model.hide_system_buttons = _.union(popup_model.hide_system_buttons,['export']); 
    popup_model.inlinepopup = 1;
  }
  %>
  <div style="display:none;">
    <div class="xsubform xpopup xelem<%=model.class%> popup_<%=model.class%>_duplicate">
      <div class="xpanel" style="<%=model.duplicate.popupstyle%>">
        <%-jsh.Render(popup_model,model,model.duplicate)%>
        <div style="text-align:center;padding-top:8px;">
          <input type="button" data-model="<%=popup_model.id%>" class="xform_ctrl xelem<%=popup_model.class%> style="padding:3px 8px;" value="Duplicate" onclick="<%-instance%>.XPage.Duplicate('<%=popup_model.id%>','<%-XExt.escapeHTMLQ(XExt.escapeJS(model.duplicate.link_on_success||''))%>','<%-XExt.escapeHTMLQ(XExt.escapeJS(model.duplicate.link_options_on_success||''))%>'); return false;" />
          <input type="button" data-model="<%=popup_model.id%>" class="xform_ctrl xelem<%=popup_model.class%> style="padding:3px 8px;" value="Cancel" onclick="<%-instance%>.XExt.CancelDialog(); return false;" />
        </div>
      </div>
    </div>
  </div>
<% } %>
<%-jsh.RenderEJS(model.ejs,ejsparams)%>