<dtml-var manage_page_header>

<dtml-var manage_tabs>

<main class="container-fluid">

	<dtml-var "manage_form_title(this(), _, form_title='Change Property Types')">
	
	<dtml-unless props
		><dtml-if ids
			><dtml-call expr="REQUEST.set('props', [])"
			><dtml-call expr="REQUEST.set('old_ids', ids)"
			><dtml-in propertyMap mapping
				><dtml-if expr="id in ids"
					><dtml-call expr="props.append({'new_id': propertyLabel(id),
						'new_type': type, 'new_value': getProperty(id),
						'was_seq': type in ('tokens', 'lines', 'multiple selection')})"
				></dtml-if
			></dtml-in
		></dtml-if
	></dtml-unless>


	<form action="<dtml-var "REQUEST.URL1" html_quote>" method="post">

		<dtml-if old_ids>

			<p class="form-help">
				To change property names and values, edit them and click
				<em>Save Changes</em>. To edit properties using their new type,
				select the new types and click <em>Edit with new Types</em>.
			</p>

			<dtml-in old_ids>
				<input type="hidden" name="old_ids:list" value="&dtml-sequence-item;" />
			</dtml-in>

			<table class="table table-sm">
				<thead>
					<tr>
						<th class="property_name">Property Name</th>
						<th class="value">Value</th>
						<th class="new_type">New Type</th>
					</tr>
				</thead>
				<tbody>
					<dtml-in props mapping>
						<dtml-if expr="new_type in ('tokens', 'lines', 'multiple selection')"
							><input type="hidden" name="props.was_seq:records" value="1" />
						<dtml-else
							><input type="hidden" name="props.was_seq:records" value="" />
						</dtml-if>
						<dtml-let value_name="'props.new_value:' + {'multiple selection': 'list', 'selection': 'string'}.get(new_type, new_type) + ':records'">
							<tr>
								<td class="property_name">
									<input type="text" class="form-control" name="props.new_id:records" value="&dtml-new_id;" />
								</td>
								<td>
									<dtml-if expr="new_type in ('int', 'long', 'float', 'date', 'string', 'tokens')"
										><input type="text" class="form-control" name="&dtml-value_name;" 
										<dtml-if was_seq
											>value="<dtml-in new_value>&dtml-sequence-item; </dtml-in>"
										<dtml-elif expr="new_type=='long'"
											>value="<dtml-var expr="_.str(getProperty(id))[:-1]" html_quote>"
										<dtml-else
											>value="&dtml-new_value;"
										</dtml-if>>
									<dtml-elif "new_type=='boolean'"
										><div class="form-check"><input class="form-check-input" type="checkbox" name="&dtml-value_name;"
											<dtml-if new_value>checked="checked"</dtml-if> 
										/></div>
									<dtml-elif "new_type in ('text', 'lines')"
										><textarea class="form-control" name="&dtml-value_name;" rows="6"
											><dtml-if was_seq><dtml-in	new_value>&dtml-sequence-item;<dtml-unless sequence-end><dtml-var expr="'\n'"></dtml-unless></dtml-in><dtml-else>&dtml-new_value;</dtml-if></textarea>
									<dtml-elif "new_type=='selection'"
										><dtml-if "_.has_key(select_variable)"
											><select name="&dtml-value_name;"
												><dtml-in "_[select_variable]"
													><option <dtml-if "_['sequence-item']==new_value">selected="selected"</dtml-if>>&dtml-sequence-item;</option>
												</dtml-in
											></select>
										<dtml-else
											>No value for &dtml-select_variable;.
										</dtml-if>
									<dtml-elif "new_type=='multiple selection'"
										><dtml-if "_.has_key(select_variable)"
											><select class="form-control" name="&dtml-value_name;" multiple="multiple"	size="<dtml-var "_.min(7, _.len(_[select_variable]))">">
												<dtml-in "_[select_variable]">
													<option<dtml-if "_['sequence-item'] in new_value"> selected="selected"</dtml-if>>&dtml-sequence-item;</option>
												</dtml-in>
											</select>
										<dtml-else
											>No value for &dtml-select_variable;.
										</dtml-if>
									<dtml-else>
										<em>Unknown property type</em>
									</dtml-if>
								</td>
								<td>
									<select class="form-control" name="props.new_type:records">
										<dtml-in expr="('boolean', 'date', 'float', 'int', 'lines', 'long', 'string', 'text', 'tokens', 'selection', 'multiple selection')">
											><option <dtml-var "['', 'selected=\042selected\042'][new_type==_['sequence-item']]">>&dtml-sequence-item;</option>
										</dtml-in>
									</select>
								</td>
							</tr>
						</dtml-let>
					</dtml-in>
				</tbody>
			</table>

			<div class="zmi-controls">
				<input class="btn btn-primary" type="submit" name="manage_changePropertyTypes:method" value="Save Changes" />
				<input class="btn btn-primary" type="submit" name="manage_propertyTypeForm:method" value="Edit with new Types" />
			</div>

		<dtml-else>

			<div class="alert alert-warning">No properties were selected for this item.</div>

		</dtml-if>

	</form>

</main>

<dtml-var manage_page_footer>