mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Optimise code.
This commit is contained in:
6
public/v1/js/ff/charts.js
vendored
6
public/v1/js/ff/charts.js
vendored
@@ -64,11 +64,11 @@ function colorizeData(data) {
|
||||
var newData = {};
|
||||
newData.datasets = [];
|
||||
|
||||
for (var i = 0; i < data.count; i++) {
|
||||
for (var loop = 0; loop < data.count; loop++) {
|
||||
newData.labels = data.labels;
|
||||
var dataset = data.datasets[i];
|
||||
var dataset = data.datasets[loop];
|
||||
dataset.fill = false;
|
||||
dataset.backgroundColor = dataset.borderColor = fillColors[i];
|
||||
dataset.backgroundColor = dataset.borderColor = fillColors[loop];
|
||||
newData.datasets.push(dataset);
|
||||
}
|
||||
return newData;
|
||||
|
92
public/v1/js/ff/list/groups.js
vendored
92
public/v1/js/ff/list/groups.js
vendored
@@ -22,7 +22,97 @@ var count = 0;
|
||||
|
||||
$(document).ready(function () {
|
||||
updateListButtons();
|
||||
addSort();
|
||||
});
|
||||
|
||||
var fixHelper = function (e, tr) {
|
||||
"use strict";
|
||||
var $originals = tr.children();
|
||||
var $helper = tr.clone();
|
||||
$helper.children().each(function (index) {
|
||||
// Set helper cell sizes to match the original sizes
|
||||
$(this).width($originals.eq(index).width());
|
||||
});
|
||||
return $helper;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function addSort() {
|
||||
if (typeof $(".table-sortable>tbody").sortable !== "undefined") {
|
||||
$('.table-sortable>tbody').sortable(
|
||||
{
|
||||
items: "tr:not(.unsortable)",
|
||||
handle: '.object-handle',
|
||||
stop: sortStop,
|
||||
start: function (event, ui) {
|
||||
// Build a placeholder cell that spans all the cells in the row
|
||||
var cellCount = 0;
|
||||
$('td, th', ui.helper).each(function () {
|
||||
// For each TD or TH try and get it's colspan attribute, and add that or 1 to the total
|
||||
var colspan = 1;
|
||||
var colspanAttr = $(this).attr('colspan');
|
||||
if (colspanAttr > 1) {
|
||||
colspan = colspanAttr;
|
||||
}
|
||||
cellCount += colspan;
|
||||
});
|
||||
|
||||
// Add the placeholder UI - note that this is the item's content, so TD rather than TR
|
||||
ui.placeholder.html('<td colspan="' + cellCount + '"> </td>');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event
|
||||
* @param ui
|
||||
* @returns {boolean|undefined}
|
||||
*/
|
||||
function sortStop(event, ui) {
|
||||
"use strict";
|
||||
var current = $(ui.item);
|
||||
var thisDate = current.data('date');
|
||||
var originalBG = current.css('backgroundColor');
|
||||
|
||||
|
||||
if (current.prev().data('date') !== thisDate && current.next().data('date') !== thisDate) {
|
||||
// animate something with color:
|
||||
current.animate({backgroundColor: "#d9534f"}, 200, function () {
|
||||
$(this).animate({backgroundColor: originalBG}, 200);
|
||||
return undefined;
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
//return false;
|
||||
// do update
|
||||
var list = $('tr[data-date="' + thisDate + '"]');
|
||||
var submit = [];
|
||||
$.each(list, function (i, v) {
|
||||
var row = $(v);
|
||||
var id = row.data('id');
|
||||
submit.push(id);
|
||||
});
|
||||
|
||||
// do extra animation when done?
|
||||
$.post('transactions/reorder', {items: submit, date: thisDate, _token: token});
|
||||
|
||||
current.animate({backgroundColor: "#5cb85c"}, 200, function () {
|
||||
$(this).animate({backgroundColor: originalBG}, 200);
|
||||
return undefined;
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function updateListButtons() {
|
||||
// top button to select all / deselect all:
|
||||
$('input[name="select-all"]').change(function () {
|
||||
@@ -91,8 +181,6 @@ function getCheckboxes() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function countChecked() {
|
||||
count = $('.mass-select:checked').length;
|
||||
}
|
||||
|
20
public/v1/js/ff/rules/index.js
vendored
20
public/v1/js/ff/rules/index.js
vendored
@@ -59,7 +59,7 @@ function testRuleTriggers(e) {
|
||||
|
||||
var modal = $("#testTriggerModal");
|
||||
// respond to modal:
|
||||
modal.on('hide.bs.modal', function (e) {
|
||||
modal.on('hide.bs.modal', function () {
|
||||
disableRuleSpinners();
|
||||
});
|
||||
|
||||
@@ -98,28 +98,28 @@ function sortStop(event, ui) {
|
||||
|
||||
// resort / move rule
|
||||
$.each($('.group-rules'), function(i,v) {
|
||||
$.each($('tr.single-rule', $(v)), function (i, v) {
|
||||
var holder = $(v);
|
||||
$.each($('tr.single-rule', $(v)), function (counter, value) {
|
||||
var holder = $(value);
|
||||
var position = parseInt(holder.data('position'));
|
||||
var ruleGroupId = holder.data('group-id');
|
||||
var ruleId = holder.data('id');
|
||||
var originalOrder = parseInt(holder.data('order'));
|
||||
var newOrder;
|
||||
|
||||
if (position === i) {
|
||||
if (position === counter) {
|
||||
// not changed, position is what it should be.
|
||||
return;
|
||||
}
|
||||
if (position < i) {
|
||||
if (position < counter) {
|
||||
// position is less.
|
||||
console.log('Rule #' + ruleId + ' moved down from position ' + originalOrder + ' to ' + (i + 1));
|
||||
console.log('Rule #' + ruleId + ' moved down from position ' + originalOrder + ' to ' + (counter + 1));
|
||||
}
|
||||
if (position > i) {
|
||||
console.log('Rule #' + ruleId + ' moved up from position ' + originalOrder + ' to ' + (i + 1));
|
||||
if (position > counter) {
|
||||
console.log('Rule #' + ruleId + ' moved up from position ' + originalOrder + ' to ' + (counter + 1));
|
||||
}
|
||||
// update position:
|
||||
holder.data('position', i);
|
||||
newOrder = i+1;
|
||||
holder.data('position', counter);
|
||||
newOrder = counter + 1;
|
||||
|
||||
$.post('rules/move-rule/' + ruleId + '/' + ruleGroupId, {order: newOrder, _token: token});
|
||||
});
|
||||
|
Reference in New Issue
Block a user