Commit 30b2ecc5 by David Villalba

Guardamos perfil

parent 944d4390
...@@ -33,6 +33,13 @@ class Controller_Perfil_Index extends \Controller_App{ ...@@ -33,6 +33,13 @@ class Controller_Perfil_Index extends \Controller_App{
parent::before(); parent::before();
} }
/**
*
* Pantalla carga perfil
*
* @return Response
*/
public function action_index(){ public function action_index(){
$view = View::forge('perfil/index.twig'); $view = View::forge('perfil/index.twig');
...@@ -51,9 +58,14 @@ class Controller_Perfil_Index extends \Controller_App{ ...@@ -51,9 +58,14 @@ class Controller_Perfil_Index extends \Controller_App{
return Response::forge($view); return Response::forge($view);
} }
/**
* Guardamos datos perfil.
*
* @return bool
*/
public function post_update(){ public function post_update(){
$this->ws_profile_put(\Input::post('id'),\Input::post('inputs')); return $this->ws_profile_put(\Input::post('id'),\Input::post('inputs')) ? true : false;
} }
......
...@@ -25,18 +25,18 @@ trait Trait_InutraliaWS { ...@@ -25,18 +25,18 @@ trait Trait_InutraliaWS {
} }
/** /**
* Method to make requests to inutralia. *
* Metodo generico para relaizar peticiones al WS de inutralia
* *
* MORE INFO CURL --> http://php.net/manual/es/function.curl-setopt.php * MORE INFO CURL --> http://php.net/manual/es/function.curl-setopt.php
* *
* @param $parameter_url * @param $url
* @param bool $header * @param string $method
* @param int $timeout
* @param bool $httpget
* @param int $return_transfer * @param int $return_transfer
* @param array $extra_options --> Opciones extra para la request curl, arrat(key, opcion curl / value, valor curl).
* @param array $add_params_header --> Array para añadir mas opciones a la cabecera por defecto.
* @return mixed * @return mixed
*/ */
public function request_generic($url, $method = "get", $return_transfer = 1, $extra_options = array(),$add_params_header = array()){ public function request_generic($url, $method = "get", $return_transfer = 1, $extra_options = array(),$add_params_header = array()){
$constant = \Config::load('constants'); $constant = \Config::load('constants');
...@@ -98,10 +98,10 @@ trait Trait_InutraliaWS { ...@@ -98,10 +98,10 @@ trait Trait_InutraliaWS {
*/ */
public function ws_profile_put($id, $data){ public function ws_profile_put($id, $data){
$data_json = http_build_query($data); $data_json = json_encode($data);
$extra_options = array( $extra_options = array(
CURLOPT_CUSTOMREQUEST => 'put', CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $data_json CURLOPT_POSTFIELDS => $data_json
); );
......
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao data-profile" type="text" id="age" name="age" required="" value="{{ profile.age }}"/> <input class="input__field input__field--nao data-profile" type="text" id="age" rel="age" name="age" required="" value="{{ profile.age }}"/>
<label class="input__label input__label--nao" for="age"> <label class="input__label input__label--nao" for="age">
<span class="input__label-content input__label-content--nao">Edad</span> <span class="input__label-content input__label-content--nao">Edad</span>
</label> </label>
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
</span> </span>
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao data-profile" type="text" id="height" name="height" required="" value="{{ profile.height }}"/> <input class="input__field input__field--nao data-profile" type="text" id="height" rel="height" name="height" required="" value="{{ profile.height }}"/>
<label class="input__label input__label--nao" for="height"> <label class="input__label input__label--nao" for="height">
<span class="input__label-content input__label-content--nao">Altura</span> <span class="input__label-content input__label-content--nao">Altura</span>
</label> </label>
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</span> </span>
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao data-profile" type="text" id="weight" name="weight" required="" value="{{ profile.weight }}"/> <input class="input__field input__field--nao data-profile" type="text" id="weight" rel="weight" name="weight" required="" value="{{ profile.weight }}"/>
<label class="input__label input__label--nao" for="weight"> <label class="input__label input__label--nao" for="weight">
<span class="input__label-content input__label-content--nao">Peso</span> <span class="input__label-content input__label-content--nao">Peso</span>
</label> </label>
...@@ -28,15 +28,15 @@ ...@@ -28,15 +28,15 @@
</svg> </svg>
</span> </span>
<select class="cs-select cs-skin-underline mt20 data-profile" id="gender"> <select class="cs-select cs-skin-underline mt20 data-profile" rel="gender">
<option value="" {% if (profile.gender=='') %} selected {% endif %} disabled >Género...</option> <option value="" {% if (profile.gender=='') %} selected {% endif %} disabled >Género...</option>
<option value="1"{% if(profile.gender=='H') %} selected {% endif %} >Hombre</option> <option value="H"{% if(profile.gender=='H') %} selected {% endif %} >Hombre</option>
<option value="2"{% if(profile.gender=='M') %} selected {% endif %} >Mujer</option> <option value="M"{% if(profile.gender=='M') %} selected {% endif %} >Mujer</option>
</select> </select>
<select class="cs-select cs-skin-underline mt20 data-profile" id="physical" > <select class="cs-select cs-skin-underline mt20 data-profile" rel="physical" >
<option value="" {% if (profile.physical=='') %} selected {% endif %} disabled >Actividad fisica...</option> <option value="" {% if (profile.physical=='') %} selected {% endif %} disabled >Actividad fisica...</option>
<option value="1"{% if(profile.physical=='1') %} selected {% endif %} >Sedentario</option> <option value="1"{% if(profile.physical=='1') %} selected {% endif %} >Sedentario</option>
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<option value="5"{% if(profile.physical=='5') %} selected {% endif %} >Muy Intenso</option> <option value="5"{% if(profile.physical=='5') %} selected {% endif %} >Muy Intenso</option>
</select> </select>
<select class="cs-select cs-skin-underline mt20 data-profile" id="preference"> <select class="cs-select cs-skin-underline mt20 data-profile" rel="preference">
<option value="" {% if profile.preference == "" %} selected {% endif %}disabled>Preferencia de dieta...</option> <option value="" {% if profile.preference == "" %} selected {% endif %}disabled>Preferencia de dieta...</option>
<option value="1"{% if profile.preference == "1" %} selected {% endif %}>Normal</option> <option value="1"{% if profile.preference == "1" %} selected {% endif %}>Normal</option>
<option value="2"{% if profile.preference == "2" %} selected {% endif %}>Vegetariana</option> <option value="2"{% if profile.preference == "2" %} selected {% endif %}>Vegetariana</option>
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
<div class="row"> <div class="row">
{% endif %} {% endif %}
<div class="col-md-4 col-lg-4 visible-md visible-lg"> <div class="container-checkbox col-md-4 col-lg-4 visible-md visible-lg">
<div class="form-group text-center"> <div class="form-group text-center">
<label class="switch" for="{{ key }}"> <label class="switch" for="{{ key }}">
<input type="checkbox" class="data-profile" id="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/> <input type="checkbox" class="data-profile" id="{{ key }}" rel="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/>
<div class="slider round"></div> <div class="slider round"></div>
</label> </label>
<p>{{ value }}</p> <p>{{ value }}</p>
...@@ -52,10 +52,10 @@ ...@@ -52,10 +52,10 @@
<div class="row"> <div class="row">
{% endif %} {% endif %}
<div class="col-xs-6 col-sm-6 visible-xs visible-sm"> <div class="container-checkbox col-xs-6 col-sm-6 visible-xs visible-sm">
<div class="form-group text-center"> <div class="form-group text-center">
<label class="switch" for="{{ key }}"> <label class="switch" for="{{ "movil_"~key }}">
<input type="checkbox" class="data-profile" id="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/> <input type="checkbox" class="data-profile" id="{{ "movil_"~key }}" rel="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/>
<div class="slider round"></div> <div class="slider round"></div>
</label> </label>
<p>{{ value }}</p> <p>{{ value }}</p>
......
$(document).ready(function() { $(document).ready(function() {
/**
* Guardamos perfil
*/
$('#save-profile').on('click',function () { $('#save-profile').on('click',function () {
var inputs = {}; var inputs = {};
// Recorremos todos los inputs a guardar
$('.data-profile').map(function () { $('.data-profile').map(function () {
if( typeof $(this).attr('id') !== "undefined"){ if(typeof $(this).attr('rel') !== "undefined"){
// Si el input es de tipo checkout lo tratamos de forma diferente.
if($(this).attr('type') === "checkbox"){
// Exiten inputs ocultos (para movil) identicos a los visibles, con esto los diferenciamos.
if( $(this).closest('div.container-checkbox').css('display') !== 'none' ){
inputs[$(this).attr('rel')] = $(this).is(':checked') ? "1" : "0";
inputs[$(this).attr('id')] = $(this).attr('type') === "checkbox" ? $(this).is(':checked') : $(this).val(); }
}else{
inputs[$(this).attr('rel')] = $(this).val()
}
} }
...@@ -26,17 +49,16 @@ $(document).ready(function() { ...@@ -26,17 +49,16 @@ $(document).ready(function() {
}, },
success: function (data) { success: function (data) {
console.log(data); if(data != "" && data != 0){
// Modal success
}, }else{
error: function (data) { // Modal error
}
console.log(data);
location.reload();
} }
}) })
}) })
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment