Skip to content

Instantly share code, notes, and snippets.

@des1roer des1roer/admin.js
Created Jun 3, 2017

Embed
What would you like to do?
c = function () {
return console.log.apply(console, arguments);
};
Object.size = function (obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key))
size++;
}
return size;
};
Vue.component('modal', {
template: '#modal-template'
})
var vm = new Vue({
el: '.wrapper',
data: {
cols: {},
id: window.location.href.split('#')[1] || 0,
loader: true,
showModal: false,
add_row: {},
rows: {},
},
mounted: function () {
// next(self.videos, self.id)
},
methods: {
refresh: function () {
var self = this;
$.ajax({
url: "php/data.php",
type: 'POST',
data: {act: 'load', user: self.user_id},
success: function (data) {
c(data)
var data = $.parseJSON(data);
c(data)
self.loader = false;
self.cols = data;
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
},
pass: function (data) {
handleAuthClick();
},
add: function (data) {
var self = this;
if (typeof self.add_row.name == 'undefined' || self.add_row.name.trim() == '')
return false;
self.loader = true;
$.ajax({
url: "php/data.php",
type: 'POST',
data: {act: 'add', data: self.add_row, user: self.user_id},
success: function (data) {
var data = JSON.parse(data);
if (typeof data.error == 'undefined') {
self.add_row = {};
vm.refresh();
} else {
alert(data.error.errorInfo);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
},
edit: function (data) {
console.log(data)
this.loader = true;
$.ajax({
url: "php/data.php",
type: 'POST',
data: {act: 'edit', data: data},
success: function (data) {
var data = JSON.parse(data);
if (typeof data.error == 'undefined') {
vm.refresh();
} else {
alert(data.error.errorInfo);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
},
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.