This commit is contained in:
Michele Artini 2022-06-21 12:08:58 +02:00
parent 45673b832c
commit 4d6bc4b327
2 changed files with 37 additions and 16 deletions

View File

@ -1,7 +1,9 @@
var app = angular.module('vocabulariesApp', []);
app.controller('vocabulariesController', function($scope, $http) {
$scope.vocabularies = [];
$scope.vocabularies = [];
$scope.tmpVoc = {};
$scope.mode = '';
$scope.reload = function() {
$http.get('./api/vocs/?' + $.now()).then(function successCallback(res) {
@ -10,16 +12,30 @@ app.controller('vocabulariesController', function($scope, $http) {
alert('ERROR: ' + res.data.message);
});
};
$scope.prepareNewVoc = function() {
$scope.mode = 'new';
$scope.tmpVoc = {
'id' : '',
'name' : '',
'description' : ''
};
}
$scope.prepareEditVoc = function(voc) {
$scope.mode = 'edit';
$scope.tmpVoc = {
'id' : voc.id,
'name' : voc.name,
'description' : voc.description
};
}
$scope.newVocabulary = function(id, name, desc) {
$scope.saveVocabulary = function(voc) {
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
$http.post('./api/vocs/?' + $.now(), {
'id' : id,
'name' : name,
'description' : desc
}).then(function successCallback(res) {
$http.post('./api/vocs/?' + $.now(), voc).then(function successCallback(res) {
$scope.vocabularies = res.data;
alert("New vocabulary created");
alert("Vocabulary saved");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});

View File

@ -20,7 +20,7 @@
<h1>Information Service - Vocabularies</h1>
<hr />
<p>
<a href="javascript:void(0)" data-toggle="modal" data-target="#newVocabularyModal">create a new vocabulary</a>
<a href="javascript:void(0)" data-toggle="modal" data-target="#editVocabularyModal" ng-click="prepareNewVoc()">create a new vocabulary</a>
</p>
<p ng-show="vocabularies.length > 0">
<input type="text" class="form-control form-control-sm" ng-model="vocFilter" placeholder="Filter..."/>
@ -45,7 +45,10 @@
<th><a href="vocabularyEditor?id={{v.id}}">{{v.id}}</a></th>
<td>{{v.name}}</td>
<td>{{v.description}}</td>
<td align="right"><button type="button" class="btn btn-sm btn-danger" ng-click="deleteVocabulary(v.id)">delete</button></td>
<td align="right">
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editVocabularyModal" ng-click="prepareEditVoc(v)" >edit</button>
<button type="button" class="btn btn-sm btn-danger" ng-click="deleteVocabulary(v.id)">delete</button>
</td>
</tr>
</tbody>
</table>
@ -55,32 +58,34 @@
<!-- Modals -->
<div class="modal fade" tabindex="-1" id="newVocabularyModal">
<div class="modal fade" tabindex="-1" id="editVocabularyModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">New vocabulary</h4>
<h4 class="modal-title" ng-if="mode == 'new'">New vocabulary</h4>
<h4 class="modal-title" ng-if="mode == 'edit'">Edit vocabulary</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" ng-model="newVocId" />
<input ng-show="mode == 'new'" type="text" class="form-control" ng-model="tmpVoc.id" />
<input ng-show="mode == 'edit'" type="text" readonly class="form-control-plaintext" ng-model="tmpVoc.id" />
</div>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" ng-model="newVocName" />
<input type="text" class="form-control" ng-model="tmpVoc.name" />
</div>
<div class="form-group">
<label>Description</label>
<textarea class="form-control" ng-model="newVocDesc"></textarea>
<textarea class="form-control" ng-model="tmpVoc.description"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="newVocabulary(newVocId, newVocName, newVocDesc)">Submit</button>
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="saveVocabulary(tmpVoc)">Submit</button>
</div>
</div>
</div>