Implement flag arrays

This commit is contained in:
nemunaire 2018-12-04 18:34:38 +01:00
parent 3056a19d09
commit dbf1985d25
6 changed files with 90 additions and 8 deletions

View file

@ -171,6 +171,10 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
angular.forEach(exercice.flags, function(flag, fid) {
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].value !== undefined)
data.exercices[eid].flags[fid].value = $scope.my.exercices[eid].flags[fid].value;
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].values !== undefined)
data.exercices[eid].flags[fid].values = $scope.my.exercices[eid].flags[fid].values;
else
data.exercices[eid].flags[fid].values = [""];
});
});
angular.forEach(data.exercices, function(exercice, eid) {
@ -270,6 +274,10 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
var cbs;
var cbd;
$scope.additem = function(key) {
key.values.push("");
};
$scope.ssubmit = function() {
var resp = {}
var check = undefined
@ -279,6 +287,22 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
{
resp["flags"] = {};
angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) {
if (flag.values !== undefined) {
if (flag.separator) {
for (var i = flag.values.length - 1; i >= 0; i--) {
if (!flag.values[i].length)
flag.values.splice(i, 1);
}
flag.value = flag.values.join(flag.separator) + flag.separator;
if (flag.values.length == 0)
flag.values = [""];
}
else
flag.value = flag.values[0];
}
if (flag.found == null) {
if (flag.soluce !== undefined) {
if (check === undefined) check = true;

View file

@ -88,15 +88,20 @@
<div class="form-group" ng-repeat="(kid,key) in my.exercices[current_exercice].flags">
<label for="sol_{{ kid }}">{{ key.label }}&nbsp;:</label>
<span ng-if="key.found && key.value" ng-bind="key.value"></span>
<div class="input-group">
<input type="text" class="form-control" id="sol_{{ kid }}" autocomplete="off" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && !key.choices">
<select class="custom-select" id="sol_{{ kid }}" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && key.choices" ng-options="l as v for (l, v) in key.choices"></select>
<div class="input-group" ng-repeat="v in key.values track by $index" ng-class="{'mt-1': !$first}" ng-if="!key.found">
<input type="text" class="form-control" id="sol_{{ kid }}_{{ $index }}" autocomplete="off" name="sol_{{ kid }}" ng-model="key.values[$index]" ng-if="!key.choices">
<select class="custom-select" id="sol_{{ kid }}" name="sol_{{ kid }}" ng-model="key.values[$index]" ng-if="key.choices" ng-options="l as v for (l, v) in key.choices"></select>
<div class="input-group-append" ng-if="key.choices_cost">
<button class="btn btn-success" type="button" ng-click="wantchoices(kid)" ng-class="{disabled: key.wcsubmitted}" title="Cliquez pour échanger ce champ de texte par une liste de choix. L'opération vous coûtera {{ key.choices_cost }} points.">
<span class="glyphicon glyphicon-tasks" aria-hidden="true"></span>
Liste de propositions ({{ key.choices_cost }} points)
</button>
</div>
<div class="input-group-append" ng-if="key.separator && $last">
<button class="btn btn-success" type="button" ng-click="additem(key)" title="Ajouter un élément.">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</div>
</div>
<small class="form-text text-muted" ng-if="!key.found && key.help.length > 0" ng-bind="key.help"></small>
<span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="key.found" title="Flag trouvé à {{ key.found | date:'mediumTime'}}"></span>