Added a keypress directive.

Updated the Ledger html and controller to work with keyboard shortcut.
Still have to implement Remove entry and restore entry in ledger.

Signed-off-by: Tanshu <tanshu@gmail.com>
This commit is contained in:
Tanshu 2013-09-09 18:29:38 +05:30
parent b3ece30300
commit 909b468c9d
7 changed files with 72 additions and 8 deletions

View File

@ -0,0 +1,9 @@
/* mousetrap v1.4.5 craig.is/killing/mice */
(function(J,r,f){function s(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)}function A(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return h[a.which]?h[a.which]:B[a.which]?B[a.which]:String.fromCharCode(a.which).toLowerCase()}function t(a){a=a||{};var b=!1,c;for(c in n)a[c]?b=!0:n[c]=0;b||(u=!1)}function C(a,b,c,d,e,v){var g,k,f=[],h=c.type;if(!l[a])return[];"keyup"==h&&w(a)&&(b=[a]);for(g=0;g<l[a].length;++g)if(k=
l[a][g],!(!d&&k.seq&&n[k.seq]!=k.level||h!=k.action||("keypress"!=h||c.metaKey||c.ctrlKey)&&b.sort().join(",")!==k.modifiers.sort().join(","))){var m=d&&k.seq==d&&k.level==v;(!d&&k.combo==e||m)&&l[a].splice(g,1);f.push(k)}return f}function K(a){var b=[];a.shiftKey&&b.push("shift");a.altKey&&b.push("alt");a.ctrlKey&&b.push("ctrl");a.metaKey&&b.push("meta");return b}function x(a,b,c){m.stopCallback(b,b.target||b.srcElement,c)||!1!==a(b,c)||(b.preventDefault&&b.preventDefault(),b.stopPropagation&&b.stopPropagation(),
b.returnValue=!1,b.cancelBubble=!0)}function y(a){"number"!==typeof a.which&&(a.which=a.keyCode);var b=A(a);b&&("keyup"==a.type&&z===b?z=!1:m.handleKey(b,K(a),a))}function w(a){return"shift"==a||"ctrl"==a||"alt"==a||"meta"==a}function L(a,b,c,d){function e(b){return function(){u=b;++n[a];clearTimeout(D);D=setTimeout(t,1E3)}}function v(b){x(c,b,a);"keyup"!==d&&(z=A(b));setTimeout(t,10)}for(var g=n[a]=0;g<b.length;++g){var f=g+1===b.length?v:e(d||E(b[g+1]).action);F(b[g],f,d,a,g)}}function E(a,b){var c,
d,e,f=[];c="+"===a?["+"]:a.split("+");for(e=0;e<c.length;++e)d=c[e],G[d]&&(d=G[d]),b&&"keypress"!=b&&H[d]&&(d=H[d],f.push("shift")),w(d)&&f.push(d);c=d;e=b;if(!e){if(!p){p={};for(var g in h)95<g&&112>g||h.hasOwnProperty(g)&&(p[h[g]]=g)}e=p[c]?"keydown":"keypress"}"keypress"==e&&f.length&&(e="keydown");return{key:d,modifiers:f,action:e}}function F(a,b,c,d,e){q[a+":"+c]=b;a=a.replace(/\s+/g," ");var f=a.split(" ");1<f.length?L(a,f,b,c):(c=E(a,c),l[c.key]=l[c.key]||[],C(c.key,c.modifiers,{type:c.action},
d,a,e),l[c.key][d?"unshift":"push"]({callback:b,modifiers:c.modifiers,action:c.action,seq:d,level:e,combo:a}))}var h={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},B={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},H={"~":"`","!":"1",
"@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},G={option:"alt",command:"meta","return":"enter",escape:"esc",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},p,l={},q={},n={},D,z=!1,I=!1,u=!1;for(f=1;20>f;++f)h[111+f]="f"+f;for(f=0;9>=f;++f)h[f+96]=f;s(r,"keypress",y);s(r,"keydown",y);s(r,"keyup",y);var m={bind:function(a,b,c){a=a instanceof Array?a:[a];for(var d=0;d<a.length;++d)F(a[d],b,c);return this},
unbind:function(a,b){return m.bind(a,function(){},b)},trigger:function(a,b){if(q[a+":"+b])q[a+":"+b]({},a);return this},reset:function(){l={};q={};return this},stopCallback:function(a,b){return-1<(" "+b.className+" ").indexOf(" mousetrap ")?!1:"INPUT"==b.tagName||"SELECT"==b.tagName||"TEXTAREA"==b.tagName||b.isContentEditable},handleKey:function(a,b,c){var d=C(a,b,c),e;b={};var f=0,g=!1;for(e=0;e<d.length;++e)d[e].seq&&(f=Math.max(f,d[e].level));for(e=0;e<d.length;++e)d[e].seq?d[e].level==f&&(g=!0,
b[d[e].seq]=1,x(d[e].callback,c,d[e].combo)):g||x(d[e].callback,c,d[e].combo);d="keypress"==c.type&&I;c.type!=u||w(a)||d||t(b);I=g&&"keydown"==c.type}};J.Mousetrap=m;"function"===typeof define&&define.amd&&define(m)})(window,document);

View File

@ -1,6 +1,6 @@
CACHE MANIFEST
# version 2013-06-30.1
# version 2013-09-11.1
CACHE:
/partial/404.html

View File

@ -19,7 +19,7 @@
<div class="control-group">
<label for="gvGrid" class="control-label"></label>
<div class="controls">
<div class="controls" keypress='shortcuts'>
<table id="gvGrid" class="table table-condensed table-bordered table-striped">
<thead>
<tr>
@ -33,7 +33,7 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="item in info.Body" ng-class="{true:'', false:'error'}[item.Posted]">
<tr ng-repeat="item in info.Body" ng-class="{error:!item.Posted, info:$index==selected}" ng-click="setSelected($index)">
<td class="no-wrap">{{item.Date}}</td>
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td class="no-wrap">{{item.Type}}</td>

View File

@ -264,6 +264,7 @@ overlord_directive.directive('aceEditor', ['$parse', function ($parse) {
editor.getSession().on('change', function () {
if (valid(editor)) {
// ngModel.$setViewValue(editor.getValue());
setter(scope, editor.getValue());
scope.$apply();
}
@ -319,4 +320,19 @@ overlord_directive.directive('chosen', ['$parse', function ($parse) {
restrict: 'A',
link: linker
}
}])
}])
overlord_directive.directive('keypress', [function () {
return function (scope, element, attrs) {
// console.log(scope, element, attrs);
var attribute = scope.$eval(attrs.keypress || '{}');
for (var k in attribute) {
(function (k) {
console.log('binding ' + k + ' as ' + attribute[k]);
Mousetrap.bind(k, function () {
return attribute[k](scope, element);
});
})(k);
}
};
}]);

View File

@ -1,13 +1,46 @@
'use strict';
var LedgerCtrl = ['$scope', '$routeParams', '$location', 'ledger', 'Ledger', function ($scope, $routeParams, $location, ledger, Ledger) {
$scope.shortcuts = {
'up': function () {
if ($scope.selected > 0) {
$scope.$apply(function () {
$scope.selected = $scope.selected -= 1;
});
}
},
'down': function () {
if ($scope.selected < $scope.info.Body.length - 1) {
$scope.$apply(function () {
$scope.selected = $scope.selected += 1;
});
}
},
'alt+r': function () {
console.log('alt+r');
},
'enter': function () {
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');
}
};
$scope.selected = 0;
$scope.setSelected = function (index) {
$scope.selected = index;
}
$scope.info = ledger;
$scope.show = function () {
var id = $scope.info.Ledger.LedgerID;
var start_date = $scope.info.StartDate;
var finish_date = $scope.info.FinishDate;
if (id == $routeParams.id && start_date == $routeParams.StartDate && finish_date == $routeParams.FinishDate) {
Ledger.get({id:id, StartDate:start_date, FinishDate:finish_date}, function (data) {
Ledger.get({id: id, StartDate: start_date, FinishDate: finish_date}, function (data) {
$scope.info = data;
});
}
@ -21,11 +54,15 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'ledger', 'Ledger', fun
html = html.replace(/á/g, '&aacute;');
window.open('data:application/vnd.ms-excel;charset=UTF-8,' + encodeURIComponent(html));
}
$('#txtLedger').focus();
if ($routeParams.id) {
$('#gvGrid').focus();
} else {
$('#txtLedger').focus();
}
}]
LedgerCtrl.resolve = {
ledger:['$q', '$route', 'Ledger', function ($q, $route, Ledger) {
ledger: ['$q', '$route', 'Ledger', function ($q, $route, Ledger) {
var deferred = $q.defer();
var id = $route.current.params.id;
@ -39,7 +76,7 @@ LedgerCtrl.resolve = {
if (typeof id === 'undefined') {
Ledger.get({}, successCb);
} else {
Ledger.get({id:id, StartDate:start_date, FinishDate:finish_date}, successCb);
Ledger.get({id: id, StartDate: start_date, FinishDate: finish_date}, successCb);
}
return deferred.promise;
}]

View File

@ -20,6 +20,7 @@
<link rel="stylesheet" type="text/css" media="screen" href="/css/spinner.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="/css/chosen.css"/>
<script src="/js/mousetrap.min-1.4.5.js"></script>
<script src="/js/jquery-2.0.2.min.js"></script>
<script src="/js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="/js/bootstrap.min.js"></script>

View File

@ -0,0 +1 @@
__author__ = 'tanshu'