1

Hey i have a delete function works on http:

$scope.RemoveWorker=function(workerid){
    $http.delete("/ShiftWeb/rest/admin/removeworker?id="+workerid)
            .then(function(response){$scope.removeworker=response.data;
            alert("Worker " + workerid + " Deleted");
            $state.reload()
            console.log(response.data);
            }, function(error) {
                alert(error.data);
            }
            );
};

anybody knows how do i ask the client if he sure he wants to delete it or not. if he say no then dont delete it. help please :)

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Yair Gabbay
  • 57
  • 1
  • 6
  • 2
    Use [ui.bootstrap.modal](https://angular-ui.github.io/bootstrap/#!modal). But be aware modal dialogs can double error rates, increase time to task completion, and are near-universally despised by users. Alternate means of notification are often available and should be utilized wherever possible and appropriate. [ref](https://ux.stackexchange.com/questions/12637/what-research-is-there-suggesting-modal-dialogs-are-disruptive) – georgeawg Jul 13 '18 at 20:27
  • See [MDN Web API Reference - Window.confirm()](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm) – georgeawg Jul 13 '18 at 20:31
  • Kamlesh was way easier xD but ty! – Yair Gabbay Jul 13 '18 at 20:36
  • Kamlesh's way is easier, but george's suggestion is a better user experience. – BShaps Jul 13 '18 at 20:38
  • i didnt understand george suggestion xD... and i want to design the confirm way with the bootstrap. how do i use that :S? – Yair Gabbay Jul 13 '18 at 20:42
  • Check out the ui.bootstrap.modal link. You can make the buttons be confirm or deny and design the html for the modal however you like. Here is a SO question with a solid example of how to create what you're looking for: [reusable modal service](https://stackoverflow.com/questions/29602222/create-a-simple-bootstrap-yes-no-confirmation-or-just-notification-alert-in-angu) – BShaps Jul 13 '18 at 21:30
  • i dont know why i cant understand that.. im using this guide: https://www.w3schools.com/bootstrap4/bootstrap_modal.asp | https://prnt.sc/k67ypc | but when i press DELETE the screen turns grey and i cant press anything : http://prntscr.com/k67yrw help? my code is : – Yair Gabbay Jul 13 '18 at 21:43
  • http://prntscr.com/k67zc4 – Yair Gabbay Jul 13 '18 at 21:44

1 Answers1

3

You can modify the function as below using confirm function in which you can enter any message that will prompt user

$scope.RemoveWorker=function(workerid){
    if(confirm("Do you really want to delete this record ?")){
        $http.delete("/ShiftWeb/rest/admin/removeworker?id="+workerid)
             .then(function(response){$scope.removeworker=response.data;
               alert("Worker " + workerid + " Deleted");
               $state.reload()
              console.log(response.data);
              }, function(error) {
                    alert(error.data);
             });
     }
};
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Kamlesh
  • 511
  • 1
  • 7
  • 18
  • Starting with Chrome 46.0 this method is blocked inside an ` – georgeawg Jul 13 '18 at 20:36
  • how do i use the attribute value? allow-modal? – Yair Gabbay Jul 13 '18 at 20:43