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
|
/* 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/>.
*/
/**
* 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.
*/
define([
'dojo/_base/lang',
'./app', // creates circular dependency
'./ipa',
'exports' // for handling circular dependency
],
function(lang, app, IPA, exports) {
var get_router = function() {
return app.app.router;
},
/**
* 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
*
* @param Object params
* @param {Object|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. //FIXME: not yet implemented
*
* When it's an object (Facet) and has an entity set it will be
* dealt as entity facet.
*
*/
show = function(arg1, arg2, arg3) {
var nav = get_router();
var params = {};
set_params(params, arg1);
set_params(params, arg2);
set_params(params, arg3);
var facet = params.facet;
if (typeof facet === 'string') {
// FIXME: doesn't work at the moment
throw 'Not yet supported';
//facet = IPA.get_facet(facet);
}
if (!facet) throw 'Argument exception: missing facet';
if (facet && facet.entity) {
return nav.navigate_to_entity_facet(
facet.entity.name,
facet.name,
params.pkeys,
params.args);
} else {
return nav.navigate_to_facet(facet.name, params.args);
}
},
/**
* Show entity facet.
*
* @param String Enity name
* @param {Object|Facet|String|Function} arg1
* @param {Object|Facet|String|Function} arg2
* @param {Object|Facet|String|Function} arg3
*
* arg1,arg2,arg3 are:
* facet name as String
* pkeys as Array
* args as Object
*/
show_entity = function(entity_name, arg1, arg2, arg3) {
var nav = get_router();
var params = {};
set_params(params, arg1);
set_params(params, arg2);
set_params(params, arg3);
return nav.navigate_to_entity_facet(entity_name, params.facet,
params.pkeys, params.args);
},
show_default = function() {
// TODO: make configurable
return show_entity('user', 'search');
};
// Module export
exports = {
show: show,
show_entity: show_entity,
show_default: show_default
};
return exports;
});
|