aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/tools/web_config/js/app.js
blob: 6c5733898e6e0b8b0a907e74c9d17243ff155027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
fishconfig = angular.module("fishconfig", ["filters", "controllers"]);

fishconfig.config(
    ["$routeProvider", function($routeProvider) {
        $routeProvider
        .when("/colors", {
            controller: "colorsController",
            templateUrl: "partials/colors.html"
        })
        .when("/prompt", {
            controller: "promptController",
            templateUrl: "partials/prompt.html"
        })
        .when("/functions", {
            controller: "functionsController",
            templateUrl: "partials/functions.html"
        })
        .when("/variables", {
            controller: "variablesController",
            templateUrl: "partials/variables.html"
        })
        .when("/history", {
            controller: "historyController",
            templateUrl: "partials/history.html"
        })
        .when("/bindings", {
            controller: "bindingsController",
            templateUrl: "partials/bindings.html"
        })
        .when("/abbreviations", {
            controller: "abbreviationsController",
            templateUrl: "partials/abbreviations.html"
        })
        .otherwise({
            redirectTo: "/colors"
        })
    }]);

/* Inspired from http://blog.tomaka17.com/2012/12/random-tricks-when-using-angularjs/ */
fishconfig.config(function($httpProvider, $compileProvider) {
    var global_error_element = null;

    var showMessage = function(content) {
        global_error_element.text(content); 
    };
    
    $httpProvider.responseInterceptors.push(function($q) {
        return function(promise) {
            return promise.then(function(successResponse) {
                showMessage('');
                return successResponse;
            }, function(errorResponse) {
                switch (errorResponse.status) {
                    case 0:
                        showMessage("The request received an error. Perhaps the server has shut down.");
                        break;
                   case 500:
                        showMessage('Server internal error: ' + errorResponse.data);
                        break;
                    default:
                        showMessage('Error ' + errorResponse.status + ': ' + errorResponse.data);
                }
                return $q.reject(errorResponse);
            });
        };
    });

    $compileProvider.directive('errorMessage', function() {
        return {
            link: function(scope, element, attrs) { global_error_element = element; }
        };
    });
});