mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 18:54:58 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			133 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
		
			Vendored
		
	
	
	
			
		
		
	
	
			133 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
		
			Vendored
		
	
	
	
| /*
 | |
|  * show.js
 | |
|  * Copyright (c) 2019 james@firefly-iii.org
 | |
|  *
 | |
|  * This file is part of Firefly III (https://github.com/firefly-iii).
 | |
|  *
 | |
|  * This program is free software: you can redistribute it and/or modify
 | |
|  * it under the terms of the GNU Affero General Public License as
 | |
|  * published by the Free Software Foundation, either version 3 of the
 | |
|  * License, or (at your option) any later version.
 | |
|  *
 | |
|  * This program is distributed in the hope that it will be useful,
 | |
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
|  * GNU Affero General Public License for more details.
 | |
|  *
 | |
|  * You should have received a copy of the GNU Affero General Public License
 | |
|  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | |
|  */
 | |
| 
 | |
| /** global: chartUri, incomeCategoryUri, showAll, expenseCategoryUri, expenseBudgetUri, token */
 | |
| 
 | |
| 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 () {
 | |
|     "use strict";
 | |
|     //lineChart(chartUri, 'overview-chart');
 | |
|     lineNoStartZeroChart(chartUri, 'overview-chart');
 | |
|     if (!showAll) {
 | |
|         multiCurrencyPieChart(incomeCategoryUri, 'account-cat-in');
 | |
|         multiCurrencyPieChart(expenseCategoryUri, 'account-cat-out');
 | |
|         multiCurrencyPieChart(expenseBudgetUri, 'account-budget-out');
 | |
|     }
 | |
| 
 | |
|     // sortable!
 | |
|     if (typeof $(".sortable-table tbody").sortable !== "undefined") {
 | |
|         $(".sortable-table tbody").sortable(
 | |
|             {
 | |
|                 helper: fixHelper,
 | |
|                 items: 'tr:not(.ignore)',
 | |
|                 stop: sortStop,
 | |
|                 handle: '.handle',
 | |
|                 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>');
 | |
|                 }
 | |
|             }
 | |
|         );
 | |
|     }
 | |
| 
 | |
|     if (doPlaceMarker === true) {
 | |
|         /*
 | |
|          Create new map:
 | |
|          */
 | |
| 
 | |
|         // make map:
 | |
|         var mymap = L.map('location_map', {
 | |
|             zoomControl: false,
 | |
|             touchZoom: false,
 | |
|             doubleClickZoom: false,
 | |
|             scrollWheelZoom: false,
 | |
|             boxZoom: false,
 | |
|             dragging: false
 | |
|         }).setView([latitude, longitude], zoomLevel);
 | |
| 
 | |
|         L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
 | |
|             attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
 | |
|             maxZoom: 18,
 | |
|             id: 'mapbox.streets',
 | |
|             accessToken: mapboxToken
 | |
|         }).addTo(mymap);
 | |
|         L.marker([latitude, longitude]).addTo(mymap);
 | |
|     }
 | |
| 
 | |
| });
 | |
| 
 | |
| 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;
 | |
|     }
 | |
| 
 | |
|     // 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;
 | |
| }
 |