use which instead of keycode
[xtuple] / lib / enyo-x / source / app.js
index 20e2b53..ff4a060 100644 (file)
@@ -1,7 +1,7 @@
 /*jshint indent:2, curly:true, eqeqeq:true, immed:true, latedef:true,
 newcap:true, noarg:true, regexp:true, undef:true, trailing:true,
 white:true*/
-/*global enyo:true, XT:true, _:true, document:true, window:true, XM:true */
+/*global Backbone:true, enyo:true, XT:true, _:true, document:true, window:true, XM:true */
 
 (function () {
 
@@ -44,7 +44,23 @@ white:true*/
     */
     handleKeyDown: function (inSender, inEvent) {
       var that = this,
-        keyCode = inEvent.keyCode;
+        keyCode = inEvent.which,
+        exoticTransforms = {},
+        numberShiftCharacters = ")!@#$%^&*(";
+
+      // exotic transforms. sorta hackish, but the inEvent codes coming
+      // through are not always the ones we want
+
+      // http://stackoverflow.com/questions/1898129/javascript-subtract-keycode
+      exoticTransforms[XT.ASCII.VULGAR_HALF] = XT.ASCII.N_DASH;
+      if (_.contains(Object.keys(exoticTransforms), "" + keyCode)) {
+        // account for inexplicably wrongly mapped keys
+        keyCode = exoticTransforms[keyCode];
+      } else if (inEvent.shiftKey && keyCode >= XT.ASCII.ZERO && keyCode <= XT.ASCII.NINE) {
+        // shift-number should be transformed into the appropriate character
+        // XXX jingoistic implementation
+        keyCode = numberShiftCharacters.charCodeAt(keyCode - XT.ASCII.ZERO);
+      }
 
       // remember the last 10 key presses
       this._keyBufferArray.push(keyCode);
@@ -56,10 +72,6 @@ white:true*/
         return;
       }
 
-      if (keyCode === 189) {
-        // XXX FIXME hack. Dashes aren't coming through as dashes from my keyboard
-        keyCode = '-'.charCodeAt(0);
-      }
       if (inEvent.altKey) {
         inEvent.cancelBubble = true;
         inEvent.returnValue = false;
@@ -319,11 +331,23 @@ white:true*/
         details = XT.session.details;
         loginInfo.setContent(details.username + " ยท " + details.organization);
         this.state = RUNNING;
+        that.startupProcess();
+
+      // TODO - 7. Initiate Empty Database Startup "checklist" process for empty/quick start databases
+      } else if (this.state === RUNNING) {
+        // No process in place so proceed to activate
+        XM.Tuplespace.trigger("activate");
         XT.app.$.postbooks.activate();
+
+        // Send no Base Currency event
+        if (!XT.baseCurrency()) {
+          this.waterfallNoBaseCurr();
+        }
+        Backbone.history.start();
       }
     },
     start: function (debug) {
-      if (this.getIsStarted()) { return; }
+      if (this.getIsStarted()) {return; }
       XT.app = this;
       this.setDebug(debug);
 
@@ -343,6 +367,10 @@ white:true*/
     togglePullout: function (inSender, inEvent) {
       this.$.pullout.togglePullout(inSender, inEvent);
     },
+    waterfallNoBaseCurr: function (inSender, inEvent) {
+      this.$.postbooks.waterfall("onNoBaseCurr", inEvent);
+      return true;
+    },
     waterfallSearch: function (inSender, inEvent) {
       this.$.postbooks.waterfall("onSearch", inEvent);
       return true; // don't want to double up