Commit 7fed2788 authored by CupCakeArmy's avatar CupCakeArmy
Browse files

New Modal Button System

parent 80ec2355
......@@ -50,8 +50,16 @@ The JS library ```tools``` is the backbone of the single tools. It enables the t
* ```data /js object``` Object containning the infos
* ```head /text, HTML (optional)``` Sets the modal title.
* ```body /text, HTML (optional)``` Sets the modal body.
* ```button /text, HTML (optional)``` Confirm button text.
* ```success /function (optional)``` Function called on confirm button press.
* ```button /object (optional)``` Buttons in the footer. (Multiple allowed!! :D)
* ```type /string (optional)``` Type of boostrap button
* primary
* success
* info
* warning
* danger
* link
* ```close /bool (optional)``` Close modal on click
* ```callback /function (optional)``` Callback for the button
* ```cancel /function (optional)``` Function called on cancel or modal is closed.
##### Example:
......@@ -62,10 +70,15 @@ tools.modal();
tools.modal({
head: 'Download Flash Player!!',
body: 'Your browser needs this super important plugin',
button: 'DOWNLOAD!',
success: function(){
some.nasty.virus();
},
button: {
'DOWNLOAD!':{
type: 'success',
close: true,
callback: function(){
some.nasty.virusdownload.now();
}
},
},
cancel: function(){
console.log('No Virus for you -.-');
}
......
......@@ -41,13 +41,14 @@ var tools = {
$('.modalCont .modal-footer').html('<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>');
var modalBtnId = 0;
for (var curBtn in attr.button) {
if (attr.button[curBtn].type === undefined && attr.button[curBtn].type != '')
if (attr.button[curBtn].type === undefined || attr.button[curBtn].type == '')
attr.button[curBtn].type = 'primary';
$('.modalCont .modal-footer').append('<button type="button" class="btn btn-primary modal-btn-' + modalBtnId + '">' + curBtn + '</button>');
$('.modalCont .modal-footer').append('<button type="button" class="btn btn-' + attr.button[curBtn].type + ' modal-btn-' + modalBtnId + '">' + curBtn + '</button>');
if (attr.button[curBtn].callback !== undefined && typeof(attr.button[curBtn].callback) == 'function')
$('.modal-btn-' + modalBtnId).off('click').on('click', attr.button[curBtn].callback);
if (attr.button[curBtn].close === true)
$('.modal-btn-' + modalBtnId).on('click', tools.modalClose);
modalBtnId++;
}
$('.modalCont').modal('show');
},
......
......@@ -89,8 +89,13 @@
tools.modal({
head: ret.firstname + ' ' + ret.lastname,
body: tmp,
button: 'OK',
success: users.inspectUser
button: {
'Update': {
type: 'success',
close: true,
callback: users.inspectUser,
}
}
});
});;
......@@ -134,22 +139,29 @@
tools.modal({
head: 'New User',
body: tmp,
button: 'Add',
success: function() {
var newUserData = {};
$('.users-user-add-table tr').each(function() {
newUserData[$(this).children('td:nth-child(1)').html()] = $(this).children('td:nth-child(2)').html();
});
amivcore.users.POST({
data: newUserData
}, function(ret) {
if (!ret.hasOwnProperty('_status') || ret['_status'] != 'OK')
tools.log(JSON.stringify(ret.responseJSON['_issues']), 'e');
console.log(ret);
users.get();
});
button: {
'Add': {
type: 'success',
close: true,
callback: function() {
var newUserData = {};
$('.users-user-add-table tr').each(function() {
newUserData[$(this).children('td:nth-child(1)').html()] = $(this).children('td:nth-child(2)').html();
});
amivcore.users.POST({
data: newUserData
}, function(ret) {
if (!ret.hasOwnProperty('_status') || ret['_status'] != 'OK')
tools.log(JSON.stringify(ret.responseJSON['_issues']), 'e');
else {
tools.log('User Added', 's');
users.get();
}
});
}
}
}
})
});
}
};
......@@ -168,17 +180,14 @@
body: '<div class="form-group"><input type="number" value="' + users.page.cur() + '" class="form-control users-go-page"></div>',
button: {
'Go': {
type: 'primary',
type: 'success',
close: true,
callback: function() {
users.page.set($('.users-go-page').val());
},
},
},
success: function() {
users.page.set($('.users-go-page').val());
}
}
})
});
}
},
'<span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span>': {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment