You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dialogokcancel.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Created by robin on 11/2/15.
  3. */
  4. angular.module('luticate')
  5. .directive('dialogOkCancel', [
  6. function () {
  7. return {
  8. restrict: 'EA',
  9. transclude: true,
  10. templateUrl: 'views/directives/dialogokcancel.html',
  11. link: function link($scope, element, attrs) {
  12. $scope.title = attrs.title;
  13. $scope.model = {};
  14. $scope.pending = false;
  15. $scope.submitted = false;
  16. $scope.errorString = "";
  17. $scope.__submit = function()
  18. {
  19. $scope.submitted = true;
  20. $scope.errorString = "";
  21. if ($scope.form.$valid) {
  22. $scope.pending = true;
  23. $scope.promise = $scope.submitForm();
  24. if ($scope.promise)
  25. {
  26. $scope.promise.then(function(data) {
  27. if ($scope.onDone) {
  28. $scope.onDone(data);
  29. }
  30. $scope.$close(data);
  31. $scope.pending = false;
  32. })
  33. .catch(function(error)
  34. {
  35. if ($scope.onError) {
  36. $scope.onError(error);
  37. }
  38. if (error.Data) {
  39. $scope.errorString = error.Data;
  40. }
  41. else {
  42. $scope.errorString = error;
  43. }
  44. $scope.pending = false;
  45. });
  46. }
  47. else {
  48. $scope.$close();
  49. $scope.pending = false;
  50. }
  51. }
  52. };
  53. $scope.__cancel = function()
  54. {
  55. if ($scope.onCanceled) {
  56. $scope.onCanceled();
  57. }
  58. $scope.$dismiss();
  59. $scope.pending = false;
  60. };
  61. }
  62. };
  63. }]);