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 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Created by robin on 11/2/15.
  3. */
  4. angular.module('luticateUtils')
  5. .directive('dialogOkCancel', ['luticateDialogErrorHelper',
  6. function (luticateDialogErrorHelper) {
  7. return {
  8. restrict: 'EA',
  9. transclude: true,
  10. templateUrl: '/luticateUtils/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.__submit = function()
  17. {
  18. $scope.submitted = true;
  19. if ($scope.form.$valid) {
  20. $scope.pending = true;
  21. $scope.promise = $scope.submitForm();
  22. if ($scope.promise)
  23. {
  24. $scope.promise.then(function(data) {
  25. if ($scope.onDone) {
  26. $scope.onDone(data);
  27. }
  28. $scope.$close(data);
  29. $scope.pending = false;
  30. })
  31. .catch(function(error)
  32. {
  33. if ($scope.onError) {
  34. $scope.onError(error);
  35. }
  36. luticateDialogErrorHelper.errorDialog(error)
  37. .result.then(function(data)
  38. {
  39. }, function(error2)
  40. {
  41. $scope.$dismiss(error);
  42. });
  43. $scope.pending = false;
  44. });
  45. }
  46. else {
  47. $scope.$close();
  48. $scope.pending = false;
  49. }
  50. }
  51. };
  52. $scope.__cancel = function()
  53. {
  54. if ($scope.onCanceled) {
  55. $scope.onCanceled();
  56. }
  57. $scope.$dismiss();
  58. $scope.pending = false;
  59. };
  60. }
  61. };
  62. }]);
  63. angular.module("luticateUtils").run(["$templateCache", function($templateCache)
  64. {
  65. $templateCache.put("/luticateUtils/dialogokcancel.html", '<div class="popin modal-content" xmlns="http://www.w3.org/1999/html">' +
  66. '<form name="form" class="form-horizontal" ng-submit="__submit()">' +
  67. '<div class="modal-header">{{ title }}</div>' +
  68. '<div class="modal-body" lu-busy="modal">' +
  69. ' <div class="form-group">' +
  70. ' <ng-transclude></ng-transclude>' +
  71. ' </div>' +
  72. ' <div class="clearfix"></div>' +
  73. /*' <span class="error" ng-show="submitted">' +
  74. ' <p class="error">{{ errorString }}</p>' +
  75. '</span>' +*/
  76. '</div>' +
  77. '<div class="modal-footer">' +
  78. ' <button type="button" class="btn btn-inverse" ng-click="__cancel()">Cancel</button>' +
  79. ' <button type="submit" class="btn btn-primary" ng-enabled="!pending">OK</button>' +
  80. ' </div>' +
  81. ' </form>' +
  82. ' </div>')
  83. }]);