Commit bb6c096b authored by wilhelmhb's avatar wilhelmhb

permettre de changer une ruche de rucher

parent dcdc4fb6
......@@ -65,6 +65,19 @@ function updateLocalHive(donnees) {
for(var field in donnees) {
donneesRuches.hivegroups[idHiveGroup].hives[idHive][field] = donnees[field];
}
if(donneesRuches.hivegroups[idHiveGroup].hives[idHive].id_hive_group != idHiveGroup) {
var id = donneesRuches.hivegroups[idHiveGroup].hives[idHive].id_hive_group;
var idHG;
for(var hivegroup in donneesRuches.hivegroups) {
if(donneesRuches.hivegroups[hivegroup].id_hive_group == id) {
idHG = hivegroup;
}
}
donneesRuches.hivegroups[idHG].hives.push(donneesRuches.hivegroups[idHiveGroup].hives[idHive]);
donneesRuches.hivegroups[idHiveGroup].hives.splice(idHive, 1);
idHive = donneesRuches.hivegroups[idHG].hives.length - 1;
idHiveGroup = idHG;
}
}
}
......
......@@ -152,7 +152,16 @@ function goToHiveGroupParameters() {
function goToHiveParameters() {
//console.log('goToHiveParameters : begin');
var template = $(templates).filter('#tpl-params-ruche').html();
var h = Mustache.render(template, donneesRuches.hivegroups[idHiveGroup].hives[idHive]);
var hivegroups = [];
console.log(idHiveGroup);
for(var hivegroup in donneesRuches.hivegroups) {
var h = donneesRuches.hivegroups[hivegroup];
h.isHiveGroup = hivegroup == idHiveGroup;
hivegroups.push(h);
}
var donneesHive = { 'hive' : donneesRuches.hivegroups[idHiveGroup].hives[idHive], 'hivegroups' : hivegroups };
console.log(hivegroups);
var h = Mustache.render(template, donneesHive);
document.getElementById("corps-params-ruche").innerHTML = h;
$("#sous_titre_pruche").children("h1").html(donneesRuches.hivegroups[idHiveGroup].hives[idHive].name);
......@@ -166,6 +175,7 @@ function goToHiveParameters() {
donneesRuches.hivegroups[idHiveGroup].hives[idHive].note = $("#apibundle_pshive_note").val();
donneesRuches.hivegroups[idHiveGroup].hives[idHive].latitude = $("#apibundle_pshive_latitude").val();
donneesRuches.hivegroups[idHiveGroup].hives[idHive].longitude = $("#apibundle_pshive_longitude").val();
donneesRuches.hivegroups[idHiveGroup].hives[idHive].id_hive_group = $("#apibundle_pshive_hivegroup").val();
donneesRuches.hivegroups[idHiveGroup].hives[idHive].hive_type = $("#apibundle_pshive_hiveType").val();
donneesRuches.hivegroups[idHiveGroup].hives[idHive].bees_type = $("#apibundle_pshive_beesType").val();
donneesRuches.hivegroups[idHiveGroup].hives[idHive].material = $("#apibundle_pshive_material").val();
......@@ -186,22 +196,24 @@ function goToHiveParameters() {
//console.log("début modif");
e.preventDefault();
var donnees = $(this).serialize();
//console.log(donnees);
console.log(donnees);
console.log(donneesRuches.hivegroups[idHiveGroup].hives[idHive]);
charge();
$.ajax({
type: 'PATCH',
url: url+'pshive/'+donneesRuches.hivegroups[idHiveGroup].hives[idHive].id_hive + '/update',
xhrFields: {
withCredentials: true
},
data: donnees + '&apibundle_pshive%5BidHiveGroup%5D=' + donneesRuches.hivegroups[idHiveGroup].id_hive_group,
data: donnees,
success: function(data) {
console.log(data);
//customer = data;
updateLocalHive(data);
console.log(donneesRuches.hivegroups[idHiveGroup].hives[idHive]);
/* go back to details */
goToDataHives(donneesRuches.hivegroups[idHiveGroup].hives[idHive].name, donneesRuches.hivegroups[idHiveGroup].hives[idHive].data,true);
finCharge();
goToDataHive(true);
//console.log("fin modif");
},
error: function (xhr, ajaxOptions, thrownError) {
......@@ -222,8 +234,8 @@ function submitParamsHive(){
var donnees = $("#form-params-hive").serialize();
//console.log(donnees);
console.log(donneesRuches.hivegroups[idHiveGroup].hives[idHive]);
charge();
$.ajax({
//charge();
/*$.ajax({
type: 'PATCH',
url: url+'pshive/'+donneesRuches.hivegroups[idHiveGroup].hives[idHive].id_hive + '/update',
xhrFields: {
......@@ -236,14 +248,14 @@ function submitParamsHive(){
updateLocalHive(data);
console.log(donneesRuches.hivegroups[idHiveGroup].hives[idHive]);
/* go back to details */
finCharge();
/*finCharge();
goToDataHive(true);
//console.log("fin modif");
},
error: function (xhr, ajaxOptions, thrownError) {
//console.log(xhr.responseText);
}
});
});*/
}
/**
......
......@@ -275,53 +275,60 @@
</div>-->
<div>
<label for="apibundle_pshive_name">Nom</label>
<input type="text" value="{{ name }}" id="apibundle_pshive_name" name="apibundle_pshive[name]" maxlength="64" />
<input type="text" value="{{ hive.name }}" id="apibundle_pshive_name" name="apibundle_pshive[name]" maxlength="64" />
<div class="cl"></div>
</div>
<!--<div>
<label for="apibundle_pshive_note">Note</label>
<textarea id="apibundle_pshive_note" name="apibundle_pshive[note]" maxlength="65535"></textarea>
</div>
</div>-->
<div>
<label for="apibundle_pshive_latitude">Latitude</label>
<input type="text" id="apibundle_pshive_latitude" value="{{ latitude }}" name="apibundle_pshive[latitude]" />
<input type="text" id="apibundle_pshive_latitude" value="{{ hive.latitude }}" name="apibundle_pshive[latitude]" />
<div class="cl"></div>
</div>
<div>
<label for="apibundle_pshive_longitude">Longitude</label>
<input type="text" id="apibundle_pshive_longitude" value="{{ longitude }}" name="apibundle_pshive[longitude]" />
<input type="text" id="apibundle_pshive_longitude" value="{{ hive.longitude }}" name="apibundle_pshive[longitude]" />
</div>
<div>
<label for="apibundle_pshive_hivegroup">Rucher</label>
<select type="text" id="apibundle_pshive_hivegroup" name="apibundle_pshive[idHiveGroup]">
{{#hivegroups}}
<option value="{{ id_hive_group }}" {{#isHiveGroup}}selected{{/isHiveGroup}}>{{ name }}</option>
{{/hivegroups}}
</select>
</div>
<div class="cl"></div>
<!--<div>
<label for="apibundle_pshive_active">En activité</label>
<input type="checkbox" id="apibundle_pshive_active" name="apibundle_pshive[active]" checked="{{ active }}"/>
<input type="checkbox" id="apibundle_pshive_active" name="apibundle_pshive[active]" checked="{{ hive.active }}"/>
</div>-->
<div>
<label for="apibundle_pshive_hiveType">Type de ruche</label>
<input type="text" value="{{ hive_type }}" id="apibundle_pshive_hiveType" name="apibundle_pshive[hiveType]" maxlength="64" />
<input type="text" value="{{ hive.hive_type }}" id="apibundle_pshive_hiveType" name="apibundle_pshive[hiveType]" maxlength="64" />
</div>
<div>
<label for="apibundle_pshive_beesType">Espèce d'abeilles</label>
<input type="text" value="{{ bees_type }}" id="apibundle_pshive_beesType" name="apibundle_pshive[beesType]" maxlength="64" />
<input type="text" value="{{ hive.bees_type }}" id="apibundle_pshive_beesType" name="apibundle_pshive[beesType]" maxlength="64" />
</div>
<div>
<label for="apibundle_pshive_material">Matériau</label>
<input type="text" value="{{ material }}" id="apibundle_pshive_material" name="apibundle_pshive[material]" maxlength="64" />
<input type="text" value="{{ hive.material }}" id="apibundle_pshive_material" name="apibundle_pshive[material]" maxlength="64" />
</div>
<div>
<label for="apibundle_pshive_support">Support</label>
<input type="text" value="{{ support }}" id="apibundle_pshive_support" name="apibundle_pshive[support]" maxlength="64" />
<input type="text" value="{{ hive.support }}" id="apibundle_pshive_support" name="apibundle_pshive[support]" maxlength="64" />
</div>
<div>
<label for="apibundle_pshive_state">État</label>
<input type="text" value="{{ state }}" id="apibundle_pshive_state" name="apibundle_pshive[state]" maxlength="64" />
<input type="text" value="{{ hive.state }}" id="apibundle_pshive_state" name="apibundle_pshive[state]" maxlength="64" />
</div>
<div>
<label for="apibundle_pshive_harvest" class="required">Récolte</label>
<input type="number" id="apibundle_pshive_harvest" value="{{ harvest }}" name="apibundle_pshive[harvest]" required="required" />
<input type="number" id="apibundle_pshive_harvest" value="{{ hive.harvest }}" name="apibundle_pshive[harvest]" required="required" />
</div>
<!--<div>
<label for="apibundle_pshive_notes">Notes</label>
......
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