From 62130fc3d8682c81c5405fe4a9f87b2a0f638a6f Mon Sep 17 00:00:00 2001
From: CupCakeArmy <nicco.borgioli@gmail.com>
Date: Fri, 22 Apr 2016 12:00:23 +0200
Subject: [PATCH] Added Custom Menu Feature

---
 admin/lib/cust/main.js | 244 ++++++++++++++++++++++-------------------
 1 file changed, 129 insertions(+), 115 deletions(-)

diff --git a/admin/lib/cust/main.js b/admin/lib/cust/main.js
index c5cd496..47400de 100644
--- a/admin/lib/cust/main.js
+++ b/admin/lib/cust/main.js
@@ -2,98 +2,115 @@
 
 // Library for all tool actions
 var tools = {
-	
-	//Log Function & Utility Vars
-	alertNum: 0,
-	alertType: {
-		's': 'alert-success',
-		'i': 'alert-info',
-		'w': 'alert-warning',
-		'e': 'alert-danger'
-	},
-	log: function(msg, type, timeout){
-		timeout = timeout || 5000;
-		tools.alertNum++;
-		$('.alertCont').append('<div id="alertBox'+tools.alertNum+'" class="alert '+tools.alertType[type]+' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+msg+'</div>');
-		setTimeout(function(){
-			$('#alertBox'+tools.alertNum).alert('close');
-		}, timeout);
-		console.log(msg);
-	},
-	
-	// Ajax loading gunction and getting the tools
-	curTool: '',
-	getTool: function(tool) {
-		//Setting home if no other tool is selected
-		if(window.location.hash == '' || window.location.hash == null)
-			window.location.hash = 'home';
-		// If tool is specfied, get it
-		var nextTool = (tool && typeof tool != 'object')? tool : window.location.hash.slice(1);
-		if(tools.curTool == nextTool)
-			return;
-		tools.curTool = nextTool;
-		window.location.hash = tools.curTool;
-		$('#wheel-logo').css('transform', 'rotate(360deg)');
-	  $('#main-content').fadeOut(100,function() {
-		  $.ajax({
-		    url: 'tools/' + tools.curTool + '.tool',
-		    dataType: 'html',
-		    error: function() {
-		      tools.log('Tool not found', 'e');
-		    }
-		  }).done(function(data){
-		    $('#main-content').html(data);
-		    tools.ui.resizeTool();
-	      $('#main-content').fadeIn(250,function() {
-	        $('#wheel-logo').css('transform', 'rotate(0deg)');
-	      });
-		  });
-	  });
-	},
-	
-	// UI Stuff
-	ui: {
-		//Toggle the sidemenu
-		toggleSideMenu: function(){
-			$('.wrapper-main').toggleClass('toggled');
-		},
-		login: function(){
-			$('.loginPanel').css({'top':'-100%'});
-		},
-		logout: function(){
-			$('.loginPanel').css({'top':'0%'});
-		},
-		resizeTool: function(){
-			console.log('Resizing');
-			$('tools-full-height').height( $(window).height() - $('.navbar-main').height() );
-		}
-	},
-	
-	// Memory to store stuff
-	memStore: function(type, name, val){
-		window[type].setItem(name, val);
-	},
-	memGet: function(type, name){
-		return window[type].getItem(name);
-	},
-	mem: {
-		local: {
-			set: function(name, val){
-				tools.memStore('localStorage', tools.curTool+name, val);
-			},
-			get: function(name){
-				return tools.memGet('localStorage', tools.curTool+name);
-			},
-		},
-		session: {
-			set: function(name, val){
-				tools.memStore('sessionStorage', tools.curTool+name, val);
-			},
-			get: function(name){
-				return tools.memGet('sessionStorage', tools.curTool+name);
-			},
-		}
-	}
+
+    //Log Function & Utility Vars
+    alertNum: 0,
+    alertType: {
+        's': 'alert-success',
+        'i': 'alert-info',
+        'w': 'alert-warning',
+        'e': 'alert-danger'
+    },
+    log: function(msg, type, timeout) {
+        timeout = timeout || 5000;
+        tools.alertNum++;
+        $('.alertCont').append('<div id="alertBox' + tools.alertNum + '" class="alert ' + tools.alertType[type] + ' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' + msg + '</div>');
+        setTimeout(function() {
+            $('#alertBox' + tools.alertNum).alert('close');
+        }, timeout);
+        console.log(msg);
+    },
+
+    // Ajax loading gunction and getting the tools
+    curTool: '',
+    getTool: function(tool) {
+        //Setting home if no other tool is selected
+        if (window.location.hash == '' || window.location.hash == null)
+            window.location.hash = 'home';
+        // If tool is specfied, get it
+        var nextTool = (tool && typeof tool != 'object') ? tool : window.location.hash.slice(1);
+        if (tools.curTool == nextTool)
+            return;
+        tools.curTool = nextTool;
+        window.location.hash = tools.curTool;
+        $('#wheel-logo').css('transform', 'rotate(360deg)');
+        $('#main-content').fadeOut(100, function() {
+            $.ajax({
+                url: 'tools/' + tools.curTool + '.tool',
+                dataType: 'html',
+                error: function() {
+                    tools.log('Tool not found', 'e');
+                }
+            }).done(function(data) {
+                $('#main-content').html(data);
+                tools.ui.resizeTool();
+                $('#main-content').fadeIn(250, function() {
+                    $('#wheel-logo').css('transform', 'rotate(0deg)');
+                });
+            });
+        });
+    },
+
+    // UI Stuff
+    ui: {
+        //Toggle the sidemenu
+        toggleSideMenu: function() {
+            $('.wrapper-main').toggleClass('toggled');
+        },
+        login: function() {
+            $('.loginPanel').css({
+                'top': '-100%'
+            });
+        },
+        logout: function() {
+            $('.loginPanel').css({
+                'top': '0%'
+            });
+        },
+        resizeTool: function() {
+            $('tools-full-height').height($(window).height() - $('.navbar-main').height());
+        },
+        menuId: 0,
+        menu: function(attr) {
+            var custMenu = $('.cust-menu');
+            custMenu.html('');
+            tools.ui.menuId++;
+            for (var cur in attr) {
+                if (attr[cur].link == '' || attr[cur].link === undefined)
+                    attr[cur].link = 'javascript:void(0);';
+                custMenu.append('<li><a href="' + attr[cur].link + '" id="cust-menu-link-' + tools.ui.menuId + '">' + cur + '</a></li>');
+                if (typeof(attr[cur].callback) == 'function')
+                    $('#cust-menu-link-' + tools.ui.menuId).click(attr[cur].callback);
+            }
+
+        }
+    },
+
+    // Memory to store stuff
+    memStore: function(type, name, val) {
+        window[type].setItem(name, val);
+    },
+    memGet: function(type, name) {
+        return window[type].getItem(name);
+    },
+    mem: {
+        local: {
+            set: function(name, val) {
+                tools.memStore('localStorage', tools.curTool + name, val);
+            },
+            get: function(name) {
+                return tools.memGet('localStorage', tools.curTool + name);
+            },
+        },
+        session: {
+            set: function(name, val) {
+                tools.memStore('sessionStorage', tools.curTool + name, val);
+            },
+            get: function(name) {
+                return tools.memGet('sessionStorage', tools.curTool + name);
+            },
+        }
+    }
 }
 
 /*
@@ -103,36 +120,33 @@ var tools = {
 //Binding tool change whenever the hash is changed
 window.onhashchange = tools.getTool;
 
-
 // Login function
-function loginFunc(){
-	$('.loginPanel input').attr('readonly', 1);
-	amivcore.login($('#loginUsername').val(),$('#loginPassword').val(), function(ret){
-		if(ret !== true)
-			tools.log('Wrong Credentials', 'w');
-		$('.loginPanel input').removeAttr('readonly');
-	});
+function loginFunc() {
+    $('.loginPanel input').attr('readonly', 1);
+    amivcore.login($('#loginUsername').val(), $('#loginPassword').val(), function(ret) {
+        if (ret !== true)
+            tools.log('Wrong Credentials', 'w');
+        $('.loginPanel input').removeAttr('readonly');
+    });
 }
-			
+
 // Binding the buttons
 $('.toggleSidebarBtn').click(tools.ui.toggleSideMenu);
 $('.loginAction').click(loginFunc);
 $('.logoutAction').click(amivcore.logout);
-$('.loginPanel').keypress(function(e){
-	if(e.which == 13){
-		e.preventDefault();
-		loginFunc();
-	}
+$('.loginPanel').keypress(function(e) {
+    if (e.which == 13) {
+        e.preventDefault();
+        loginFunc();
+    }
 })
 
-window.onresize = tools.ui.resizeTools;
-
-amivcore.on('ready', function(){
-	tools.getTool();
+amivcore.on('ready', function() {
+    tools.getTool();
+});
+amivcore.on('login', function() {
+    tools.ui.login();
 });
-amivcore.on('login', function(){
-	tools.ui.login();	
+amivcore.on('logout', function() {
+    tools.ui.logout();
 });
-amivcore.on('logout', function(){
-	tools.ui.logout();	
-});
\ No newline at end of file
-- 
GitLab