mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Adding option to name api-keys and removing them
This commit is contained in:
@@ -4,15 +4,43 @@ var connection_options = {
|
||||
'force new connection': true
|
||||
};
|
||||
var socket = io.connect(window.location.protocol + '//' + window.location.hostname + ':8080', connection_options);
|
||||
var api_token_list;
|
||||
|
||||
$(document).ready(function(){
|
||||
$('ul.tabs').tabs();
|
||||
api_token_list = $("#api_token_list").clone();
|
||||
$("#api_token_list").remove();
|
||||
loaded();
|
||||
});
|
||||
|
||||
$(document).on("click", "#refresh_all", function(e){
|
||||
e.preventDefault();
|
||||
$("#descriptions_cont").empty();
|
||||
$("#thumbnails_cont").empty();
|
||||
$("#api_token_name").remove();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/api_token",
|
||||
success: function(response) {
|
||||
if(response.length == 0) {
|
||||
if(!$(".header-api-fields").hasClass("hide")) {
|
||||
$(".header-api-fields").addClass("hide");
|
||||
}
|
||||
return;
|
||||
}
|
||||
$(".header-api-fields").removeClass("hide");
|
||||
for(var i = 0; i < response.length; i++) {
|
||||
var to_add = api_token_list;
|
||||
to_add.attr("id", response[i]._id);
|
||||
to_add.find(".api_token_name").text(response[i].name);
|
||||
to_add.find(".api_token_usage").text(response[i].usage);
|
||||
to_add.find("#delete_api_token").attr("data-id", response[i]._id);
|
||||
$(".channel_things").append(to_add);
|
||||
}
|
||||
},
|
||||
error: function(err) {
|
||||
}
|
||||
});
|
||||
if(!$(".channel_things").hasClass("hide")) {
|
||||
$(".channel_things").addClass("hide")
|
||||
}
|
||||
@@ -88,59 +116,120 @@ if(!$(".channel_things").hasClass("hide")) {
|
||||
}
|
||||
$(".preloader-wrapper").removeClass("hide");
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/lists",
|
||||
success: function(response){
|
||||
var output_pinned = '<option value="" disabled selected>Channels</option>';
|
||||
var output_delete = '<option value="" disabled selected>Channels</option>';
|
||||
for(var x = 0; x < response.length; x++){
|
||||
if(response[x].count > 5){
|
||||
output_pinned += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
$(document).on("click", "#delete_api_token", function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).attr("data-id");
|
||||
var that = this;
|
||||
$(that).toggleClass("disabled");
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: "api/api_token",
|
||||
data: {
|
||||
id: id
|
||||
},
|
||||
success: function(response) {
|
||||
if(response == "success") {
|
||||
Materialize.toast("Removed token!", 2000, "green lighten");
|
||||
$("#" + id).remove();
|
||||
} else {
|
||||
Materialize.toast("Something went wrong...", 2000, "red lighten");
|
||||
$(that).toggleClass("disabled");
|
||||
}
|
||||
output_delete += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
}
|
||||
|
||||
$("#frontpage_pinned").html(output_pinned);
|
||||
$("#remove_thumbnail").html(output_delete);
|
||||
$("#remove_description").html(output_delete);
|
||||
$("#delete_list_name").html(output_delete);
|
||||
$("#delete_userpass_name").html(output_delete);
|
||||
$("#delete_channel_name").html(output_delete);
|
||||
$("select").material_select();
|
||||
|
||||
if(!$(".preloader-wrapper").hasClass("hide")) {
|
||||
$(".preloader-wrapper").addClass("hide")
|
||||
}
|
||||
$(".channel_things").removeClass("hide");
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/names",
|
||||
success: function(response) {
|
||||
for(var i = 0; i < response.length; i++) {
|
||||
var icon = "";
|
||||
if(response[i].icon && response[i].icon != "") {
|
||||
icon = "<img class='chat-icon' src='" + response[i].icon + "' alt='" + response[i]._id + "'>";
|
||||
function loaded() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/api_token",
|
||||
success: function(response) {
|
||||
if(response.length == 0) {
|
||||
if(!$(".header-api-fields").hasClass("hide")) {
|
||||
$(".header-api-fields").addClass("hide");
|
||||
}
|
||||
return;
|
||||
}
|
||||
$(".names-container").append("<div class='col s12'><div class='name-chat col s3'>" + icon + response[i]._id + "</div><input type='text' class='" + response[i]._id + "_input col s7'><a class='btn green waves-effect col s2 m1 approve_name' href='#' data-name='" + response[i]._id + "'><i class='material-icons'>check</i></a></div>");
|
||||
$(".header-api-fields").removeClass("hide");
|
||||
for(var i = 0; i < response.length; i++) {
|
||||
var to_add = api_token_list.clone();
|
||||
to_add.attr("id", response[i]._id);
|
||||
to_add.find(".api_token_name").text(response[i].name);
|
||||
to_add.find(".api_token_usage").text(response[i].usage);
|
||||
to_add.find("#delete_api_token").attr("data-id", response[i]._id);
|
||||
$(".channel_things").append(to_add);
|
||||
}
|
||||
},
|
||||
error: function(err) {
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/thumbnails",
|
||||
success: function(response){
|
||||
if(response.length > 0){
|
||||
$(".thumbnails-badge").removeClass("hide");
|
||||
$(".thumbnails-badge").text(response.length);
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/lists",
|
||||
success: function(response){
|
||||
var output_pinned = '<option value="" disabled selected>Channels</option>';
|
||||
var output_delete = '<option value="" disabled selected>Channels</option>';
|
||||
for(var x = 0; x < response.length; x++){
|
||||
if(response[x].count > 5){
|
||||
output_pinned += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
}
|
||||
output_delete += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
}
|
||||
|
||||
$("#frontpage_pinned").html(output_pinned);
|
||||
$("#remove_thumbnail").html(output_delete);
|
||||
$("#remove_description").html(output_delete);
|
||||
$("#delete_list_name").html(output_delete);
|
||||
$("#delete_userpass_name").html(output_delete);
|
||||
$("#delete_channel_name").html(output_delete);
|
||||
$("select").material_select();
|
||||
|
||||
if(!$(".preloader-wrapper").hasClass("hide")) {
|
||||
$(".preloader-wrapper").addClass("hide")
|
||||
}
|
||||
$(".channel_things").removeClass("hide");
|
||||
}
|
||||
add_to_tab("thumbnails", response);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/names",
|
||||
success: function(response) {
|
||||
for(var i = 0; i < response.length; i++) {
|
||||
var icon = "";
|
||||
if(response[i].icon && response[i].icon != "") {
|
||||
icon = "<img class='chat-icon' src='" + response[i].icon + "' alt='" + response[i]._id + "'>";
|
||||
}
|
||||
$(".names-container").append("<div class='col s12'><div class='name-chat col s3'>" + icon + response[i]._id + "</div><input type='text' class='" + response[i]._id + "_input col s7'><a class='btn green waves-effect col s2 m1 approve_name' href='#' data-name='" + response[i]._id + "'><i class='material-icons'>check</i></a></div>");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/thumbnails",
|
||||
success: function(response){
|
||||
if(response.length > 0){
|
||||
$(".thumbnails-badge").removeClass("hide");
|
||||
$(".thumbnails-badge").text(response.length);
|
||||
}
|
||||
add_to_tab("thumbnails", response);
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/descriptions",
|
||||
success: function(response){
|
||||
if(response.length > 0){
|
||||
$(".descriptions-badge").removeClass("hide");
|
||||
$(".descriptions-badge").text(response.length);
|
||||
}
|
||||
add_to_tab("descriptions", response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on("click", ".approve_name", function(e) {
|
||||
var that = this;
|
||||
@@ -168,18 +257,6 @@ $(document).on("click", ".thumbnail_link", function(e) {
|
||||
window.open("https:" + this.value,'_blank');
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/descriptions",
|
||||
success: function(response){
|
||||
if(response.length > 0){
|
||||
$(".descriptions-badge").removeClass("hide");
|
||||
$(".descriptions-badge").text(response.length);
|
||||
}
|
||||
add_to_tab("descriptions", response);
|
||||
}
|
||||
});
|
||||
|
||||
function add_to_tab(dest, resp){
|
||||
for(var x = 0; x < resp.length; x++){
|
||||
if(dest == "thumbnails"){
|
||||
@@ -207,12 +284,30 @@ $(document).on("click", "#get_token", function(e){
|
||||
|
||||
$(document).on("click", "#get_api_token", function(e){
|
||||
e.preventDefault();
|
||||
var name = $("#new_api_token_name").val();
|
||||
if(name == "") {
|
||||
Materialize.toast("Empty name..!", 2000, "red lighten");
|
||||
return;
|
||||
}
|
||||
$("#new_api_token_name").val("");
|
||||
$("#get_api_token").toggleClass("disabled");
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
type: "POST",
|
||||
url: "/api/api_token",
|
||||
data: {
|
||||
name: name,
|
||||
},
|
||||
success: function(response){
|
||||
if(response != false){
|
||||
Materialize.toast("Gotten token", 2000, "green lighten");
|
||||
$("#new_api_token").val(response.token);
|
||||
$("#get_api_token").toggleClass("disabled");
|
||||
var to_add = api_token_list;
|
||||
to_add.attr("id", response._id);
|
||||
to_add.find(".api_token_name").text(name);
|
||||
to_add.find(".api_token_usage").text(0);
|
||||
to_add.find("#delete_api_token").attr("data-id", response._id);
|
||||
$(".channel_things").append(to_add);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user