diff --git a/www/css/gridview2.css b/www/css/gridview2.css index ac265d0..99ce468 100644 --- a/www/css/gridview2.css +++ b/www/css/gridview2.css @@ -240,6 +240,18 @@ tr.even { background-color: #eee; } +tr.even.selected td { + background-color: #FFFCCC; +} + +tr.odd.selected td { + background-color: #FFFCCC; +} + +tr:hover { + background-color: #DDDDDD; +} + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DataTables cells classes */ @@ -289,15 +301,6 @@ td.details { } -table.display tr.even.row_selected td { - background-color: #B0BED9; -} - -table.display tr.odd.row_selected td { - background-color: #9FAFD1; -} - - /* * Sorting classes for columns */ diff --git a/www/protected/controllers/CandidatoController.php b/www/protected/controllers/CandidatoController.php index fa312b6..e7a2b88 100644 --- a/www/protected/controllers/CandidatoController.php +++ b/www/protected/controllers/CandidatoController.php @@ -27,13 +27,9 @@ class CandidatoController extends Controller { return array( array('allow', // allow authenticated user to perform 'create' and 'update' actions - 'actions'=>array('index','view','create','update','delete'), + 'actions'=>array('index','view','create','update','delete','admin'), 'users'=>array('@'), ), - array('allow', // allow admin user to perform 'admin' and 'delete' actions - 'actions'=>array('admin'), - 'users'=>array('admin'), - ), array('deny', // deny all users 'users'=>array('*'), ), @@ -114,10 +110,9 @@ class CandidatoController extends Controller if (isset($_POST['Candidato'])) { $model->attributes=$_POST['Candidato']; $foto=CUploadedFile::getInstance($model,'foto'); - - if ($model->validate()) { - $foundInvalidChild = false; - + + $foundInvalidChild = false; + if ($model->validate()) { if (!MultiModelForm::validate($model, $idiomasValidos, $idiomasBorrados)) $foundInvalidChild = true; @@ -133,7 +128,9 @@ class CandidatoController extends Controller { $this->guardarFoto($model->id, $foto); Yii::app()->user->setFlash('success', "Candidato dado de alta correctamente."); - $this->redirect(array('index')); + $url=$this->createUrl('index', array('id' => $model->id)); + //$this->redirect(array('index')); + $this->redirect($url); } } } @@ -211,9 +208,34 @@ class CandidatoController extends Controller } }*/ - if(isset($_POST['Candidato'])) { - $foto=CUploadedFile::getInstance($model,'foto'); + if (isset($_POST['Candidato'])) { $model->attributes=$_POST['Candidato']; + $foto=CUploadedFile::getInstance($model,'foto'); + + $foundInvalidChild = false; + if ($model->validate()) { + if (!MultiModelForm::validate($model, $idiomasValidos, $idiomasBorrados)) + $foundInvalidChild = true; + + if (!MultiModelForm::validate($model, $titulacionesValidas, $titulacionesBorradas)) + $foundInvalidChild = true; + } + + if (!$foundInvalidChild && $model->save() ) { + $masterValues = array ('candidato_id'=>$model->id); + + if (MultiModelForm::save($model, $idiomasValidos, $idiomasBorrados, $masterValues) && + MultiModelForm::save($model, $titulacionesValidas, $titulacionesBorradas, $masterValues)) + { + $this->guardarFoto($model->id, $foto); + Yii::app()->user->setFlash('success', "Candidato actualizado correctamente."); + $this->redirect(array('index')); + } + } + } + + + /*if(isset($_POST['Candidato'])) { //the value for the foreign key 'candidato_id' $masterValues = array ('candidato_id'=>$model->id); @@ -224,12 +246,14 @@ class CandidatoController extends Controller Yii::app()->user->setFlash('success', "Candidato actualizado correctamente."); //$this->redirect(array('view','id'=>$model->id)); } - } + }*/ $this->render('update',array( 'model'=>$model, 'idioma'=>$idioma, - 'validatedIdiomas'=>$validatedIdiomas, + 'titulacion'=>$titulacion, + 'idiomasValidos'=>$idiomasValidos, + 'titulacionesValidas'=>$titulacionesValidas, )); } @@ -257,85 +281,14 @@ class CandidatoController extends Controller /** * Lists all models. */ - public function actionIndex() + public function actionIndex($id) { $model=new Candidato('search'); $model->unsetAttributes(); // clear any default values - /*$columns = array( - array( - 'type' => 'html', - 'name' => 'nombreApellidos', - 'value' => 'CHtml::link(CHtml::encode($data->nombreApellidos), array("update", "id"=>$data->id));', - 'headerHtmlOptions'=>array( - 'class' => 'head0 sorting', - ), - ), - array( - 'type' => 'html', - 'name' => 'estado', - 'value' => 'CHtml::link(CHtml::encode($data->estado), "#", array("class" => $data->cssClassEstado));', - 'headerHtmlOptions'=>array( - 'class' => 'head1 sorting', - ), - ), - - array( - 'name' => 'id', - 'headerHtmlOptions'=>array( - 'class' => 'head0 sorting', - ), - ), - array( - 'name' => 'fecha_modificacion', - 'headerHtmlOptions'=>array( - 'class' => 'head1 sorting', - ), - ), - ); - - $sortableColumnNamesArray = array('estado', 'id', 'nombre'); - -$criteria = new CDbCriteria; -// bro-tip: $_REQUEST is like $_GET and $_POST combined -if (isset($_REQUEST['sSearch']) && isset($_REQUEST['sSearch']{0})) { - // use operator ILIKE if using PostgreSQL to get case insensitive search - $criteria->addSearchCondition('nombre', $_REQUEST['sSearch'], true, 'AND', 'LIKE'); -} - -$sort = new EDTSort('Candidato', $sortableColumnNamesArray); -$sort->defaultOrder = 'id'; -$pagination = new EDTPagination(); - -$dataProvider = new CActiveDataProvider('Candidato', array( - 'criteria' => $criteria, - 'pagination' => $pagination, - 'sort' => $sort, -)) ; - - $widget=$this->createWidget('ext.EDataTables.EDataTables', array( - 'id' => 'candidato-grid', - 'dataProvider' => $dataProvider, - 'cssFile' => Yii::app()->baseUrl . '/css/gridview.css', - 'ajaxUrl' => Yii::app()->createUrl('/candidato/index'), - 'filter' => Candidato::model(), - 'filterPosition'=> 'footer', - 'columns' => $columns, - )); */ - /*if(isset($_GET['Candidato'])) + if(isset($_GET['Candidato'])) $model->attributes=$_GET['Candidato']; - if (!Yii::app()->getRequest()->getIsAjaxRequest()) { - $this->render('index',array( - 'model'=>$model, - 'widget' => $widget, - )); - return; - } else { - echo json_encode($widget->getFormattedData(intval($_REQUEST['sEcho']))); - Yii::app()->end(); - }*/ - $this->render('index',array( 'model'=>$model)); } diff --git a/www/protected/controllers/UsuarioController.php b/www/protected/controllers/UsuarioController.php index 734f9cb..c75d0c7 100644 --- a/www/protected/controllers/UsuarioController.php +++ b/www/protected/controllers/UsuarioController.php @@ -122,11 +122,12 @@ class UsuarioController extends Controller { $model=new Usuario('search'); $model->unsetAttributes(); // clear any default values + if(isset($_GET['Usuario'])) $model->attributes=$_GET['Usuario']; $this->render('index',array( - 'model'=>$model, + 'model'=>$model, )); } diff --git a/www/protected/extensions/PageSize/PageSize.php b/www/protected/extensions/PageSize/PageSize.php index 94be87a..96838a6 100644 --- a/www/protected/extensions/PageSize/PageSize.php +++ b/www/protected/extensions/PageSize/PageSize.php @@ -18,9 +18,9 @@ class PageSize extends CWidget Yii::app()->user->setState('pageSize', $this->mPageSize); $this->mPageSize = null == $this->mPageSize ? $this->mDefPageSize : $this->mPageSize; - - echo Yii::t('pagesize', 'Mostrar '); - echo CHtml::dropDownList('pageSize', $this->mPageSize, $this->mPageSizeOptions,array( + + echo Yii::t('pagesize', 'Mostrar '); + echo CHtml::dropDownList('pageSize', $this->mPageSize, $this->mPageSizeOptions, array( 'onchange'=>"$.fn.yiiGridView.update('$this->mGridId',{ data:{pageSize: $(this).val() }})", )); echo Yii::t('pagesize', ' registros'); diff --git a/www/protected/extensions/SelGridView.php b/www/protected/extensions/SelGridView.php new file mode 100644 index 0000000..ce7da57 --- /dev/null +++ b/www/protected/extensions/SelGridView.php @@ -0,0 +1,162 @@ + +*/ + +Yii::import('zii.widgets.grid.CGridView'); + +/** +* SelGridView v1.1 +* +* SelGridView remembers selected rows of gridview when sorting or navigating by pages. Also it can select particular rows by GET param when page is loading +* +* Usage: +* Just put this file to extensions directory, create widget as usual and enjoy +* +*
+* $this->widget('application.extensions.SelGridView', array(
+* ...
+* ));
+*
+*/
+
+class SelGridView extends CGridView
+{
+ /**
+ * GET param name to pass selected row(s)
+ *
+ * @var mixed
+ */
+ public $selVar;
+
+ /**
+ * Creates column objects and initializes them.
+ * Automatically add hidden checkbox column.
+ */
+ protected function initColumns()
+ {
+ parent::initColumns();
+
+ if($this->selectableRows == 0) return;
+
+ if(empty($this->selVar)) {
+ $this->selVar = $this->dataProvider->getId().'_sel';
+ }
+
+ //if gridview already has user defined Checkbox column --> exit
+ foreach($this->columns as $col) {
+ if($col instanceof CCheckBoxColumn) return;
+ }
+
+ if($this->dataProvider instanceOf CActiveDataProvider) {
+ $primaryKey = '$data->primaryKey';
+ } elseif($this->dataProvider instanceOf CArrayDataProvider) {
+ $primaryKey = '$data["'.$this->dataProvider->keyField.'"]';
+ } else {
+ throw new CException('Unsupported DataProvider!');
+ }
+
+ //creating hidden checkbox column
+ $checkboxColumn = new CCheckBoxColumn($this);
+ $checkboxColumn->checked = 'isset($_GET["'.$this->selVar.'"]) ? in_array('.$primaryKey.', is_array($_GET["'.$this->selVar.'"]) ? $_GET["'.$this->selVar.'"] : array($_GET["'.$this->selVar.'"])) : false;';
+ $checkboxColumn->htmlOptions = array('style'=>'display:none');
+ $checkboxColumn->headerHtmlOptions = array('style'=>'display:none');
+ $checkboxColumn->init();
+
+ $this->columns[] = $checkboxColumn;
+ }
+
+ /**
+ * Registers necessary client scripts.
+ * Automaticlly prepend user's beforeajaxUpdate with needed code that will modify GET params when navigating and sorting
+ */
+ public function registerClientScript()
+ {
+ if($this->selectableRows > 0) $this->applyBeforeAjaxUpdate();
+ parent::registerClientScript();
+ }
+
+ /**
+ * prepending user's beforeajaxUpdate with needed code
+ *
+ */
+ protected function applyBeforeAjaxUpdate()
+ {
+ $funcChangeQuery = '
+ function(id, options) {
+ if(this.selectableRows == 0) return;
+
+ //all GET params in current url
+ var params = $.deparam.querystring(options.url);
+
+ //GET param named "{ModelClass}_sel" showing selected rows in whole grid (not only current page)
+ var selVar = "'.$this->selVar.'";
+ var checkedInQuery = (params[selVar]) ? params[selVar] : [];
+ if(!$.isArray(checkedInQuery)) checkedInQuery = [checkedInQuery];
+
+ //rows selected on current page
+ var checkedInPage = $.fn.yiiGridView.getSelection(id);
+
+ //if only one row can be selected - logic is simple: if any row selected on current page, clear all previously selected
+ if(this.selectableRows == 1) {
+ if(!checkedInPage.length) return;
+ params[selVar] = checkedInPage;
+ options.url = $.param.querystring(options.url, params);
+ return;
+ }
+
+ //iterating all keys of this page
+ $("#"+id).find(".keys span").each(function (i) {
+ var key = $(this).text();
+
+ //row found in GET params
+ var indexInQuery = $.inArray(key, checkedInQuery);
+
+ //row is checked on current page
+ var indexInChecked = $.inArray(key, checkedInPage);
+
+ //row is selected and not in GET params --> adding to GET params
+ if(indexInChecked >= 0 && indexInQuery == -1) {
+ checkedInQuery.push(key);
+ }
+
+ //row not selected, but in GET params due to selected previously --> deleting from GET params
+ if(indexInChecked == -1 && indexInQuery >= 0) {
+ delete checkedInQuery[indexInQuery];
+ }
+ });
+
+ if(!checkedInQuery) {
+ if(params[selVar]) delete params[selVar];
+ } else {
+ params[selVar] = checkedInQuery;
+ }
+
+ options.url = $.param.querystring( options.url, params);
+ }
+ ';
+
+ if(empty($this->beforeAjaxUpdate)) {
+ //no user defined ajaxUpdate handler. Simply use SelGridView's
+ $this->beforeAjaxUpdate = $funcChangeQuery;
+ } else {
+
+ //beforeAjaxUpdate = function or direct JS code
+ if(preg_match('/(function.+\})/is', $this->beforeAjaxUpdate, $matches)) {
+ $userScript = '('.$matches[0].')(id, options);';
+ } else {
+ $userScript = $this->beforeAjaxUpdate;
+ }
+
+ //merge to one beforeAjaxUpdate function
+ $this->beforeAjaxUpdate = '
+ function(id, options) {
+ ('.$funcChangeQuery.')(id, options);
+ '.$userScript.'
+ }
+ ';
+ }
+ }
+}
diff --git a/www/protected/models/Candidato.php b/www/protected/models/Candidato.php
index 3908364..6e1822e 100644
--- a/www/protected/models/Candidato.php
+++ b/www/protected/models/Candidato.php
@@ -96,6 +96,7 @@ class Candidato extends CActiveRecord
return array(
array('nombre, apellidos', 'required'),
array('email', 'unique'),
+ array('email', 'email'),
array('foto', 'file',
'types'=>'jpg',
'maxSize'=>1024 * 1024 * 1, // 1MB como máximo
@@ -156,28 +157,33 @@ class Candidato extends CActiveRecord
*/
public function search()
{
- // Warning: Please modify the following code to remove attributes that
- // should not be searched.
+ // Warning: Please modify the following code to remove attributes that
+ // should not be searched.
- $criteria=new CDbCriteria;
+ $criteria=new CDbCriteria;
- $criteria->compare('id',$this->id);
- $criteria->compare('estado',$this->estado,true);
- $criteria->compare('dni',$this->dni,true);
- $criteria->compare('nombre',$this->nombre,true);
- $criteria->compare('apellidos',$this->apellidos,true);
- $criteria->compare('email',$this->email,true);
- $criteria->compare('telefono_fijo',$this->telefono_fijo,true);
- $criteria->compare('telefono_movil',$this->telefono_movil,true);
- $criteria->compare('sexo',$this->sexo,true);
- $criteria->compare('fecha_nacimiento',$this->fecha_nacimiento,true);
- $criteria->compare('lugar_nacimiento',$this->lugar_nacimiento,true);
+ $criteria->compare('id',$this->id);
+ $criteria->compare('estado',$this->estado,true);
+ $criteria->compare('dni',$this->dni,true);
+ $criteria->compare('nombre',$this->nombre,true);
+ $criteria->compare('apellidos',$this->apellidos,true);
+ $criteria->compare('email',$this->email,true);
+ $criteria->compare('telefono_fijo',$this->telefono_fijo,true);
+ $criteria->compare('telefono_movil',$this->telefono_movil,true);
+ $criteria->compare('sexo',$this->sexo,true);
+ $criteria->compare('fecha_nacimiento',$this->fecha_nacimiento,true);
+ $criteria->compare('lugar_nacimiento',$this->lugar_nacimiento,true);
- //$criteria->compare('nombreApellidos',$this->nombreApellidos,true);
+ //$criteria->compare('nombreApellidos',$this->nombreApellidos,true);
+
+ $sort = new CSort;
+ $sort->defaultOrder = 'nombre, apellidos ASC';
+
+ return new CActiveDataProvider($this, array(
+ 'criteria' => $criteria,
+ 'sort' => $sort,
+ ));
- return new CActiveDataProvider($this, array(
- 'criteria'=>$criteria,
- ));
}
protected function beforeValidate() {
diff --git a/www/protected/views/candidato/index.php b/www/protected/views/candidato/index.php
index f5a0b72..bc93292 100644
--- a/www/protected/views/candidato/index.php
+++ b/www/protected/views/candidato/index.php
@@ -9,8 +9,15 @@ $this->menu=array(
'url'=>array('create'),
'linkOptions'=>array('class'=>'iconlink'),
),
+ array(
+ 'label'=>'-You may optionally enter a comparison operator (<, <=, >, >=, <> -or =) at the beginning of each of your search values to specify how the comparison should be done. -
- -'search-button')); ?> + + -widget('ext.EDataTables.EDataTables', array( - 'id' => 'candidatos', - 'options' => array( - 'class' => 'dataTables_wrapper', + +-You may optionally enter a comparison operator (<, <=, >, >=, <> -or =) at the beginning of each of your search values to specify how the comparison should be done. -
- +