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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| (function ()
{
'use strict';
angular
.module('app.toolbar')
.controller('ToolbarController', ToolbarController);
/** @ngInject */
function ToolbarController($rootScope, $q, $state, $timeout, $mdSidenav, $translate, $mdToast, msNavigationService)
{
var vm = this;
// Data
$rootScope.global = {
search: ''
};
vm.bodyEl = angular.element('body');
vm.userStatusOptions = [
{
'title': 'Online',
'icon' : 'icon-checkbox-marked-circle',
'color': '#4CAF50'
},
{
'title': 'Away',
'icon' : 'icon-clock',
'color': '#FFC107'
},
{
'title': 'Do not Disturb',
'icon' : 'icon-minus-circle',
'color': '#F44336'
},
{
'title': 'Invisible',
'icon' : 'icon-checkbox-blank-circle-outline',
'color': '#BDBDBD'
},
{
'title': 'Offline',
'icon' : 'icon-checkbox-blank-circle-outline',
'color': '#616161'
}
];
vm.languages = {
en: {
'title' : 'English',
'translation': 'TOOLBAR.ENGLISH',
'code' : 'en',
'flag' : 'us'
},
es: {
'title' : 'Spanish',
'translation': 'TOOLBAR.SPANISH',
'code' : 'es',
'flag' : 'es'
},
tr: {
'title' : 'Turkish',
'translation': 'TOOLBAR.TURKISH',
'code' : 'tr',
'flag' : 'tr'
}
};
// Methods
vm.toggleSidenav = toggleSidenav;
vm.logout = logout;
vm.changeLanguage = changeLanguage;
vm.setUserStatus = setUserStatus;
vm.toggleHorizontalMobileMenu = toggleHorizontalMobileMenu;
vm.toggleMsNavigationFolded = toggleMsNavigationFolded;
vm.search = search;
vm.searchResultClick = searchResultClick;
//////////
init();
/**
* Initialize
*/
function init()
{
// Select the first status as a default
vm.userStatus = vm.userStatusOptions[0];
// Get the selected language directly from angular-translate module setting
vm.selectedLanguage = vm.languages[$translate.preferredLanguage()];
}
/**
* Toggle sidenav
*
* @param sidenavId
*/
function toggleSidenav(sidenavId)
{
$mdSidenav(sidenavId).toggle();
}
/**
* Sets User Status
* @param status
*/
function setUserStatus(status)
{
vm.userStatus = status;
}
/**
* Logout Function
*/
function logout()
{
// Do logout here..
}
/**
* Change Language
*/
function changeLanguage(lang)
{
vm.selectedLanguage = lang;
/**
* Show temporary message if user selects a language other than English
*
* angular-translate module will try to load language specific json files
* as soon as you change the language. And because we don't have them, there
* will be a lot of errors in the page potentially breaking couple functions
* of the template.
*
* To prevent that from happening, we added a simple "return;" statement at the
* end of this if block. If you have all the translation files, remove this if
* block and the translations should work without any problems.
*/
if ( lang.code !== 'en' )
{
var message = 'Fuse supports translations through angular-translate module, but currently we do not have any translations other than English language. If you want to help us, send us a message through ThemeForest profile page.';
$mdToast.show({
template : '<md-toast id="language-message" layout="column" layout-align="center start"><div class="md-toast-content">' + message + '</div></md-toast>',
hideDelay: 7000,
position : 'top right',
parent : '#content'
});
return;
}
// Change the language
$translate.use(lang.code);
}
/**
* Toggle horizontal mobile menu
*/
function toggleHorizontalMobileMenu()
{
vm.bodyEl.toggleClass('ms-navigation-horizontal-mobile-menu-active');
}
/**
* Toggle msNavigation folded
*/
function toggleMsNavigationFolded()
{
msNavigationService.toggleFolded();
}
/**
* Search action
*
* @param query
* @returns {Promise}
*/
function search(query)
{
var navigation = [],
flatNavigation = msNavigationService.getFlatNavigation(),
deferred = $q.defer();
// Iterate through the navigation array and
// make sure it doesn't have any groups or
// none ui-sref items
for ( var x = 0; x < flatNavigation.length; x++ )
{
if ( flatNavigation[x].uisref )
{
navigation.push(flatNavigation[x]);
}
}
// If there is a query, filter the navigation;
// otherwise we will return the entire navigation
// list. Not exactly a good thing to do but it's
// for demo purposes.
if ( query )
{
navigation = navigation.filter(function (item)
{
if ( angular.lowercase(item.title).search(angular.lowercase(query)) > -1 )
{
return true;
}
});
}
// Fake service delay
$timeout(function ()
{
deferred.resolve(navigation);
}, 1000);
return deferred.promise;
}
/**
* Search result click action
*
* @param item
*/
function searchResultClick(item)
{
// If item has a link
if ( item.uisref )
{
// If there are state params,
// use them...
if ( item.stateParams )
{
$state.go(item.state, item.stateParams);
}
else
{
$state.go(item.state);
}
}
}
}
})(); |