Skip to content

Instantly share code, notes, and snippets.

@jazlopez
Created March 2, 2016 20:34
Show Gist options
  • Save jazlopez/b599fba1cc26488f4f6e to your computer and use it in GitHub Desktop.
Save jazlopez/b599fba1cc26488f4f6e to your computer and use it in GitHub Desktop.
Backoffice | handle archive update bulk mode | Add form submit filters
/**
*
* Utility Backoffice Object
*/
window.backoffice = Object.create({
/**
* Getter URL parameters
* @param name
* @returns {string|null}
*/
getUrlParameter: function (name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)')
.exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || '';
},
/**
* Disable any generic form action button
* Useful if the buttons needs to go away after taking an action
*/
disableFormButtons: function () {
var elements = document.getElementsByClassName('form-actions');
while (elements.length > 0)
elements[0].parentNode.removeChild(elements[0]);
},
/**
* Submit new product purchase order
*/
submitOrder: function () {
document.getElementById('orderForm').action += '?vendor_id=' + this.getUrlParameter('vendor_id');
document.getElementById('orderForm').action += '&product_id=' + this.getUrlParameter('product_id');
document.getElementById('orderForm').submit();
},
/**
* Redirect to empty order form
*/
resetOrder: function () {
document.location.href = '{{ path('back_office_orders') }}';
},
/**
* Submit filters for reports
**/
filterReport: function () {
// TODO: validate inputs of this form
document.getElementById('filterReportForm').submit();
},
/**
*
* Get selected items and archive bulk mode
*/
archiveSelected: function (_dt) {
var shipIds = [];
$.each(_dt.rows, function (index, row) {
if ($(row).hasClass('selected')) shipIds.push(parseInt($(row)[0].cells[0].innerHTML));
});
document.getElementById('archiveShipmentsId').value = shipIds.join(',');
document.getElementById('massShipmentArchive').submit();
},
/**
*
* Get selected items and mark as shipped bulk mode
*/
shipSelected: function (_dt) {
var shipIds = [];
$.each(_dt.rows, function (index, row) {
if ($(row).hasClass('selected')) shipIds.push(parseInt($(row)[0].cells[0].innerHTML));
});
document.getElementById('updateShipmentsId').value = shipIds.join(',');
document.getElementById('massShipmentUpdate').submit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment