<!-- Edit this file to change the layout of the detail view form -->

<a name="detail-view"></a>
<div class="panel-heading"><h3 class="panel-title"><strong><%%DETAIL_VIEW_TITLE%%></strong></h3></div>

<div class="panel-body" id="order_details_dv_container">
	<!-- child links -->
	<div class="row vspacer-md">
		<div class="col-xs-12">
			<div class="clearfix"></div>
		</div>
	</div>
	<hr class="hidden-xs hidden-sm">

	<div class="row">
		<!-- form inputs -->
		<div class="col-md-8 col-lg-10" id="order_details_dv_form">
			<fieldset class="form-horizontal">

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="odID" class="control-label col-lg-3">ID</label>
					<div class="col-lg-9">
						<div class="form-control-static" id="odID"><%%VALUE(odID)%%></div>
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="OrderID" class="control-label col-lg-3" data-parent_link="view_parent_modal">Order ID <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#OrderID-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block collapse" id="OrderID-description"><div class="alert alert-info">This field is a lookup field that gets its data from the Orders table. Since the Orders table has a large number of orders, AppGini automatically displays this lookup field as an<br />auto-complete. Type part of the order number to see a list of matching orders to choose from.</div></span>

						<div class="form-control-static" style="white-space: nowrap; overflow-x: hidden;"><%%COMBO(OrderID)%%><%%PLINK(OrderID)%%><%%ADDNEW(orders)%%></div>
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="ProductID" class="control-label col-lg-3" data-parent_link="view_parent_modal">Product</label>
					<div class="col-lg-9">
						<div class="form-control-static" style="white-space: nowrap; overflow-x: hidden;"><%%COMBO(ProductID)%%><%%PLINK(ProductID)%%><%%ADDNEW(products)%%><span id="ProductIDLoading"></span></div>
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="Category" class="control-label col-lg-3">Category</label>
					<div class="col-lg-9">
						<div class="form-control-static" id="Category"></div>
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="CatalogPrice" class="control-label col-lg-3">Catalog Price <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#CatalogPrice-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block collapse" id="CatalogPrice-description"><div class="alert alert-info">This is the price of the product as specified in the products table. You could use that in the unit price field or specify another price.</div></span>

						<div class="form-control-static" id="CatalogPrice"></div>
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="UnitsInStock" class="control-label col-lg-3">Units In Stock <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#UnitsInStock-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block collapse" id="UnitsInStock-description"><div class="alert alert-info">Units remaining in stock. You shouldn't exceed that amount in the quantity field unless you know an incoming shipment will cover the missing quantity before the order required date.</div></span>

						<div class="form-control-static" id="UnitsInStock"></div>
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="UnitPrice" class="control-label col-lg-3">Unit Price <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#UnitPrice-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block collapse" id="UnitPrice-description"><div class="alert alert-info">This field will appear formatted as US currency in the table view.</div></span>

						<input maxlength="13" type="text" class="form-control" name="UnitPrice" id="UnitPrice" value="<%%VALUE(UnitPrice)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="Quantity" class="control-label col-lg-3">Quantity <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#Quantity-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block collapse" id="Quantity-description"><div class="alert alert-info">The table view displays the sum of all item quantities below the quantity column. Although meaningless, this just shows the sum feature provided by AppGini.</div></span>

						<input maxlength="" type="text" class="form-control" name="Quantity" id="Quantity" value="<%%VALUE(Quantity)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="Discount" class="control-label col-lg-3">Discount <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#Discount-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block collapse" id="Discount-description"><div class="alert alert-info">Enter a discount amount here rather than a percentage or ratio. This field will appear formatted as US currency in the table view.</div></span>

						<input maxlength="13" type="text" class="form-control" name="Discount" id="Discount" value="<%%VALUE(Discount)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="Subtotal" class="control-label col-lg-3">Subtotal <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#Subtotal-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block collapse" id="Subtotal-description"><div class="alert alert-info">This field is <a href="https://bigprof.com/appgini/help/calculated-fields">Automatically calculated</a>.</div></span>

						<div class="form-control-static" id="Subtotal"><%%VALUE(Subtotal)%%></div>
					</div>
				</div>

			</fieldset>
		</div>

		<!-- DV action buttons -->
		<hr class="hidden-md hidden-lg">
		<div class="col-md-4 col-lg-2" id="order_details_dv_action_buttons">
			<div class="btn-toolbar">
				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
					<%%UPDATE_BUTTON%%>
				</div><p></p>
				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
					<%%DESELECT_BUTTON%%>
					<%%DVPRINT_BUTTON%%>
					<%%DELETE_BUTTON%%>
				</div><p></p>
				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
					<%%INSERT_BUTTON%%>
				</div>
			</div>
		</div>
	</div>


</div><!-- /div class="panel-body" -->
	<script>
		$j(function() {
			var add_new_mode = (!$j('input[name=SelectedID]').val());
			var embedded_mode = ($j('input[name=Embedded]').val() == 1);

			/* auto-close embedded page? */
			var autoclose_mode = ($j('input[name=AutoClose]').val() == 1);
			var record_added_ok = (location.search.split('record-added-ok=').length == 2);
			var record_updated_ok = (location.search.split('record-updated-ok=').length == 2);
			if((record_added_ok || record_updated_ok) && embedded_mode && autoclose_mode) {
				setTimeout(AppGini.closeParentModal, 2000);
			}

			/* enable DV action buttons to float on scrolling down the form */
			enable_dvab_floating();

			setTimeout(AppGini.focusFirstFormElement, 1500);

			$j('form').eq(0).change(function() {
				if($j(this).data('already_changed')) return;
				if($j('#deselect').length) $j('#deselect').removeClass('btn-default').addClass('btn-warning').get(0).lastChild.data = " <%%TRANSLATION(Cancel)%%>";
				$j(this).data('already_changed', true);
			});

			$j('a[href="<%%TRANSLATION(ImageFolder)%%>"]').click(function() { /* */ return false; });


			if(!embedded_mode) {
				/* add a horizontal spacer to [add new parent] buttons that don't have a spacered element before them */
				$j('.add_new_parent').prev(':not(.hspacer-md)').next().addClass('hspacer-md');

				$j('.add_new_parent').click(function() {
					var pt = $j(this).attr('id').replace(/_add_new$/, '');
					modal_window({
						url: pt + '_view.php?addNew_x=1&Embedded=1',
						close: function() {
							var field_id = $j('#' + pt + '_add_new').prevAll('input:hidden').eq(0).attr('id');
							$j('#' + field_id + '-container').select2('focus').select2('focus');

							/* if a new parent was added, select it */
							var new_id = localStorage.getItem(pt + '_last_added_id');
							if(new_id === null) return;

							localStorage.clear(pt + '_last_added_id');
							AppGini.lookupText({
								id: new_id,
								table: 'order_details',
								field: field_id,
								callback: function(data) {
									$j('#' + field_id + '-container').select2('data', data, true);
								}
							});
						},
						size: 'full',
						title: $j(this).attr('title')
					});
				});
			}

			AppGini.hideViewParentLinks();

			$j('form').on('click', '.view_parent', function() {
				var pt = $j(this).attr('id').replace(/_view_parent$/, '');
				if($j(this).prevAll('input:hidden').length) {
					var parent_id = $j(this).prevAll('input:hidden').eq(0).val();
				}else{
					var parent_id = $j(this).prevAll().children('input:hidden').eq(0).val();
				}

				/* handle radio lookups */
				if($j(this).prevAll('[type=radio]').length) {
					parent_id = $j(this).prevAll('[type=radio]').eq(0).val();
				}

				if(parent_id != '{empty_value}' && parent_id != undefined && parent_id != '') {
					var parent_link = $j(this).parents('.form-group').children('label').data('parent_link');
					switch(parent_link) {
						case 'view_parent_hidden':
							break;
						case 'view_parent_modal':
							modal_window({
								url: pt + '_view.php?Embedded=1&SelectedID=' + encodeURIComponent(parent_id),
								close: function() {
									var field_id = $j('#' + pt + '_view_parent').prevAll('input:hidden').eq(0).attr('id');
									$j('#' + field_id + '-container').select2('focus').select2('focus');
								},
								size: 'full',
								title: $j(this).attr('title')
							});
							break;
						case 'view_parent_same_window':
							window.location = pt + '_view.php?Embedded=' + (embedded_mode ? '1' : '') + '&SelectedID=' + encodeURIComponent(parent_id);
							break;
						case 'view_parent_new_window':
							window.open(pt + '_view.php?SelectedID=' + encodeURIComponent(parent_id));
							break;
					}

				}
			});


			/* load admin tools for admin user */
			if(!add_new_mode) {
				$j('body').append('<div id="admin-tools-appendix"></div>');
				$j('#admin-tools-appendix').load(
					'ajax_admin_tools.php?table=order_details&id=<%%URLVALUE(odID)%%>',
					function(resp) {
						if(!resp.length) return;
						$j.ajax('ajax_admin_tools.php?action=get_admin_tools_js&table=order_details&id=<%%URLVALUE(odID)%%>');
					}
				);
			}

			/* warn user if 'add new' clicked while unsaved changes exist */
			$j('#addNew').click(function() {
				if($j('#deselect.btn-warning').length) {
					return confirm('<%%TRANSLATION(discard changes confirm)%%>');
				}
			});

		});
	</script>