<?php
Yii::app()->bootstrap->register();
if ($from_view_page == 'false') {
    echo '<input id="item_detail_hidden_input" name="ItemRequestHeader[items_detail_array]" type="hidden">';
    //echo $form->hiddenField($model, 'items_detail_array', array('id' => 'item_detail_hidden_input'));
}

if ($from_view_page != 'detail') {
    $box = $this->beginWidget('application.extensions.box.WhBox', array(
		'title' => Yii::t('default', 'Included Items'),
		'headerIcon' => 'icon-th-list',
		'htmlOptions' => array(
		    'style' => 'width: 1180px  !important;',
		),
//		'htmlContentOptions' => array(
//		    'style' => 'padding-bottom: 33px !important;padding-top: 33px !important;',
//		),
		    // when displaying a table, if we include bootstra-widget-table class
		    // the table will be 0-padding to the box
		    //'htmlOptions' => array('class' => 'bootstrap-widget-table')
	    ));
}
?>
<?php
//initial data
$dataArray = array();
$last_id = 0;
$item_detail_model_id = null;
if ($model->isNewRecord) {
    $dataArray = array();
    $last_id = 0;
    $item_detail_model_id = null;
} else {
    $dataArray = ItemRequestDetail::getItemsDetailData(ItemRequestDetail::getItemsDetail($model->id));
    $last_elem = end($dataArray);
    $last_id = ($last_elem != null) ? $last_elem['id'] : 0;
    $item_detail_model_id = $model->id;
}
?>
<script type='text/javascript'>
    var items_detail_array=new Array();
    
<?php
$items_detail_data = json_encode($dataArray);
//echo "var items_detail_array = " . $items_detail_data . ";\n";
$js_model_id = json_encode($item_detail_model_id);
echo "var model_id = " . $js_model_id . ";\n";
echo "var id = " . $last_id . ";\n";
echo "var location_id = " . (($location_id != null && $location_id != "") ? $location_id : '""') . ";\n";
?>
</script>
<?php
$dataProvider = new CArrayDataProvider($dataArray, array('id' => 'item_details', 'pagination' => false));
Yii::app()->controller->renderPartial('/itemRequestDetail/_grid', array('dataProvider' => $dataProvider, 'model_id' => $item_detail_model_id, 'from_view_page' => $from_view_page,'location_id'=>$location_id));
if ($from_view_page != 'detail') {
    $this->endWidget();
}
?>