Commit 944d4390 by David Villalba

En proceso de guardar perfil ! WS put profile

parent 25f7a11d
...@@ -23,7 +23,7 @@ class Controller_Perfil_Index extends \Controller_App{ ...@@ -23,7 +23,7 @@ class Controller_Perfil_Index extends \Controller_App{
public function before(){ public function before(){
//Se cargan funciones de javascript especificas de esta funcionalidad //Se cargan funciones de javascript especificas de esta funcionalidad
Casset::js('dashboard/index.js'); Casset::js('perfil/index.js');
//Se marca la navegación en forma de migas de pan. Cada miga de pan la forman dos variables: //Se marca la navegación en forma de migas de pan. Cada miga de pan la forman dos variables:
// ds : String a mostrar // ds : String a mostrar
...@@ -46,9 +46,16 @@ class Controller_Perfil_Index extends \Controller_App{ ...@@ -46,9 +46,16 @@ class Controller_Perfil_Index extends \Controller_App{
//Paso de las opciones de menu que deben aparecer seleccionadas //Paso de las opciones de menu que deben aparecer seleccionadas
$view->option_menu = $this->_option_menu; $view->option_menu = $this->_option_menu;
$view -> profile = $this->ws_profile(); $view -> profile = $this->ws_profile_get();
return Response::forge($view); return Response::forge($view);
} }
public function post_update(){
$this->ws_profile_put(\Input::post('id'),\Input::post('inputs'));
}
} }
\ No newline at end of file
...@@ -15,10 +15,11 @@ trait Trait_InutraliaWS { ...@@ -15,10 +15,11 @@ trait Trait_InutraliaWS {
public function get_header(){ public function get_header(){
return array( return array(
'Content-Type: application/json', 'Content-Type: application/json',
'Accept: application/json', 'Accept: application/json',
'Authorization: Basic '. \Session::get('token_auth') 'Authorization: Basic '. \Session::get('token_auth'),
); );
} }
...@@ -36,22 +37,27 @@ trait Trait_InutraliaWS { ...@@ -36,22 +37,27 @@ trait Trait_InutraliaWS {
* @return mixed * @return mixed
*/ */
public function request_generic($parameter_url, $header = false, $timeout = 30, $httpget = true, $return_transfer = 1){ 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');
// La url la obtiene de config dependiendo del entorno. // La url la obtiene de config dependiendo del entorno.
$process = curl_init($constant[$parameter_url]); $ch = curl_init($constant['domain'].$url.$constant['apikey']);
curl_setopt($ch, CURLOPT_HTTPHEADER,array_merge($this->get_header(),$add_params_header));
curl_setopt($ch, $method == "get" ? CURLOPT_HTTPGET :CURLOPT_POST , 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_transfer);
foreach ($extra_options as $key => $value){
curl_setopt($ch, $key, $value);
}
curl_setopt($process, CURLOPT_HTTPHEADER,$this->get_header());
curl_setopt($process, CURLOPT_HEADER, $header);
curl_setopt($process, CURLOPT_TIMEOUT, $timeout);
curl_setopt($process, CURLOPT_HTTPGET , $httpget);
curl_setopt($process, CURLOPT_RETURNTRANSFER, $return_transfer);
$return = curl_exec($process); $return = curl_exec($ch);
curl_close($process); curl_close($ch);
return $return; return $return;
} }
...@@ -73,13 +79,35 @@ trait Trait_InutraliaWS { ...@@ -73,13 +79,35 @@ trait Trait_InutraliaWS {
} }
/** /**
* Request get profile * Reques profile get
*
* @param null $data
* @return mixed
*/ */
public function ws_profile(){ public function ws_profile_get(){
return json_decode($this->request_generic('profile')); return json_decode($this->request_generic('profile'));
} }
/**
* Reques profile put
*
* @param $data
* @return mixed
*/
public function ws_profile_put($id, $data){
$data_json = http_build_query($data);
$extra_options = array(
CURLOPT_CUSTOMREQUEST => 'put',
CURLOPT_POSTFIELDS => $data_json
);
return json_decode($this->request_generic('profile'.DS.$id,"post",1,$extra_options,array('Content-Length: ' . strlen($data_json))));
}
} }
\ No newline at end of file
...@@ -29,15 +29,11 @@ ...@@ -29,15 +29,11 @@
const DOMAIN = "http://inutralia20back"; const DOMAIN = "http://inutralia20back";
const V1 = '/api/v1/'; const V1 = '/api/v1/';
const APIKEY = "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e";
// PARAMETERS // PARAMETERS
const USER = 'user';
const PROFILE = 'profile';
return array( return array(
'user' => DOMAIN.V1.USER.APIKEY, 'domain' => DOMAIN.V1,
'profile' => DOMAIN.V1.PROFILE.APIKEY, 'apikey' => "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e"
); );
\ No newline at end of file
...@@ -25,17 +25,28 @@ return array( ...@@ -25,17 +25,28 @@ return array(
/*HOME*/ /*HOME*/
'dashboard' => 'dashboard/index', 'dashboard' => 'dashboard/index',
'perfil' =>'perfil/index',
// PERFIL
'perfil' => 'perfil/index',
'perfil/update' => 'perfil/index/update',
// MENU PERSONALIZADO
'menupersonalizado' =>'menupersonalizado/index', 'menupersonalizado' =>'menupersonalizado/index',
// MENU SALUDABLES
'menussaludables' =>'menussaludables/lista/index', 'menussaludables' =>'menussaludables/lista/index',
'menussaludables-menu' =>'menussaludables/menu/index', 'menussaludables-menu' =>'menussaludables/menu/index',
// RECETA
'receta-detalle' =>'receta/index', 'receta-detalle' =>'receta/index',
// RECETARIO
'recetario' =>'recetario/index', 'recetario' =>'recetario/index',
// BOLETIN SALUDABLE
'boletin-saludable' =>'boletinsaludable/index', 'boletin-saludable' =>'boletinsaludable/index',
// ARTICULO
'articulo-detalle' =>'articulo/index', 'articulo-detalle' =>'articulo/index',
......
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao" type="text" id="edad" name="edad" required="" value="{{ profile.age }}"/> <input class="input__field input__field--nao data-profile" type="text" id="age" name="age" required="" value="{{ profile.age }}"/>
<label class="input__label input__label--nao" for="input-1"> <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>
<svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none"> <svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
</span> </span>
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao" type="text" id="altura" name="altura" required="" value="{{ profile.height }}"/> <input class="input__field input__field--nao data-profile" type="text" id="height" name="height" required="" value="{{ profile.height }}"/>
<label class="input__label input__label--nao" for="input-1"> <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>
<svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none"> <svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
</span> </span>
<span class="input input--nao"> <span class="input input--nao">
<input class="input__field input__field--nao" type="text" id="peso" name="peso" required="" value="{{ profile.weight }}"/> <input class="input__field input__field--nao data-profile" type="text" id="weight" name="weight" required="" value="{{ profile.weight }}"/>
<label class="input__label input__label--nao" for="input-1"> <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>
<svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none"> <svg class="graphic graphic--nao" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</svg> </svg>
</span> </span>
<select class="cs-select cs-skin-underline mt20"> <select class="cs-select cs-skin-underline mt20 data-profile" id="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="1"{% if(profile.gender=='H') %} selected {% endif %} >Hombre</option>
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</select> </select>
<select class="cs-select cs-skin-underline mt20"> <select class="cs-select cs-skin-underline mt20 data-profile" id="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"> <select class="cs-select cs-skin-underline mt20 data-profile" id="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>
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
</div> </div>
<div class="container" > <div class="container" >
<input type="hidden" id="profile_id" value="{{ profile.id }}">
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="solid-box bg-color-perfil pb50"> <div class="solid-box bg-color-perfil pb50">
...@@ -29,7 +30,7 @@ ...@@ -29,7 +30,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-4 col-md-offset-8"> <div class="col-md-4 col-md-offset-8">
<button class="btn btn-custom btn-perfil mt20" ><i class="fa fa-save"></i> Guardar Perfil</button> <button class="btn btn-custom btn-perfil mt20" id="save-profile" ><i class="fa fa-save"></i> Guardar Perfil</button>
</div> </div>
</div> </div>
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<div class="col-md-4 col-lg-4 visible-md visible-lg"> <div class="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" id="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/> <input type="checkbox" class="data-profile" id="{{ 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>
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<div class="col-xs-6 col-sm-6 visible-xs visible-sm"> <div class="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="{{ key }}">
<input type="checkbox" id="{{ key }}" {% if attribute(profile, key) %} checked {% endif %}/> <input type="checkbox" class="data-profile" id="{{ 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() {
$('#save-profile').on('click',function () {
var inputs = {};
$('.data-profile').map(function () {
if( typeof $(this).attr('id') !== "undefined"){
inputs[$(this).attr('id')] = $(this).attr('type') === "checkbox" ? $(this).is(':checked') : $(this).val();
}
});
$.ajax({
url: "perfil/update",
type: "POST",
method:"post",
data: {
id: $('#profile_id').val(),
inputs: inputs
},
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
}
})
})
});
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