Feature: Keyboard navigation in ledger with Remove and Undo.

This commit is contained in:
Amritanshu committed 2014-06-04 16:02:33 +05:30
1 parent 4e85d97e47
commit 248a841695
6 files changed
+186 -23

No files matched your search

+6 -4
View File
@@ -125,13 +125,15 @@ overlord_directive.directive('keypress', [function () {
var attribute = scope.$eval(attrs.keypress || '{}');
for (var k in attribute) {
(function (k) {
Mousetrap.bind(k, function () {
return attribute[k](scope, element);
});
Mousetrap.bind(k, attribute[k]);
})(k);
}
element.on('$destroy', function () {
$interval.cancel(timeoutId);
for (var k in attribute) {
(function (k) {
Mousetrap.unbind(k);
})(k);
}
});
};
+62 -7
View File
@@ -2,6 +2,7 @@
var LedgerCtrl = ['$scope', '$routeParams', '$location', 'dateFilter', 'ledger', 'Ledger', 'Account', function ($scope, $routeParams, $location, dateFilter, ledger, Ledger, Account) {
$scope.info = ledger;
$scope.hidden = [];
$scope.show = function () {
var id = $scope.info.Ledger.LedgerID;
var start_date = angular.isDate($scope.info.StartDate) ? dateFilter($scope.info.StartDate, 'dd-MMM-yyyy') : $scope.info.StartDate;
@@ -14,6 +15,7 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'dateFilter', 'ledger',
$location.path('/Ledger/' + id).search('StartDate', start_date).search('FinishDate', finish_date);
}
};
$scope.downloadTable = function () {
var table = $('#gvGrid'),
html = table.clone().wrap('<div></div>').parent().html();
@@ -32,32 +34,85 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'dateFilter', 'ledger',
$scope.selected = index;
};
$scope.$watch('hidden', function () {
$scope.display = doFilter($scope.info, $scope.hidden);
}, true);
var doFilter = function (input, hidden) {
var ledger = angular.copy(input),
data = ledger.Body,
footer = ledger.Footer,
debit = 0, credit = 0, running = 0;
if (hidden.length !== 0) {
data = _.filter(data, function (item) {
return !_.any(hidden, function (hi) {
if (!item.hasOwnProperty('Url') && !hi.hasOwnProperty('Url')) {
return true;
} else if (item.hasOwnProperty('Url') !== hi.hasOwnProperty('Url')) {
return false;
}
return item.Url === hi.Url;
});
});
}
_.forEach(data, function (item) {
debit += item.Debit;
credit += item.Credit;
running = debit - credit;
item.Running = running;
});
footer.Debit = debit;
footer.Credit = credit;
footer.Running = running;
return {Body: data, Footer: footer};
};
$scope.shortcuts = {
'up': function () {
'up': function (e) {
if ($scope.selected > 0) {
$scope.$apply(function () {
$scope.selected = $scope.selected -= 1;
});
$("#" + $scope.selected).scrollintoview({duration: 'fast'});
e.preventDefault();
}
},
'down': function () {
'down': function (e) {
if ($scope.selected < $scope.info.Body.length - 1) {
$scope.$apply(function () {
$scope.selected = $scope.selected += 1;
});
$("#" + $scope.selected).scrollintoview({duration: 'fast'});
e.preventDefault();
}
},
'alt+r': function () {
console.log('alt+r');
'alt+r': function (e) {
if ($scope.selected > -1) {
$scope.$apply(function () {
var max = $scope.display.Body.length;
$scope.hidden.push(angular.copy($scope.display.Body[$scope.selected]));
if ($scope.selected === max -1) {
$scope.selected = max - 2;
}
});
}
e.preventDefault();
},
'enter': function () {
'enter': function (e) {
var path = $scope.info.Body[$scope.selected].Url.replace(/^(?:\/\/|[^\/]+)*/, "");
$scope.$apply(function () {
$location.path(path).search('StartDate', null).search('FinishDate', null);
});
},
'alt+u': function () {
console.log('alt+u');
'alt+u': function (e) {
if ($scope.hidden.length !== 0) {
$scope.$apply(function () {
$scope.hidden.pop();
});
}
e.preventDefault();
}
};