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

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