admin: alert can contains yes/no buttons

This commit is contained in:
nemunaire 2017-11-12 14:42:54 +01:00 committed by Pierre-Olivier Mercier
parent 070807b485
commit 7b2fdaf0ad
3 changed files with 48 additions and 3 deletions

View File

@ -49,6 +49,8 @@ const indextpl = `<!DOCTYPE html>
<div ng-repeat="box in boxes" class="alert alert-dismissible alert-{{"{{ box.kind }}"}}" ng-cloak>
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong ng-if="box.title">{{"{{ box.title }}"}}</strong> {{"{{ box.msg }}"}}
<button class="btn btn-sm btn-success" ng-if="box.yes || box.no" ng-click="box.yes()">Yes</button>
<button class="btn btn-sm btn-danger" ng-if="box.yes || box.no" ng-click="box.no()">No</button>
</div>
</div>
<div class="row">

View File

@ -47,6 +47,8 @@
<div ng-repeat="box in boxes" class="alert alert-dismissible alert-{{ box.kind }}" ng-cloak>
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong ng-if="box.title">{{ box.title }}</strong> {{ box.msg }}
<button class="btn btn-sm btn-success" ng-if="box.yes || box.no" ng-click="box.yes()">Yes</button>
<button class="btn btn-sm btn-danger" ng-if="box.yes || box.no" ng-click="box.no()">No</button>
</div>
</div>
<div class="row">

View File

@ -266,7 +266,10 @@ angular.module("FICApp")
var b = $rootScope._newBoxes.shift();
$scope.boxes.unshift(b);
var id = $scope.boxes.length - 1;
$timeout(function() { $scope.boxes.pop(id); }, b.timeout);
b.cancel = function() {
$scope.boxes.pop($scope.boxes.indexOf(b));
}
$timeout(function() { b.cancel(); }, b.timeout);
}
}
@ -276,12 +279,45 @@ angular.module("FICApp")
if (msg === undefined) { msg = ''; }
if (tmout === undefined) { tmout = 5000; }
$rootScope._newBoxes.push({
var mybox = {
'kind': kind,
'title': title,
'msg': msg,
'timeout': tmout,
})
};
$rootScope._newBoxes.push(mybox);
};
$rootScope.newYesNoBox = function(kind, title, msg, yesFunc, noFunc, tmout) {
if (kind === undefined) { kind = 'default'; }
if (msg === undefined) { msg = ''; }
if (tmout === undefined) { tmout = 5000; }
var mybox;
var yesFn = function() {
mybox.cancel();
if (yesFunc !== undefined) {
yesFunc();
}
}
var noFn = function() {
mybox.cancel();
if (noFunc !== undefined) {
noFunc();
}
}
mybox = {
'kind': kind,
'title': title,
'msg': msg,
'yes': yesFn,
'no': noFn,
'timeout': tmout,
};
$rootScope._newBoxes.push(mybox);
};
$scope.boxes = new Array();
@ -311,6 +347,11 @@ angular.module("FICApp")
this.config.start = d.toISOString();
var f = new Date(ts + 120000 + this.duration * 60000);
this.config.end = f.toISOString();
$rootScope.newYesNoBox('info', 'Challenge ready to start,', 'propagate the changes?',
function() {
$scope.saveSettings();
});
}
$scope.reset = function(type) {
if (confirm("Êtes-vous sûr ?")) {