Base
This commit is contained in:
81
public/js/admin.js
Normal file
81
public/js/admin.js
Normal file
@ -0,0 +1,81 @@
|
||||
$(document).ready(function() {
|
||||
$('#databases').submit(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var db = $("[name='database']").val();
|
||||
var models = [];
|
||||
var namespaces = [];
|
||||
$.post('?p=admin&action=listModels', {"database": db}).done(function(data) {
|
||||
//console.debug(data);
|
||||
var info = $.parseJSON(data);
|
||||
//console.debug(info.models);
|
||||
|
||||
models = info.models;
|
||||
//console.debug(models);
|
||||
|
||||
$.post('?p=admin&action=listNamespaces').done(function(data) {
|
||||
//console.debug(data);
|
||||
info = $.parseJSON(data);
|
||||
//console.debug(info.models);
|
||||
|
||||
namespaces = info.namespaces;
|
||||
//console.debug(namespaces);
|
||||
|
||||
$.each(models, function(i, elem) {
|
||||
var div = $('<div></div>').attr('class', 'row');
|
||||
div.append($('<div></div>').attr('class', 'col-md-2').html(elem.model));
|
||||
var div2 = $('<div></div>').attr('class', 'row');
|
||||
$.each(namespaces, function(j, ns) {
|
||||
div2.append($('<div></div>').attr('class', 'col-md-3').append($('<span></span>').attr('class', 'ns').attr('data-table', elem.table).attr('data-ns', ns).html(ns)));
|
||||
});
|
||||
div.append($('<div></div>').attr('class', 'col-md-9').append(div2));
|
||||
div.append($('<div></div>').attr('class', 'col-md-1 remove').append($('<span></span>').attr('class', 'glyphicon glyphicon-remove')));
|
||||
$('#results').append(div);
|
||||
});
|
||||
|
||||
$('.ns').css('cursor', 'pointer');
|
||||
$('.remove').css('cursor', 'pointer');
|
||||
|
||||
$('.ns').mouseover(function(e) {
|
||||
$(this).parent().addClass('bg-success');
|
||||
$(this).parent().parent().parent().parent().addClass('bg-warning');
|
||||
}).mouseout(function(e) {
|
||||
$(this).parent().removeClass('bg-success');
|
||||
$(this).parent().parent().parent().parent().removeClass('bg-warning');
|
||||
});
|
||||
|
||||
$('.remove').mouseover(function(e) {
|
||||
$(this).parent().addClass('bg-danger');
|
||||
}).mouseout(function(e) {
|
||||
$(this).parent().removeClass('bg-danger');
|
||||
});
|
||||
|
||||
$('.ns').click(function(e) {
|
||||
var table = $(this).attr('data-table');
|
||||
var ns = $(this).attr('data-ns');
|
||||
execute(table, ns);
|
||||
});
|
||||
$('.remove').click(function(e) {
|
||||
$(this).parent().remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
function execute(table, ns) {
|
||||
console.debug(table, ns);
|
||||
var db = $("[name='database']").val();
|
||||
$.post('?p=admin&action=createModel', {"table": table, "namespace": ns, "database": db}).done(function(data) {
|
||||
console.debug(data);
|
||||
var info = $.parseJSON(data);
|
||||
console.debug(info);
|
||||
if (info.result) {
|
||||
$(".ns[data-table='" + table + "']").parent().parent().parent().parent().remove();
|
||||
} else {
|
||||
alert('Error');
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user