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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.__submit = function()
  16. {
  17. if ($scope.form.$valid) {
  18. $scope.pending = true;
  19. $scope.promise = $scope.submitForm();
  20. if ($scope.promise)
  21. {
  22. $scope.promise.then(function(data) {
  23. if ($scope.onDone) {
  24. $scope.onDone(data);
  25. }
  26. $scope.$close(data);
  27. $scope.pending = false;
  28. })
  29. .catch(function(error)
  30. {
  31. if ($scope.onError) {
  32. $scope.onError(error);
  33. }
  34. $scope.pending = false;
  35. });
  36. }
  37. else {
  38. $scope.$close();
  39. $scope.pending = false;
  40. }
  41. }
  42. };
  43. $scope.__cancel = function()
  44. {
  45. if ($scope.onCanceled) {
  46. $scope.onCanceled();
  47. }
  48. $scope.$dismiss();
  49. $scope.pending = false;
  50. };
  51. }
  52. };
  53. }]);