<?php
/* @var $this DepartmentController */
/* @var $model Department */

$this->breadcrumbs=array(
	'Departments'=>array('index'),
	'Manage',
);

$this->pageTitle='Kelola Unit Kerja';

Yii::app()->clientScript->registerScript('search', "
	$('.add-button').click(function(){
		$('.add-form').toggle();
		return false;
		});
		$('.search-button').click(function(){
			$('.search-form').toggle();
			return false;
			});
			$('.search-form form').submit(function(){
				$('#department-grid').yiiGridView('update', {
					data: $(this).serialize()
					});
					return false;
					});

					function notificationForm(form, data, hasError){
						notification('Informasi','Data Berhasil di Simpan','success');
						if (!hasError){
							$.post(form.attr('action'), form.serialize(), function(res){
								if (res.result)
								console.log(res.data);
								});
							}
							$('#department-grid').yiiGridView('update', {
								data: $(this).serialize()
								});
								return false;
							}

							function notification(heading,data,color){
								$.extend(
								$.gritter.options, {
									position: 'bottom-right'
									});
									$.gritter.add({
										title: heading,
										text: data,
										class_name: 'color '+ color + ''
										});
									}

									");
									?>

									<span class="visible-xs">

										<?php echo CHtml::link('<i class="fa fa-plus"></i>','#',array('class'=>'add-button pull-right btn btn-primary btn-flat')); ?>
										<?php //echo CHtml::link('<i class="fa fa-search"></i>','#',array('class'=>'search-button pull-right btn btn-primary btn-flat')); ?>
									</span>

									<span class="hidden-xs">

										<?php echo CHtml::link('Tambah','#',array('class'=>'add-button pull-right btn btn-primary btn-flat')); ?>
										<?php //echo CHtml::link('Pencarian','#',array('class'=>'search-button pull-right btn btn-primary btn-flat')); ?>

									</span>

									<HR>

									<div class="add-form" style="display:none">
										<?php echo $this->renderPartial('_form', array('model'=>$model)); ?></div><!-- add-form -->

										<div class="search-form" style="display:none">
											<?php $this->renderPartial('_search',array(
												'model'=>$model,
											)); ?>
										</div><!-- search-form -->

										<?php $this->widget('zii.widgets.grid.CGridView', array(
											'id'=>'department-grid',
											'dataProvider'=>$model->search(),
											'itemsCssClass' => 'table-responsive table table-striped table-hover table-vcenter',
											'columns'=>array(

												array(
													'header'=>'No',
													'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1',
													'htmlOptions'=>array('width'=>'10px',
														'style' => 'text-align: center;')),

												// 'id_department',
												'name',
												// 'leader',
												// 'address',
												// 'email',
												// 'image',
												// 'website',
												/*
												'views',
												'status',
												'type',
												'created_id',
												'created_date',
												'update_id',
												'update_date',
												*/
												array(
													'class'=>'CButtonColumn',
													'template'=>'{update}',
													'buttons'=>array(
														'update'=>
														array(
															'url'=>'Yii::app()->createUrl("ppid/department/update", array("id"=>$data->id_department))',
															// 'options'=>array(
															// 	'ajax'=>array(
															// 		'type'=>'POST',
															// 		'url'=>"js:$(this).attr('href')",
															// 		'success'=>'function(data) { $("#viewModal .modal-body p").html(data); $("#viewModal").modal(); }'
															// 	),
															// ),
														),
													),
												),
											),
										)); ?>



										<!-- Modal -->
										<div class="modal fade" id="viewModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
											<div class="modal-dialog">
												<div class="modal-content">
													<!-- Popup Header -->
													<div class="modal-header">
														<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
														<h4 class="modal-title"><strong>Detail</strong> Department</h4>
													</div>
													<!-- Popup Content -->
													<div class="modal-body">
														<p>Data</p>
													</div>
												</div>
											</div>
										</div>


