From 8933c753171f4c56cb13fa295258889fa7a69442 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 23 Oct 2012 19:02:18 +0000 Subject: [PATCH] - Idiomas de candidatos git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@66 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d --- .../controllers/CandidatoController.php | 77 +++++++++++- www/protected/models/CandidatoIdioma.php | 112 ++++++++++++++++++ www/protected/models/Idioma.php | 11 +- .../profind/js/jquery.calculation.min.js | 14 +++ www/themes/profind/js/jquery.format.js | 21 ++++ www/themes/profind/js/profind-general.js | 21 +++- www/themes/profind/js/profind-template.js | 45 +++++++ .../profind/views/candidato/__idiomas.php | 88 ++++++++++++++ www/themes/profind/views/candidato/_form.php | 14 ++- www/themes/profind/views/layouts/main.php | 19 +-- 10 files changed, 389 insertions(+), 33 deletions(-) create mode 100644 www/protected/models/CandidatoIdioma.php create mode 100644 www/themes/profind/js/jquery.calculation.min.js create mode 100644 www/themes/profind/js/jquery.format.js create mode 100644 www/themes/profind/js/profind-template.js create mode 100644 www/themes/profind/views/candidato/__idiomas.php diff --git a/www/protected/controllers/CandidatoController.php b/www/protected/controllers/CandidatoController.php index 52815f2..d1a0492 100644 --- a/www/protected/controllers/CandidatoController.php +++ b/www/protected/controllers/CandidatoController.php @@ -74,20 +74,85 @@ class CandidatoController extends Controller { // $this->performAjaxValidation($candidato); if (isset($_POST['Candidato'])) { - $candidato->attributes = $_POST['Candidato']; - $ficheroFotografia = CUploadedFile::getInstance($candidato, 'ficheroFotografia'); + Yii::trace(CVarDumper::dumpAsString($_POST)); + // Candidato + $candidato->attributes = $_POST['Candidato']; + $ficheroFotografia = CUploadedFile::getInstance($candidato, 'ficheroFotografia'); $quitarFotografia = Yii::app()->request->getParam('quitar_fotografia', '0'); + + // Idiomas del candidato + $listaIdiomas = array(); + $listaIdiomasBorrar = array(); + foreach ($_POST['CandidatoIdioma'] as $key => $idioma) { + if ($idioma['id']) + $candidatoIdioma = CandidatoIdioma::model()->findByPk($idioma['id']); + else + $candidatoIdioma = new CandidatoIdioma(); + $candidatoIdioma->attributes = $idioma; + $candidatoIdioma->candidato_id = $candidato->id; + + if ($idioma['_borrar']) + $listaIdiomasBorrar[] = $candidatoIdioma; + else + $listaIdiomas[] = $candidatoIdioma; + + Yii::trace('Idioma ' . $key); + Yii::trace(CVarDumper::dumpAsString($candidatoIdioma->attributes)); + } + $candidato->idiomas = $listaIdiomas; + + Yii::trace('Idiomas a borrar'); + Yii::trace(CVarDumper::dumpAsString($listaIdiomasBorrar)); + + // Guardar los datos + $transaccion = Yii::app()->db->beginTransaction(); + try { + Yii::trace('Guardando el candidato', 'application.controllers.CandidatoController'); + if (!$candidato->save()) + throw new CException('Error al guardar el candidato'); - if ($candidato->save()) { - if (($quitarFotografia == '1') && ($candidato->fotografia->tieneFotografia())) + if (($quitarFotografia == '1') && ($candidato->fotografia->tieneFotografia())) { + Yii::trace('Eliminando la fotografía del candidato', 'application.controllers.CandidatoController'); $candidato->fotografia->eliminarFotografia(); - - if ($ficheroFotografia) + } + + if ($ficheroFotografia) { + Yii::trace('Guardando la fotografía del candidato', 'application.controllers.CandidatoController'); $candidato->fotografia->guardarFotografia($ficheroFotografia); + } + + if (!empty($listaIdiomasBorrar)) { + Yii::trace('Eliminando idiomas marcados para borrar', 'application.controllers.CandidatoController'); + foreach ($listaIdiomasBorrar as $candidatoIdioma) { + if (!$candidatoIdioma->delete()) + throw new CException('Error al eliminar un idioma del candidato'); + } + } + + if (!empty($candidato->idiomas)) { + Yii::trace('Guardando la lista de idiomas', 'application.controllers.CandidatoController'); + foreach ($candidato->idiomas as $candidatoIdioma) { + if (!$candidatoIdioma->save()) + throw new CException('Error al guardar un idioma del candidato'); + } + } + + $transaccion->commit(); + + Yii::trace('Candidato guardado', 'application.controllers.CandidatoController'); Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha actualizado el candidato')); $this->redirect(array('index')); + + } catch (Exception $e) { + Yii::trace($e->getMessage(), 'application.controllers.CandidatoController'); + + $transaccion->rollBack(); + $errores = array_merge($candidato->getErrors() /*, $nueva_empresa->getErrors(), $nueva_subscripcion->getErrors()*/); + foreach ($errores as $campo => $mensaje) $resultado[$campo] = $mensaje; + Yii::trace(CVarDumper::dumpAsString($resultado), 'application.controllers.CandidatoController'); + Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al actualizar el candidato')); } } diff --git a/www/protected/models/CandidatoIdioma.php b/www/protected/models/CandidatoIdioma.php new file mode 100644 index 0000000..a72f4d6 --- /dev/null +++ b/www/protected/models/CandidatoIdioma.php @@ -0,0 +1,112 @@ + 'Bajo', + self::NIVEL_MEDIO => 'Medio', + self::NIVEL_ALTO => 'Alto', + ); + } + + /** + * Returns the static model of the specified AR class. + * @param string $className active record class name. + * @return CandidatoIdioma the static model class + */ + public static function model($className = __CLASS__) { + return parent::model($className); + } + + /** + * @return string the associated database table name + */ + public function tableName() { + return 'tbl_candidatos_idiomas'; + } + + /** + * @return array validation rules for model attributes. + */ + public function rules() { + // NOTE: you should only define rules for those attributes that + // will receive user inputs. + return array( + array('candidato_id, idioma', 'required'), + array('candidato_id', 'numerical', 'integerOnly' => true), + array('idioma, conversacion, lectura_traduccion', 'length', 'max' => 255), + // The following rule is used by search(). + // Please remove those attributes that should not be searched. + array('id, candidato_id, idioma, conversacion, lectura_traduccion', 'safe', 'on' => 'search'), + ); + } + + /** + * @return array relational rules. + */ + public function relations() { + // NOTE: you may need to adjust the relation name and the related + // class name for the relations automatically generated below. + return array( + 'candidato' => array(self::BELONGS_TO, 'Candidato', 'candidato_id'), + ); + } + + /** + * @return array customized attribute labels (name=>label) + */ + public function attributeLabels() { + return array( + 'id' => 'ID', + 'candidato_id' => 'Candidato', + 'idioma' => 'Idioma', + 'conversacion' => 'Nivel en conversación', + 'lectura_traduccion' => 'Nivel en lectura/traducción', + ); + } + + /** + * Retrieves a list of models based on the current search/filter conditions. + * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. + */ + public function search() { + // Warning: Please modify the following code to remove attributes that + // should not be searched. + + $criteria = new CDbCriteria; + + $criteria->compare('id', $this->id); + $criteria->compare('candidato_id', $this->candidato_id); + $criteria->compare('idioma', $this->idioma, true); + $criteria->compare('conversacion', $this->conversacion, true); + $criteria->compare('lectura_traduccion', $this->lectura_traduccion, true); + + return new CActiveDataProvider($this, array( + 'criteria' => $criteria, + )); + } + +} \ No newline at end of file diff --git a/www/protected/models/Idioma.php b/www/protected/models/Idioma.php index fab2f3b..adfb0f4 100644 --- a/www/protected/models/Idioma.php +++ b/www/protected/models/Idioma.php @@ -30,7 +30,6 @@ class Idioma extends CActiveRecord { return array( array('descripcion', 'required'), array('descripcion', 'length', 'max' => 255), - array('id, descripcion', 'safe', 'on' => 'search'), ); } @@ -45,6 +44,15 @@ class Idioma extends CActiveRecord { ); } + /** + * @return array Default scope for this model. + */ + public function defaultScope() { + return array( + 'order' => 'descripcion' + ); + } + /** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. @@ -67,4 +75,5 @@ class Idioma extends CActiveRecord { } } + ?> \ No newline at end of file diff --git a/www/themes/profind/js/jquery.calculation.min.js b/www/themes/profind/js/jquery.calculation.min.js new file mode 100644 index 0000000..6a95055 --- /dev/null +++ b/www/themes/profind/js/jquery.calculation.min.js @@ -0,0 +1,14 @@ +/* + * jQuery Calculation Plug-in + * + * Copyright (c) 2007 Dan G. Switzer, II + * + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + * Revision: 12 + * Version: 0.4.08 + * +*/ +(function($){var defaults={reNumbers:/(-|-\$)?(\d+(,\d{3})*(\.\d{1,})?|\.\d{1,})/g,cleanseNumber:function(v){return v.replace(/[^0-9.\-]/g,"")},useFieldPlugin:(!!$.fn.getValue),onParseError:null,onParseClear:null};$.Calculation={version:"0.4.08",setDefaults:function(options){$.extend(defaults,options)}};$.fn.parseNumber=function(options){var aValues=[];options=$.extend(options,defaults);this.each(function(){var $el=$(this),sMethod=($el.is(":input")?(defaults.useFieldPlugin?"getValue":"val"):"text"),v=$.trim($el[sMethod]()).match(defaults.reNumbers,"");if(v==null){v=0;if(jQuery.isFunction(options.onParseError))options.onParseError.apply($el,[sMethod]);$.data($el[0],"calcParseError",true)}else{v=options.cleanseNumber.apply(this,[v[0]]);if($.data($el[0],"calcParseError")&&jQuery.isFunction(options.onParseClear)){options.onParseClear.apply($el,[sMethod]);$.data($el[0],"calcParseError",false)}}aValues.push(parseFloat(v,10))});return aValues};$.fn.calc=function(expr,vars,cbFormat,cbDone){var $this=this,exprValue="",precision=0,$el,parsedVars={},tmp,sMethod,_,bIsError=false;for(var k in vars){expr=expr.replace((new RegExp("("+k+")","g")),"_.$1");if(!!vars[k]&&!!vars[k].jquery){parsedVars[k]=vars[k].parseNumber()}else{parsedVars[k]=vars[k]}}this.each(function(i,el){var p,len;$el=$(this);sMethod=($el.is(":input")?(defaults.useFieldPlugin?"setValue":"val"):"text");_={};for(var k in parsedVars){if(typeof parsedVars[k]=="number"){_[k]=parsedVars[k]}else if(typeof parsedVars[k]=="string"){_[k]=parseFloat(parsedVars[k],10)}else if(!!parsedVars[k]&&(parsedVars[k]instanceof Array)){tmp=(parsedVars[k].length==$this.length)?i:0;_[k]=parsedVars[k][tmp]}if(isNaN(_[k]))_[k]=0;p=_[k].toString().match(/\.\d+$/gi);len=(p)?p[0].length-1:0;if(len>precision)precision=len}try{exprValue=eval(expr);if(precision)exprValue=Number(exprValue.toFixed(Math.max(precision,4)));if(jQuery.isFunction(cbFormat)){var tmp=cbFormat.apply(this,[exprValue]);if(!!tmp)exprValue=tmp}}catch(e){exprValue=e;bIsError=true}$el[sMethod](exprValue.toString())});if(jQuery.isFunction(cbDone))cbDone.apply(this,[this]);return this};$.each(["sum","avg","min","max"],function(i,method){$.fn[method]=function(bind,selector){if(arguments.length==0)return math[method](this.parseNumber());var bSelOpt=selector&&(selector.constructor==Object)&&!(selector instanceof jQuery);var opt=bind&&bind.constructor==Object?bind:{bind:bind||"keyup",selector:(!bSelOpt)?selector:null,oncalc:null};if(bSelOpt)opt=jQuery.extend(opt,selector);if(!!opt.selector)opt.selector=$(opt.selector);var self=this,sMethod,doCalc=function(){var value=math[method](self.parseNumber(opt));if(!!opt.selector){sMethod=(opt.selector.is(":input")?(defaults.useFieldPlugin?"setValue":"val"):"text");opt.selector[sMethod](value.toString())}if(jQuery.isFunction(opt.oncalc))opt.oncalc.apply(self,[value,opt])};doCalc();return self.bind(opt.bind,doCalc)}});var math={sum:function(a){var total=0,precision=0;$.each(a,function(i,v){var p=v.toString().match(/\.\d+$/gi),len=(p)?p[0].length-1:0;if(len>precision)precision=len;total+=v});if(precision)total=Number(total.toFixed(precision));return total},avg:function(a){return math.sum(a)/a.length},min:function(a){return Math.min.apply(Math,a)},max:function(a){return Math.max.apply(Math,a)}}})(jQuery); \ No newline at end of file diff --git a/www/themes/profind/js/jquery.format.js b/www/themes/profind/js/jquery.format.js new file mode 100644 index 0000000..de09a6f --- /dev/null +++ b/www/themes/profind/js/jquery.format.js @@ -0,0 +1,21 @@ +/* + * jQuery extensions for xForm + */ +$.format = function(source, params) { + if ( arguments.length == 1 ) + return function() { + var args = $.makeArray(arguments); + args.unshift(source); + return $.format.apply( this, args ); + }; + if ( arguments.length > 2 && params.constructor != Array ) { + params = $.makeArray(arguments).slice(1); + } + if ( params.constructor != Array ) { + params = [ params ]; + } + $.each(params, function(i, n) { + source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n); + }); + return source; +}; \ No newline at end of file diff --git a/www/themes/profind/js/profind-general.js b/www/themes/profind/js/profind-general.js index 40be38f..399e9d2 100644 --- a/www/themes/profind/js/profind-general.js +++ b/www/themes/profind/js/profind-general.js @@ -41,11 +41,17 @@ $(document).ready(function() { prettyPrint(); } //* external links - profind_external_links.init(); + //profind_external_links.init(); + + /* Chosen */ + //profind_chosen.init(); + //* accordion icons profind_acc_icons.init(); + //* main menu mouseover profind_nav_mouseover.init(); + //* top submenu profind_submenu.init(); @@ -61,7 +67,18 @@ profind_external_links = { }) } }; - + +//* external links +profind_chosen = { + init: function() { + $('.chosen').chosen({ + allow_single_deselect: true, + no_results_text: 'No existe' + }); + } +}; + + profind_sidebar = { init: function() { // sidebar onload state diff --git a/www/themes/profind/js/profind-template.js b/www/themes/profind/js/profind-template.js new file mode 100644 index 0000000..0203a86 --- /dev/null +++ b/www/themes/profind/js/profind-template.js @@ -0,0 +1,45 @@ +/** + * * This script depends on jquery.format.js + */ + + +$(document).ready(function() { + profind_template.init(); +}); + +profind_template = { + init: function() { + profind_template.hideHeaderIfEmpty(); + $(".add").click(function(){ + var template = jQuery.format(jQuery.trim($(this).siblings(".template").val())); + var place = $(this).parents(".templateFrame:first").children(".templateTarget"); + var i = place.find(".rowIndex").length>0 ? place.find(".rowIndex").max()+1 : 0; + $(template(i)).appendTo(place); + profind_template.showHeader(this); + return false; + }); + + $(".remove").live("click", function() { + if ($(this).siblings(".pk").val() === '') { + $(this).parents(".templateContent:first").remove(); + } else { + $(this).siblings(".to_remove").val(1); + $(this).parents(".templateContent:first").hide(); + } + profind_template.hideHeaderIfEmpty(); + return false; + }); + }, + + hideHeaderIfEmpty: function() { + var place = $('.templateTarget').filter(function(){return $.trim($(this).text())===''}); + $(place).siblings('.templateHead').hide(); + $(place).parents(".templateFrame:first").removeClass('table'); + }, + + showHeader: function(element) { + var place = $(element).parents(".templateFrame:first"); + $(place).children('.templateHead').show(); + $(place).addClass('table'); + } +}; diff --git a/www/themes/profind/views/candidato/__idiomas.php b/www/themes/profind/views/candidato/__idiomas.php new file mode 100644 index 0000000..5b7d79a --- /dev/null +++ b/www/themes/profind/views/candidato/__idiomas.php @@ -0,0 +1,88 @@ +clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery.format.js', CClientScript::POS_END); ?> +clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery.calculation.min.js', CClientScript::POS_END); ?> +clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/profind-template.js', CClientScript::POS_END); ?> + +
+
+
+ +
+ + + + + + + + + + + + idiomas as $i=>$idioma): ?> + + + + + + + + + + + + + +
+ findAll(), 'descripcion', 'descripcion'), + array('class' => 'span12') + ); + ?> + + opcionesNivel, + array('class' => 'span12') + ); + ?> + + opcionesNivel, + array('class' => 'span12') + ); + ?> + + 'pk')); ?> + + 'to_remove')); ?> + + +
+ + +
+
+
+
+
\ No newline at end of file diff --git a/www/themes/profind/views/candidato/_form.php b/www/themes/profind/views/candidato/_form.php index 5285a6f..6bee016 100644 --- a/www/themes/profind/views/candidato/_form.php +++ b/www/themes/profind/views/candidato/_form.php @@ -1,12 +1,12 @@ -clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-inputmask.js'); ?> -clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-fileupload.js'); ?> -clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/lib/chosen/chosen.jquery.min.js'); ?> +clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-inputmask.js', CClientScript::POS_END); ?> +clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-fileupload.js', CClientScript::POS_END); ?> +clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/lib/chosen/chosen.jquery.min.js', CClientScript::POS_END); ?> clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/lib/chosen/chosen.css'); ?> clientScript->registerScript('js_quitar_foto', $js_quitar_foto, CCli $js_init = <<beginWidget('CActiveForm', array(
-
+
labelEx($candidato, 'carnet_conducir', array('class' => 'control-label')); ?> @@ -267,6 +267,8 @@ $form = $this->beginWidget('CActiveForm', array(
+renderPartial('__idiomas', array('candidato' => $candidato)); ?> +
diff --git a/www/themes/profind/views/layouts/main.php b/www/themes/profind/views/layouts/main.php index a64bbdb..c1360c9 100644 --- a/www/themes/profind/views/layouts/main.php +++ b/www/themes/profind/views/layouts/main.php @@ -177,23 +177,6 @@
- - @@ -202,7 +185,7 @@ - +