@@ -712,7 +712,60 @@ var AppRouter = Backbone.Router.extend({
712
712
_subMenuForAllTypes : [ ] ,
713
713
_subMenuForCodes : { } ,
714
714
_subMenus : { } ,
715
- _internalMenuCategories : [ "understand" , "explore" , "reach" , "improve" , "utilities" , "management" , "user" ] ,
715
+ _internalMenuCategories : [ "management" , "user" ] ,
716
+ /**
717
+ * Add menu category. Categories will be copied for all app types and its visibility should be controled from the app type plugin
718
+ * @param {string } category - new menu category
719
+ * @param {Object } node - object defining category lement
720
+ * @param {string } node.text - key for localization string which to use as text
721
+ * @param {number } node.priority - priority order number, the less it is, the more on top category will be
722
+ * @param {string } node.classes - string with css classes to add to category element
723
+ * @param {string } node.style - string with css styling to add to category element
724
+ * @param {string } node.html - additional HTML to append after text
725
+ * @param {function } node.callback - called when and each time category is added passing same parameters as to this method plus added jquery category element as 3th param
726
+ **/
727
+ addMenuCategory : function ( category , node ) {
728
+ if ( this . _internalMenuCategories . indexOf ( category ) !== - 1 ) {
729
+ throw "Category already exists with name: " + category ;
730
+ }
731
+ if ( typeof node . priority === "undefined" ) {
732
+ throw "Provide priority property for category element" ;
733
+ }
734
+ var menu = $ ( "<div></div>" ) ;
735
+ menu . addClass ( "menu-category" ) ;
736
+ menu . addClass ( category + "-category" ) ;
737
+ menu . attr ( "data-priority" , node . priority ) ;
738
+ if ( node . classes ) {
739
+ menu . addClass ( node . classes ) ;
740
+ }
741
+ if ( node . style ) {
742
+ menu . attr ( "style" , node . style ) ;
743
+ }
744
+ menu . append ( '<span class="menu-category-title" data-localize="' + ( node . text || "sidebar.category." + category ) + '"></span>' ) ;
745
+ if ( node . html ) {
746
+ menu . append ( node . html ) ;
747
+ }
748
+ this . _internalMenuCategories . push ( category ) ;
749
+ var added = false ;
750
+ var selector = "#sidebar-menu .sidebar-menu" ;
751
+ //try adding before first greater priority
752
+ $ ( selector + " > div.menu-category" ) . each ( function ( ) {
753
+ var cur = parseInt ( $ ( this ) . attr ( "data-priority" ) ) ;
754
+ if ( node . priority < cur ) {
755
+ added = true ;
756
+ $ ( this ) . before ( menu ) ;
757
+ return false ;
758
+ }
759
+ } ) ;
760
+
761
+ //if not added, maybe we are first or last, so just add it
762
+ if ( ! added ) {
763
+ $ ( selector ) . append ( menu ) ;
764
+ }
765
+ if ( typeof node . callback === "function" ) {
766
+ node . callback ( category , node , menu ) ;
767
+ }
768
+ } ,
716
769
/**
717
770
* Add first level menu element for specific app type under specified category. You can only add app type specific menu to categories "understand", "explore", "reach", "improve", "utilities"
718
771
* @param {string } app_type - type of the app for which to add menu
@@ -1233,44 +1286,50 @@ var AppRouter = Backbone.Router.extend({
1233
1286
this . refreshScripts = { } ;
1234
1287
this . appSettings = { } ;
1235
1288
this . widgetCallbacks = { } ;
1236
-
1237
- /**
1238
- * Add menus
1239
- **/
1240
-
1241
- this . addMenu ( "understand" , { code : "overview" , url : "#/" , text : "sidebar.dashboard" , icon : '<div class="logo dashboard ion-speedometer"></div>' , priority : 10 } ) ;
1242
- this . addMenu ( "understand" , { code : "analytics" , text : "sidebar.analytics" , icon : '<div class="logo analytics ion-ios-pulse-strong"></div>' , priority : 20 } ) ;
1243
- this . addMenu ( "understand" , { code : "engagement" , text : "sidebar.engagement" , icon : '<div class="logo ion-happy-outline"></div>' , priority : 30 } ) ;
1244
- this . addMenu ( "understand" , { code : "events" , text : "sidebar.events" , icon : '<div class="logo events"><i class="material-icons">bubble_chart</i></div>' , priority : 40 } ) ;
1245
- this . addSubMenu ( "events" , { code : "events-overview" , url : "#/analytics/events/overview" , text : "sidebar.events.overview" , priority : 10 } ) ;
1246
- this . addSubMenu ( "events" , { code : "all-events" , url : "#/analytics/events" , text : "sidebar.events.all-events" , priority : 20 } ) ;
1247
- if ( countlyGlobal . member . global_admin ) {
1248
- this . addSubMenu ( "events" , { code : "all-events" , url : "#/analytics/events/blueprint" , text : "sidebar.events.blueprint" , priority : 100 } ) ;
1249
- }
1250
- this . addMenu ( "utilities" , {
1251
- code : "management" ,
1252
- text : "sidebar.utilities" ,
1253
- icon : '<div class="logo management ion-wrench"></div>' ,
1254
- priority : 10000000 ,
1255
- callback : function ( type , category , node , menu ) {
1256
- //for backwards compatability of old plugins adding menu to management
1257
- menu . filter ( "#management-submenu" ) . append ( "<span class='help-toggle'></span>" ) ;
1289
+ var self = this ;
1290
+ $ ( document ) . ready ( function ( ) {
1291
+ /**
1292
+ * Add menus
1293
+ **/
1294
+ self . addMenuCategory ( "understand" , { priority : 1 } ) ;
1295
+ self . addMenuCategory ( "explore" , { priority : 2 } ) ;
1296
+ self . addMenuCategory ( "reach" , { priority : 3 } ) ;
1297
+ self . addMenuCategory ( "improve" , { priority : 4 } ) ;
1298
+ self . addMenuCategory ( "utilities" , { priority : 5 } ) ;
1299
+ self . addMenu ( "understand" , { code : "overview" , url : "#/" , text : "sidebar.dashboard" , icon : '<div class="logo dashboard ion-speedometer"></div>' , priority : 10 } ) ;
1300
+ self . addMenu ( "understand" , { code : "analytics" , text : "sidebar.analytics" , icon : '<div class="logo analytics ion-ios-pulse-strong"></div>' , priority : 20 } ) ;
1301
+ self . addMenu ( "understand" , { code : "engagement" , text : "sidebar.engagement" , icon : '<div class="logo ion-happy-outline"></div>' , priority : 30 } ) ;
1302
+ self . addMenu ( "understand" , { code : "events" , text : "sidebar.events" , icon : '<div class="logo events"><i class="material-icons">bubble_chart</i></div>' , priority : 40 } ) ;
1303
+ self . addSubMenu ( "events" , { code : "events-overview" , url : "#/analytics/events/overview" , text : "sidebar.events.overview" , priority : 10 } ) ;
1304
+ self . addSubMenu ( "events" , { code : "all-events" , url : "#/analytics/events" , text : "sidebar.events.all-events" , priority : 20 } ) ;
1305
+ if ( countlyGlobal . member . global_admin ) {
1306
+ self . addSubMenu ( "events" , { code : "all-events" , url : "#/analytics/events/blueprint" , text : "sidebar.events.blueprint" , priority : 100 } ) ;
1258
1307
}
1259
- } ) ;
1308
+ self . addMenu ( "utilities" , {
1309
+ code : "management" ,
1310
+ text : "sidebar.utilities" ,
1311
+ icon : '<div class="logo management ion-wrench"></div>' ,
1312
+ priority : 10000000 ,
1313
+ callback : function ( type , category , node , menu ) {
1314
+ //for backwards compatability of old plugins adding menu to management
1315
+ menu . filter ( "#management-submenu" ) . append ( "<span class='help-toggle'></span>" ) ;
1316
+ }
1317
+ } ) ;
1260
1318
1261
- this . addSubMenu ( "management" , { code : "longtasks" , url : "#/manage/tasks" , text : "sidebar.management.longtasks" , priority : 10 } ) ;
1319
+ self . addSubMenu ( "management" , { code : "longtasks" , url : "#/manage/tasks" , text : "sidebar.management.longtasks" , priority : 10 } ) ;
1262
1320
1263
- if ( countlyGlobal . member . global_admin || ( countlyGlobal . admin_apps && Object . keys ( countlyGlobal . admin_apps ) . length ) ) {
1264
- this . addMenu ( "management" , { code : "applications" , url : "#/manage/apps" , text : "sidebar.management.applications" , icon : '<div class="logo-icon ion-ios-albums"></div>' , priority : 10 } ) ;
1265
- }
1266
- if ( countlyGlobal . member . global_admin ) {
1267
- this . addMenu ( "management" , { code : "users" , url : "#/manage/users" , text : "sidebar.management.users" , icon : '<div class="logo-icon fa fa-user-friends"></div>' , priority : 20 } ) ;
1268
- }
1321
+ if ( countlyGlobal . member . global_admin || ( countlyGlobal . admin_apps && Object . keys ( countlyGlobal . admin_apps ) . length ) ) {
1322
+ self . addMenu ( "management" , { code : "applications" , url : "#/manage/apps" , text : "sidebar.management.applications" , icon : '<div class="logo-icon ion-ios-albums"></div>' , priority : 10 } ) ;
1323
+ }
1324
+ if ( countlyGlobal . member . global_admin ) {
1325
+ self . addMenu ( "management" , { code : "users" , url : "#/manage/users" , text : "sidebar.management.users" , icon : '<div class="logo-icon fa fa-user-friends"></div>' , priority : 20 } ) ;
1326
+ }
1269
1327
1270
- this . addMenu ( "management" , { code : "help" , text : "sidebar.management.help" , icon : '<div class="logo-icon ion-help help"></div>' , classes : "help-toggle" , html : '<div class="on-off-switch" id="help-toggle"><input type="checkbox" class="on-off-switch-checkbox" id="help-toggle-cbox"><label class="on-off-switch-label" for="help-toggle-cbox"></label></div>' , priority : 10000000 } ) ;
1328
+ self . addMenu ( "management" , { code : "help" , text : "sidebar.management.help" , icon : '<div class="logo-icon ion-help help"></div>' , classes : "help-toggle" , html : '<div class="on-off-switch" id="help-toggle"><input type="checkbox" class="on-off-switch-checkbox" id="help-toggle-cbox"><label class="on-off-switch-label" for="help-toggle-cbox"></label></div>' , priority : 10000000 } ) ;
1271
1329
1272
- this . addMenu ( "explore" , { code : "users" , text : "sidebar.analytics.users" , icon : '<div class="logo ion-person-stalker"></div>' , priority : 10 } ) ;
1273
- this . addMenu ( "explore" , { code : "behavior" , text : "sidebar.behavior" , icon : '<div class="logo ion-funnel"></div>' , priority : 20 } ) ;
1330
+ self . addMenu ( "explore" , { code : "users" , text : "sidebar.analytics.users" , icon : '<div class="logo ion-person-stalker"></div>' , priority : 10 } ) ;
1331
+ self . addMenu ( "explore" , { code : "behavior" , text : "sidebar.behavior" , icon : '<div class="logo ion-funnel"></div>' , priority : 20 } ) ;
1332
+ } ) ;
1274
1333
1275
1334
this . routesHit = 0 ; //keep count of number of routes handled by your application
1276
1335
/**
@@ -1588,7 +1647,6 @@ var AppRouter = Backbone.Router.extend({
1588
1647
return options . fn ( object [ options . hash . key ] ) ;
1589
1648
} ) ;
1590
1649
1591
- var self = this ;
1592
1650
$ ( "body" ) . addClass ( "lang-" + countlyCommon . BROWSER_LANG_SHORT ) ;
1593
1651
jQuery . i18n . properties ( {
1594
1652
name : 'locale' ,
0 commit comments