Selaa lähdekoodia

error dialog; ok cancel dialog

tags/0.1.0
Robin Thoni 8 vuotta sitten
vanhempi
commit
29f0ab8922

+ 12
- 0
src/modals/dialogerror.html Näytä tiedosto

@@ -0,0 +1,12 @@
1
+<div class="popin modal-content" xmlns="http://www.w3.org/1999/html">
2
+    <div class="modal-header">Error</div>
3
+    <div class="modal-body">
4
+        <div class="form-group">{{ message }}</div>
5
+        <div class="clearfix"></div>
6
+    </div>
7
+    <div class="modal-footer">
8
+        <button type="submit" class="btn btn-pink" ng-click="$dismiss()" ng-show="!showLogin">Close</button>
9
+        <button type="submit" class="btn btn-default" ng-click="$dismiss()" ng-show="showLogin">Cancel</button>
10
+        <button type="button" class="btn btn-pink" ng-click="reconnect()" ng-show="showLogin">Login</button>
11
+    </div>
12
+</div>

+ 16
- 0
src/modals/dialogerror.js Näytä tiedosto

@@ -0,0 +1,16 @@
1
+/**
2
+ * Created by robin on 11/3/15.
3
+ */
4
+
5
+'use strict';
6
+
7
+angular.module('luticateUtils').
8
+    controller('luticateDialogError', ['$scope', 'data', '$state', function ($scope, data, $state) {
9
+        $scope.message = data.message;
10
+        $scope.showLogin = data.data.Status == 401;
11
+        $scope.reconnect = function()
12
+        {
13
+            $scope.$dismiss();
14
+            $state.go('login');
15
+        };
16
+    }]);

+ 47
- 0
src/modals/dialogerrorhelper.js Näytä tiedosto

@@ -0,0 +1,47 @@
1
+/**
2
+ * Created by robin on 11/3/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateUtils')
8
+        .factory('luticateDialogErrorHelper', ['dialogs', function (dialogs) {
9
+
10
+            var luticateDialogErrorHelper = {};
11
+
12
+            luticateDialogErrorHelper.errorMessage = function(data)
13
+            {
14
+                var message = data.Data;
15
+                message += " (HTTP code: " + data.Status + ")";
16
+                /*var status = 'Common.Status.HttpStatus.' + data.status;
17
+                var statusText = tr(status);
18
+                if (status != statusText)
19
+                    message += " : " + statusText;*/
20
+                return message;
21
+            };
22
+
23
+            luticateDialogErrorHelper.errorDialog = function(data)
24
+            {
25
+                var message = luticateDialogErrorHelper.errorMessage(data);
26
+                dialogs.create('/luticateUtils/dialogerror.html', 'luticateDialogError', {message: message, data: data}, {keyboard: false, backdrop: 'static'});
27
+            };
28
+
29
+            return luticateDialogErrorHelper;
30
+        }]);
31
+})();
32
+
33
+angular.module("luticateUtils").run(["$templateCache", function($templateCache)
34
+{
35
+    $templateCache.put("/luticateUtils/dialogerror.html", '<div class="popin modal-content" xmlns="http://www.w3.org/1999/html">' +
36
+        '            <div class="modal-header">Error</div>' +
37
+        '        <div class="modal-body">' +
38
+        '        <div class="form-group">{{ message }}</div>' +
39
+        '        <div class="clearfix"></div>' +
40
+        '        </div>' +
41
+        '        <div class="modal-footer">' +
42
+        '        <button type="submit" class="btn btn-pink" ng-click="$dismiss()" ng-show="!showLogin">Close</button>' +
43
+        '        <button type="submit" class="btn btn-default" ng-click="$dismiss()" ng-show="showLogin">Cancel</button>' +
44
+        '        <button type="button" class="btn btn-pink" ng-click="reconnect()" ng-show="showLogin">Login</button>' +
45
+        '        </div>' +
46
+        '        </div>')
47
+}]);

+ 18
- 0
src/modals/dialogokcancel.html Näytä tiedosto

@@ -0,0 +1,18 @@
1
+<div class="popin modal-content" xmlns="http://www.w3.org/1999/html">
2
+    <form name="form" class="form-horizontal" ng-submit="__submit()">
3
+        <div class="modal-header">{{ title }}</div>
4
+        <div class="modal-body" lu-busy="modal">
5
+            <div class="form-group">
6
+                <ng-transclude></ng-transclude>
7
+            </div>
8
+            <div class="clearfix"></div>
9
+            <span class="error" ng-show="submitted">
10
+                <p class="error">{{ errorString }}</p>
11
+            </span>
12
+        </div>
13
+        <div class="modal-footer">
14
+            <button type="button" class="btn btn-default" ng-click="__cancel()">Cancel</button>
15
+            <button type="submit" class="btn btn-default" ng-enabled="!pending">OK</button>
16
+        </div>
17
+    </form>
18
+</div>

+ 89
- 0
src/modals/dialogokcancel.js Näytä tiedosto

@@ -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
+}]);

Loading…
Peruuta
Tallenna