<style>
    #document-grid {
	width: auto !important;
    }

    #flash-msg-document .alert {
	width: 1065px !important;
    }

    #checklist_div > span > label{
	display: inline-block !important;
    }

     #checklist_div > span > input[type="radio"], #checklist_div > span > input[type="checkbox"] {
	margin: 0 !important;
    }
    

</style>

<?php
Yii::app()->bootstrap->register();
if ($from_view == null) {
    echo $form->hiddenField($model, 'document_array', array('id' => 'document_hidden_input'));

    echo $form->hiddenField($model, 'document_type_ids', array('id' => 'document_type_ids_input'));
}
?>
<?php
//initial data
$document_dataArray = array();
$last_id = 0;
$tid_id = null;
if ($model->isNewRecord) {
    $document_dataArray = array();
    $last_id = 0;
    $tid_id = null;
} else {
    $document_dataArray = Document::getModelDocumentData(Document::getModelDocuments($model->id));
    $last_elem = end($document_dataArray);
    $last_id = ($last_elem != null) ? $last_elem['id'] : 0;
    $tid_id = $model->id;
}
?>
<script type='text/javascript'>
<?php
$document_data = json_encode($document_dataArray);
echo "var document_array = " . $document_data . ";\n";

$last_id = json_encode($last_id);
echo "var document_id = " . $last_id . ";\n";

$js_model_id = json_encode($tid_id);
echo "var tid_id = " . $js_model_id . ";\n";

$document_type_ids = (!$model->isNewRecord) ? Tid::getSelectedDocumentTypeAsString($model->id) : '';
echo "var document_type_ids_value = '" . $document_type_ids . "';\n";
?>
</script>
<?php
$document_dataProvider = new CArrayDataProvider($document_dataArray, array('id' => 'documents'));
Yii::app()->controller->renderPartial('/document/_grid', array('dataProvider' => $document_dataProvider, 'model_id' => $tid_id, 'from_view' => $from_view));
?>