Commit 8a6437df authored by Ad Schellevis's avatar Ad Schellevis

(trafficshaper) cleanup JS code

parent 9b338529
...@@ -30,319 +30,41 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -30,319 +30,41 @@ POSSIBILITY OF SUCH DAMAGE.
display:none; display:none;
} }
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
$( document ).ready(function() { $( document ).ready(function() {
/************************************************************************************************************* /*************************************************************************************************************
* manage bandwidth pipes * link grid actions
*************************************************************************************************************/ *************************************************************************************************************/
/** $("#grid-pipes").UIBootgrid(
* Render pipe grid using searchPipes api { 'search':'/api/trafficshaper/settings/searchPipes',
*/ 'get':'/api/trafficshaper/settings/getPipe/',
var gridPipes = stdBootgridUI("grid-pipes", "/api/trafficshaper/settings/searchPipes"); 'set':'/api/trafficshaper/settings/setPipe/',
'add':'/api/trafficshaper/settings/addPipe/',
/** 'del':'/api/trafficshaper/settings/delPipe/'
* Link pipe grid command controls (edit/delete)
*/
gridPipes.on("loaded.rs.jquery.bootgrid", function(){
// edit item
gridPipes.find(".command-edit").on("click", function(e)
{
var uuid=$(this).data("row-id");
mapDataToFormUI({'frm_DialogPipe':"/api/trafficshaper/settings/getPipe/"+uuid}).done(function(){
// update selectors
$('.selectpicker').selectpicker('refresh');
// clear validation errors (if any)
clearFormValidation('frm_DialogPipe');
});
// show dialog for pipe edit
$('#DialogPipe').modal({backdrop: 'static', keyboard: false});
// curry uuid to save action
$("#btn_DialogPipe_save").unbind('click').click(savePipe.bind(undefined, uuid));
}).end();
// delete item
gridPipes.find(".command-delete").on("click", function(e)
{
var uuid=$(this).data("row-id");
stdDialogRemoveItem('Remove selected item?',function() {
ajaxCall(url="/api/trafficshaper/settings/delPipe/" + uuid,
sendData={},callback=function(data,status){
// reload grid after delete
$("#grid-pipes").bootgrid("reload");
});
});
}).end();
});
/**
* save form data to end point for existing pipe
*/
function savePipe(uuid) {
saveFormToEndpoint(url="/api/trafficshaper/settings/setPipe/"+uuid,
formid="frm_DialogPipe", callback_ok=function(){
$("#DialogPipe").modal('hide');
$("#grid-pipes").bootgrid("reload");
}, true);
} }
);
/**
* save form data to end point for new pipe $("#grid-queues").UIBootgrid(
*/ { 'search':'/api/trafficshaper/settings/searchQueues',
function addPipe() { 'get':'/api/trafficshaper/settings/getQueue/',
saveFormToEndpoint(url="/api/trafficshaper/settings/addPipe/", 'set':'/api/trafficshaper/settings/setQueue/',
formid="frm_DialogPipe", callback_ok=function(){ 'add':'/api/trafficshaper/settings/addQueue/',
$("#DialogPipe").modal('hide'); 'del':'/api/trafficshaper/settings/delQueue/'
$("#grid-pipes").bootgrid("reload");
}, true);
} }
);
/**
* Delete list of uuids on click event $("#grid-rules").UIBootgrid(
*/ { 'search':'/api/trafficshaper/settings/searchRules',
$("#deletePipes").click(function(){ 'get':'/api/trafficshaper/settings/getRule/',
stdDialogRemoveItem("Remove selected items?",function(){ 'set':'/api/trafficshaper/settings/setRule/',
var rows =$("#grid-pipes").bootgrid('getSelectedRows'); 'add':'/api/trafficshaper/settings/addRule/',
if (rows != undefined){ 'del':'/api/trafficshaper/settings/delRule/'
var deferreds = [];
$.each(rows, function(key,uuid){
deferreds.push(ajaxCall(url="/api/trafficshaper/settings/delPipe/" + uuid, sendData={},null));
});
// refresh after load
$.when.apply(null, deferreds).done(function(){
$("#grid-pipes").bootgrid("reload");
});
} }
}); );
});
/**
* Add new pipe on click event
*/
$("#addPipe").click(function(){
mapDataToFormUI({'frm_DialogPipe':"/api/trafficshaper/settings/getPipe/"}).done(function(){
// update selectors
$('.selectpicker').selectpicker('refresh');
// clear validation errors (if any)
clearFormValidation('frm_DialogPipe');
});
// show dialog for pipe edit
$('#DialogPipe').modal({backdrop: 'static', keyboard: false});
// curry uuid to save action
$("#btn_DialogPipe_save").unbind('click').click(addPipe);
});
/*************************************************************************************************************
* manage Queues
*************************************************************************************************************/
/**
* Render queue grid using searchQueues api
*/
var gridQueues = stdBootgridUI("grid-queues", "/api/trafficshaper/settings/searchQueues");
/**
* Link queue grid command controls (edit/delete)
*/
gridQueues.on("loaded.rs.jquery.bootgrid", function(){
// edit item
gridQueues.find(".command-edit").on("click", function(e)
{
var uuid=$(this).data("row-id");
mapDataToFormUI({'frm_DialogQueue':"/api/trafficshaper/settings/getQueue/"+uuid}).done(function(){
// update selectors
$('.selectpicker').selectpicker('refresh');
// clear validation errors (if any)
clearFormValidation('frm_DialogQueue');
});
// show dialog for queue edit
$('#DialogQueue').modal({backdrop: 'static', keyboard: false});
// curry uuid to save action
$("#btn_DialogQueue_save").unbind('click').click(saveQueue.bind(undefined, uuid));
}).end();
// delete item
gridQueues.find(".command-delete").on("click", function(e)
{
var uuid=$(this).data("row-id");
stdDialogRemoveItem('Remove selected item?',function() {
ajaxCall(url="/api/trafficshaper/settings/delQueue/" + uuid,
sendData={},callback=function(data,status){
// reload grid after delete
$("#grid-queues").bootgrid("reload");
});
});
}).end();
});
/**
* save form data to end point for existing queue
*/
function saveQueue(uuid) {
saveFormToEndpoint(url="/api/trafficshaper/settings/setQueue/"+uuid,
formid="frm_DialogQueue", callback_ok=function(){
$("#DialogQueue").modal('hide');
$("#grid-queues").bootgrid("reload");
}, true);
}
/**
* save form data to end point for new queue
*/
function addQueue() {
saveFormToEndpoint(url="/api/trafficshaper/settings/addQueue/",
formid="frm_DialogQueue", callback_ok=function(){
$("#DialogQueue").modal('hide');
$("#grid-queues").bootgrid("reload");
}, true);
}
/**
* Delete list of uuids on click event
*/
$("#deleteQueues").click(function(){
stdDialogRemoveItem("Remove selected items?",function(){
var rows =$("#grid-queues").bootgrid('getSelectedRows');
if (rows != undefined){
var deferreds = [];
$.each(rows, function(key,uuid){
deferreds.push(ajaxCall(url="/api/trafficshaper/settings/delQueue/" + uuid, sendData={},null));
});
// refresh after load
$.when.apply(null, deferreds).done(function(){
$("#grid-queues").bootgrid("reload");
});
}
});
});
/**
* Add new queue on click event
*/
$("#addQueue").click(function(){
mapDataToFormUI({'frm_DialogQueue':"/api/trafficshaper/settings/getQueue/"}).done(function(){
// update selectors
$('.selectpicker').selectpicker('refresh');
// clear validation errors (if any)
clearFormValidation('frm_DialogQueue');
});
// show dialog for queue edit
$('#DialogQueue').modal({backdrop: 'static', keyboard: false});
// curry uuid to save action
$("#btn_DialogQueue_save").unbind('click').click(addQueue);
});
/*************************************************************************************************************
* manage rules
*************************************************************************************************************/
/**
* save form data to end point for existing rule
*/
function saveRule(uuid) {
saveFormToEndpoint(url="/api/trafficshaper/settings/setRule/"+uuid,
formid="frm_DialogRule", callback_ok=function(){
$("#DialogRule").modal('hide');
$("#grid-rules").bootgrid("reload");
}, true);
}
/**
* save form data to end point for new pipe
*/
function addRule() {
saveFormToEndpoint(url="/api/trafficshaper/settings/addRule/",
formid="frm_DialogRule", callback_ok=function(){
$("#DialogRule").modal('hide');
$("#grid-rules").bootgrid("reload");
}, true);
}
/**
* Render rules grid using searchPipes api
*/
var gridRules = stdBootgridUI("grid-rules", "/api/trafficshaper/settings/searchRules");
/**
* Link rule grid command controls (edit/delete)
*/
gridRules.on("loaded.rs.jquery.bootgrid", function(){
// edit item
gridRules.find(".command-edit").on("click", function(e)
{
var uuid=$(this).data("row-id");
mapDataToFormUI({'frm_DialogRule':"/api/trafficshaper/settings/getRule/"+uuid}).done(function(){
// update selectors
$('.selectpicker').selectpicker('refresh');
// clear validation errors (if any)
clearFormValidation('frm_DialogRule');
});
// show dialog for pipe edit
$('#DialogRule').modal({backdrop: 'static', keyboard: false});
// curry uuid to save action
$("#btn_DialogRule_save").unbind('click').click(saveRule.bind(undefined, uuid));
}).end();
// delete item
gridRules.find(".command-delete").on("click", function(e)
{
var uuid = $(this).data("row-id");
stdDialogRemoveItem("Remove selected item?",function(){
ajaxCall(url="/api/trafficshaper/settings/delRule/" + uuid,
sendData={},callback=function(data,status){
// reload grid after delete
$("#grid-rules").bootgrid("reload");
});
});
}).end();
});
/**
* Add new rule on click event
*/
$("#addRule").click(function(){
mapDataToFormUI({'frm_DialogRule':"/api/trafficshaper/settings/getRule/"}).done(function(){
// update selectors
$('.selectpicker').selectpicker('refresh');
// clear validation errors (if any)
clearFormValidation('frm_DialogRule');
});
// show dialog for pipe edit
$('#DialogRule').modal({backdrop: 'static', keyboard: false});
// curry uuid to save action
$("#btn_DialogRule_save").unbind('click').click(addRule);
});
/**
* Delete list of uuids on click event
*/
$("#deleteRules").click(function(){
stdDialogRemoveItem("Remove selected items?",function(){
var rows =$("#grid-rules").bootgrid('getSelectedRows');
if (rows != undefined){
var deferreds = [];
$.each(rows, function(key,uuid){
deferreds.push(ajaxCall(url="/api/trafficshaper/settings/delRule/" + uuid, sendData={},null));
});
// refresh after load
$.when.apply(null, deferreds).done(function(){
$("#grid-rules").bootgrid("reload");
});
}
});
});
/************************************************************************************************************* /*************************************************************************************************************
...@@ -374,18 +96,15 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -374,18 +96,15 @@ POSSIBILITY OF SUCH DAMAGE.
</script> </script>
<div class="container-fluid"> <ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" href="#pipes">{{ lang._('Pipes') }}</a></li> <li class="active"><a data-toggle="tab" href="#pipes">{{ lang._('Pipes') }}</a></li>
<li><a data-toggle="tab" href="#queues">{{ lang._('Queues') }}</a></li> <li><a data-toggle="tab" href="#queues">{{ lang._('Queues') }}</a></li>
<li><a data-toggle="tab" href="#rules">{{ lang._('Rules') }}</a></li> <li><a data-toggle="tab" href="#rules">{{ lang._('Rules') }}</a></li>
</ul> </ul>
<div class="tab-content content-box tab-content"> <div class="tab-content content-box tab-content">
<div id="pipes" class="tab-pane fade in active"> <div id="pipes" class="tab-pane fade in active">
<!-- tab page "pipes" --> <!-- tab page "pipes" -->
<table id="grid-pipes" class="table table-condensed table-hover table-striped table-responsive"> <table id="grid-pipes" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogPipe">
<thead> <thead>
<tr> <tr>
<th data-column-id="origin" data-type="string" data-visible="false">Origin</th> <th data-column-id="origin" data-type="string" data-visible="false">Origin</th>
...@@ -404,8 +123,8 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -404,8 +123,8 @@ POSSIBILITY OF SUCH DAMAGE.
<tr> <tr>
<td></td> <td></td>
<td> <td>
<button type="button" id="addPipe" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span></button> <button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span></button>
<button type="button" id="deletePipes" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> <button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
...@@ -413,7 +132,7 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -413,7 +132,7 @@ POSSIBILITY OF SUCH DAMAGE.
</div> </div>
<div id="queues" class="tab-pane fade in"> <div id="queues" class="tab-pane fade in">
<!-- tab page "queues" --> <!-- tab page "queues" -->
<table id="grid-queues" class="table table-condensed table-hover table-striped table-responsive"> <table id="grid-queues" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogQueue">
<thead> <thead>
<tr> <tr>
<th data-column-id="origin" data-type="string" data-visible="false">Origin</th> <th data-column-id="origin" data-type="string" data-visible="false">Origin</th>
...@@ -431,8 +150,8 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -431,8 +150,8 @@ POSSIBILITY OF SUCH DAMAGE.
<tr> <tr>
<td></td> <td></td>
<td> <td>
<button type="button" id="addQueue" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span></button> <button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span></button>
<button type="button" id="deleteQueues" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> <button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
...@@ -440,7 +159,7 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -440,7 +159,7 @@ POSSIBILITY OF SUCH DAMAGE.
</div> </div>
<div id="rules" class="tab-pane fade in"> <div id="rules" class="tab-pane fade in">
<!-- tab page "rules" --> <!-- tab page "rules" -->
<table id="grid-rules" class="table table-condensed table-hover table-striped table-responsive"> <table id="grid-rules" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogRule">
<thead> <thead>
<tr> <tr>
<th data-column-id="sequence" data-type="number">#</th> <th data-column-id="sequence" data-type="number">#</th>
...@@ -461,8 +180,8 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -461,8 +180,8 @@ POSSIBILITY OF SUCH DAMAGE.
<tr > <tr >
<td></td> <td></td>
<td> <td>
<button type="button" id="addRule" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span></button> <button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-pencil"></span></button>
<button type="button" id="deleteRules" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button> <button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
...@@ -472,9 +191,6 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -472,9 +191,6 @@ POSSIBILITY OF SUCH DAMAGE.
<hr/> <hr/>
<button class="btn btn-primary" id="reconfigureAct" type="button"><b>Apply</b><i id="reconfigureAct_progress" class=""></i></button> <button class="btn btn-primary" id="reconfigureAct" type="button"><b>Apply</b><i id="reconfigureAct_progress" class=""></i></button>
</div> </div>
</div>
</div>
</div>
</div> </div>
......
Markdown is supported
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