diff --git a/README.md b/README.md index 617eea8a822510d84547ffcb0282dc0e81d0c2a4..7125ce9bf83fa5f325c5e8e5764ba81606762a84 100644 --- a/README.md +++ b/README.md @@ -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 -.-'); } diff --git a/admin/lib/cust/main.js b/admin/lib/cust/main.js index ee2fb093c5fa8380809a9ece3ddf9acb62151698..5a7c71f76293fa594ca314596c8be5c8a1f9786a 100644 --- a/admin/lib/cust/main.js +++ b/admin/lib/cust/main.js @@ -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'); }, diff --git a/admin/tools/users.tool b/admin/tools/users.tool index 12196736f66f998e250436c8399f0be0478a2958..feb9ff5774db96e56fcbf4dae13abec5095941c0 100644 --- a/admin/tools/users.tool +++ b/admin/tools/users.tool @@ -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>': {