2015-02-24 14:10:25 -06:00
|
|
|
$(function () {
|
|
|
|
$('.addMoney').on('click', addMoney);
|
|
|
|
$('.removeMoney').on('click', removeMoney);
|
|
|
|
|
|
|
|
if (typeof(googleLineChart) === 'function' && typeof(piggyBankID) !== 'undefined') {
|
|
|
|
googleLineChart('chart/piggy-history/' + piggyBankID, 'piggy-bank-history');
|
|
|
|
}
|
2015-04-28 02:15:31 -05:00
|
|
|
|
|
|
|
$('#sortable tbody').sortable(
|
2015-03-15 12:00:33 -05:00
|
|
|
{
|
2015-04-28 02:15:31 -05:00
|
|
|
helper: fixHelper,
|
2015-03-15 12:00:33 -05:00
|
|
|
stop: stopSorting,
|
|
|
|
handle: '.handle'
|
|
|
|
}
|
|
|
|
);
|
2015-02-24 14:10:25 -06:00
|
|
|
});
|
|
|
|
|
2015-04-28 02:15:31 -05:00
|
|
|
// Return a helper with preserved width of cells
|
|
|
|
var fixHelper = function (e, ui) {
|
|
|
|
ui.children().each(function () {
|
|
|
|
$(this).width($(this).width());
|
|
|
|
});
|
|
|
|
return ui;
|
|
|
|
};
|
|
|
|
|
2015-02-24 14:10:25 -06:00
|
|
|
function addMoney(e) {
|
|
|
|
var pigID = parseInt($(e.target).data('id'));
|
2015-03-15 12:00:33 -05:00
|
|
|
$('#moneyManagementModal').empty().load('piggy-banks/add/' + pigID, function () {
|
|
|
|
$('#moneyManagementModal').modal('show');
|
|
|
|
});
|
2015-02-24 14:10:25 -06:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeMoney(e) {
|
|
|
|
var pigID = parseInt($(e.target).data('id'));
|
2015-03-15 12:00:33 -05:00
|
|
|
$('#moneyManagementModal').empty().load('piggy-banks/remove/' + pigID, function () {
|
|
|
|
$('#moneyManagementModal').modal('show');
|
|
|
|
});
|
2015-02-24 14:10:25 -06:00
|
|
|
|
|
|
|
return false;
|
2015-03-15 12:00:33 -05:00
|
|
|
}
|
|
|
|
function stopSorting() {
|
|
|
|
$('.loadSpin').addClass('fa fa-refresh fa-spin');
|
|
|
|
var order = [];
|
2015-04-28 02:15:31 -05:00
|
|
|
$.each($('#sortable>tr'), function(i,v) {
|
2015-03-15 12:00:33 -05:00
|
|
|
var holder = $(v);
|
|
|
|
var id = holder.data('id');
|
|
|
|
order.push(id);
|
|
|
|
});
|
|
|
|
$.post('/piggy-banks/sort',{_token: token, order: order}).success(function(data) {
|
|
|
|
"use strict";
|
|
|
|
$('.loadSpin').removeClass('fa fa-refresh fa-spin');
|
|
|
|
});
|
2015-02-24 14:10:25 -06:00
|
|
|
}
|