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