summaryrefslogtreecommitdiffstats
path: root/install/ui/src/freeipa/navigation.js
blob: 105e867cbb3a82e67f95774511c08b59d62570ba (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*  Authors:
 *    Petr Vobornik <pvoborni@redhat.com>
 *
 * Copyright (C) 2013 Red Hat
 * see file 'COPYING' for use and warranty information
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


define([
        'dojo/_base/lang',
        './navigation/routing'
       ],
       function(lang, routing) {


    var navigation = {
        /**
         * Navigation tells application to show certain facet.
         *
         * It's proxy for navigation/Router instance in current running
         * application.
         *
         * Modules just use the interface, they don't have to care about the logic in
         * the background.
         * @class navigation
         */

        /**
         * Sets property of params depending on arg type following way:
         *   for String sets params.facet
         *   for Facet sets params.facet  (based on show function)
         *   for Object sets params.args
         *   for Array sets params.pkeys
         *  @ignore
         *  @param Object params
         *  @param {Object|facet.facet|string|Function} arg
         */
        set_params: function(params, arg) {
            if (lang.isArray(arg)) {
                params.pkeys = arg;
            } else if (typeof arg === 'object') {

                if (typeof arg.show === 'function') params.facet = arg;
                else params.args = arg;
            } else if (typeof arg === 'string') {
                params.facet = arg;
            }
        },

        /**
         * Show facet.
         *
         * Takes 3 arguments:
         *    * facet(String or Facet)
         *    * pkeys (Array)
         *    * args (Object)
         *
         * Argument order is not defined. They are recognized based on their
         * type.
         *
         * When facet is defined as a string it has to be registered in
         * facet register.
         *
         * When it's an object (Facet) and has an entity set it will be
         * dealt as entity facet.
         * @method show
         * @param {Object|facet.facet|string|Function} arg1
         * @param {Object|facet.facet|string|Function} arg2
         * @param {Object|facet.facet|string|Function} arg3
         */
        show: function(arg1, arg2, arg3) {

            var params = {};

            this.set_params(params, arg1);
            this.set_params(params, arg2);
            this.set_params(params, arg3);

            var facet = params.facet;

            if (typeof facet === 'string') {
                return routing.navigate(['generic', facet, params.args]);
            }

            if (!facet) throw 'Argument exception: missing facet';

            if (facet && facet.entity) {
                return routing.navigate([
                    'entity',
                    facet.entity.name,
                    facet.name,
                    params.pkeys,
                    params.args]);
            } else {
                return routing.navigate(['generic', facet.name, params.args]);
            }
        },

        /**
         * Show entity facet
         *
         * arg1,arg2,arg3 are:
         *      facet name as String
         *      pkeys as Array
         *      args as Object
         * @method show_entity
         * @param String Enity name
         * @param {Object|facet.facet|string|Function} arg1
         * @param {Object|facet.facet|string|Function} arg2
         * @param {Object|facet.facet|string|Function} arg3
         */
        show_entity: function(entity_name, arg1, arg2, arg3) {
            var params = {};
            this.set_params(params, arg1);
            this.set_params(params, arg2);
            this.set_params(params, arg3);
            return routing.navigate(['entity', entity_name, params.facet,
                                                params.pkeys, params.args]);
        },

        /**
         * Uses lower level access
         *
         * `experimental`
         *
         * Navigates to generic page by changing hash.
         *
         * @param  {string} hash Hash of the change
         * @param  {Object} [facet] Facet we are navigating to. Usually used for
         *                          notification purposes
         */
        show_generic: function(hash, facet) {
            routing.router.navigate_to_hash(hash, facet);
        },

        /**
         * Show default facet
         * @method show_default
         */
        show_default: function() {
            routing.navigate(routing.default_path);
        }
    };
    return navigation;
});