<!-- ZMSRecordSet/main -->

<div class="ZMSRecordSet main" tal:define="global
		standard modules/Products/zms/standard;
		meta_id options/meta_id;
		metaObj python:here.getMetaobj(meta_id);
		metaObjIds python:here.getMetaobjIds();
		metaObjAttrIds python:here.getMetaobjAttrIds(metaObj['id']);
		dummy0 python:request.set('qsize',request.get('qsize',standard.get_session_value(here,'qsize_%s'%here.id,20)));
		dummy0 python:request.set('qfilters',request.get('qfilters',standard.get_session_value(here,'qfilters_%s'%here.id,1)));
		dummy0 python:request.set('qindex',request.get('qindex',standard.get_session_value(here,'qindex_%s'%here.id,-1)));
		dummy0 python:standard.set_session_value(here,'qsize_%s'%here.id,request.get('qsize'));
		dummy0 python:standard.set_session_value(here,'qfilters_%s'%here.id,request.get('qfilters'));
		dummy0 python:standard.set_session_value(here,'qindex_%s'%here.id,request.get('qindex'));
		dummy0 python:here.recordSet_Init(request);
		dummy0 python:here.recordSet_Filter(request);
		dummy0 python:here.recordSet_Sort(request)">

<tal:block tal:define="global
		records python:here.attr(metaObjAttrIds[0]);
		filter_columns python:[x for x in metaObj['attrs'][1:] if 
				x['id'] not in ['__sort_id']
				and x['type'] in here.metaobj_manager.valid_types+here.getMetaobjIds()
				and x['type'] not in ['password','resource']];
		metaObjAttrs python:[x for x in filter_columns if x['custom']]">

<tal:block tal:condition="python:request.get('action') not in ['updateForm','insertForm']">

<form method="get" class="form-horizontal">
	<input type="hidden" name="lang" tal:attributes="value request/lang">
	<input type="hidden" name="preview" tal:attributes="value request/preview">
	<input tal:condition="python:'qorder' in request" type="hidden" name="qorder" tal:attributes="value request/qorder">
	<input tal:condition="python:'qorderdir' in request" type="hidden" name="qorderdir" tal:attributes="value request/qorderdir">
	<div class="card">
		<div class="card-header attr_last_modified clearfix btn-collapse">
			<a class="btn card-toggle" data-toggle="collapse" href="#attrActivity" aria-expanded="false"
				><i class="fas fa-caret-right"></i> <tal:block tal:content="python:here.getZMILangStr('ATTR_ACTIVITY')">Activity</tal:block
			></a>
			<div class="btn zmi-changes" tal:content="python:here.getZMILangStr('ATTR_LAST_MODIFIED')+' '+here.getLangFmtDate(here.attr('change_dt'))+' '+here.getZMILangStr('BY')+' '+here.attr('change_uid')">change_dt by change_uid</div>
		</div><!-- .card-header -->
		<div id="attrActivity" class="collapse">
			<div class="card-body">
				<tal:block tal:condition="python:here.attr('created_dt') and here.attr('created_uid')">
					<span tal:content="python:'%s: %s %s %s'%(here.getZMILangStr('ATTR_CREATED'),here.getLangFmtDate(here.attr('created_dt')),here.getZMILangStr('BY'),here.attr('created_uid'))">Createad: %d.%m.%Y by %s</span>,
				</tal:block>
				<span title="This Node Contains ..." tal:content="python:'%i %s'%(len(here.getChildNodes(request)),here.getZMILangStr('ATTR_OBJECTS'))">%i Objects</span>,
				<span title="Data Size" class="get_size" tal:content="python:here.getDataSizeStr(here.get_size())">%i Bytes</span>,
				<span title="Unique ID" class="get_uid" tal:content="python:'ID:%s'%(here.get_uid())">unique-id</span>
			</div><!-- .card-body -->
		</div><!-- .collapse -->

		<div class="card-header filters clearfix btn-collapse">
			<a class="btn card-toggle pull-left col-sm-2 col-lg-2" data-toggle="collapse" href="#attrProperties">
				<i class="fas fa-caret-down"></i>
				<tal:block tal:content="structure python:here.getZMILangStr('ATTR_FILTER')">the label</tal:block>
			</a>
			<input type="hidden" id="qfilters" name="qfilters:int" tal:attributes="value request/qfilters" />
		</div><!-- .card-header -->

		<div id="attrProperties" class="filters collapse show">
			<div class="card-body">
				<tal:block tal:repeat="filterIndex python:range(request.get('qfilters',1)+1)">
					<div tal:attributes="class python:' '.join(['form-row']+[[],['d-none']][int(filterIndex==request.get('qfilters',1))])">
						<div class="form-group col-md-4">
							<select class="form-control form-control-sm" tal:attributes="name python:'filterattr%i'%filterIndex">
								<option value="" tal:content="python:here.getZMILangStr('CAPTION_SELECT')">the option</option>
								<tal:block tal:repeat="filter_column filter_columns">
									<option tal:attributes="value python:filter_column['id']; selected python:['','selected'][int(standard.get_session_value(here,'filterattr%i_%s'%(filterIndex,here.id))==filter_column['id'])]" tal:content="filter_column/name">label</option>
								</tal:block>
							</select>
						</div>
						<div class="form-group col-md-2">
							<select class="form-control form-control-sm" tal:attributes="name python:'filterop%i'%filterIndex">
								<tal:block tal:repeat="op python:['LIKE','=','<','<=','>','>=','NULL','NOT NULL']">
									<option tal:attributes="value python:op; selected python:['','selected'][op.lower()==request.get('filterop%i'%filterIndex, standard.get_session_value(here,'filterop%i_%s'%(filterIndex,here.id),'')).lower()]" tal:content="python:op">op</option>
								</tal:block>
							</select>
						</div>
						<div class="form-group col-md-6">
							<input class="form-control form-control-sm" type="text" tal:attributes="name python:'filtervalue%i'%filterIndex; value python:request.get('filtervalue%i'%filterIndex, standard.get_session_value(here,'filtervalue%i_%s'%(filterIndex,here.id),''))" />
						</div>
					</div><!-- .form-row -->
				</tal:block>
				<div class="form-row">
					<button type="submit" id="btn-search" class="btn btn-primary" name="btn" value="BTN_REFRESH">
						<i class="fas fa-search"></i>
						<tal:block tal:content="python:here.getZMILangStr('BTN_SEARCH')">Search</tal:block>
					</button>
					<button type="submit" id="btn-reset" class="btn btn-secondary" name="btn" value="BTN_RESET">
						<tal:block tal:content="python:here.getZMILangStr('BTN_RESET')">Reset</tal:block>
					</button>
				</div><!-- .form-row -->
			</div><!-- .card-body -->
		</div><!-- .collapse -->
	</div><!-- .card -->
</form>

	<tal:block tal:content="structure python:here.metaobj_recordset_main_grid(
			metaObjAttrIds=here.getMetaobjAttrIds(meta_id),
			metaObjAttrs=metaObjAttrs,
			filtered_records=request['res'],
			records=records,
			filtered=True,
			record_handler=here.getEntityRecordHandler(meta_id))">
		metaobj_recordset_main_grid
	</tal:block>

</tal:block>

<tal:block tal:condition="python:request.get('action')=='updateForm'">
	<tal:block tal:define="global records request/res_abs">
		<tal:block tal:condition="python:'qidentifier' in request.form">
			<tal:block tal:define="global
					rowid python:here.getMetaobjAttrIdentifierId(here.meta_id);
					row python:[x for x in records if x[rowid]==request['qidentifier']][0];
					dummy0 python:request.set('qindex',records.index(row))"></tal:block>
		</tal:block>
		<tal:block tal:content="structure python:here.metaobj_recordset_input_fields(meta_id=meta_id,action='update',qindex=request['qindex'],row=records[request['qindex']])">
			metaobj_recordset_input_fields
		</tal:block>
	</tal:block>
</tal:block>
<tal:block tal:condition="python:request.get('action')=='insertForm'">
	<tal:block tal:define="global records request/res_abs; row python:{}">
		<tal:block tal:repeat="metaObjAttr python:here.getMetaobj(here.meta_id)['attrs'][1:]">
			<tal:block tal:condition="python:metaObjAttr['id']=='sort_id'">
				<tal:block tal:define="dummy0 python:here.operator_setitem(row,metaObjAttr['id'],request.get('sort_id',len(records)))"></tal:block>
			</tal:block>
			<tal:block tal:condition="python:metaObjAttr['type'] in ['date','datetime'] and metaObjAttr['default']=='{now}'">
				<tal:block tal:define="dummy0 python:here.operator_setitem(row,metaObjAttr['id'],DateTime())"></tal:block>
			</tal:block>
			<tal:block tal:condition="python:metaObjAttr['type'] in ['identifier']">
				<tal:block tal:define="dummy0 python:here.operator_setitem(row,metaObjAttr['id'],here.getNewId())"></tal:block>
			</tal:block>
		</tal:block>
		<tal:block tal:content="structure python:here.metaobj_recordset_input_fields(meta_id=meta_id,action='insert',qindex=-1,row=row)">
			metaobj_recordset_input_fields
		</tal:block>
	</tal:block>
</tal:block>

</tal:block>

</div>


<!-- /ZMSRecordSet/main -->

