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

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