use which instead of keycode
[xtuple] / lib / enyo-x / source / app.js
index c42d466..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 () {
 
@@ -19,8 +19,7 @@ white:true*/
   enyo.kind(
     /** @lends XV.App# */{
     name: "XV.App",
-    fit: true,
-    classes: "xt-app enyo-unselectable",
+    classes: "enyo-fit enyo-unselectable",
     published: {
       isStarted: false,
       debug: false,
@@ -35,7 +34,7 @@ white:true*/
       onHistoryItemSelected: "selectHistoryItem",
       onSearch: "waterfallSearch",
       onWorkspace: "waterfallWorkspace",
-      onColumnsChange: "columnsDidChange",
+      onColumnsChange: "columnsDidChange"
     },
     /*
       Three use cases:
@@ -44,27 +43,44 @@ white:true*/
       pattern-match mode
     */
     handleKeyDown: function (inSender, inEvent) {
-      var that = this;
+      var that = this,
+        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(inEvent.keyCode);
+      this._keyBufferArray.push(keyCode);
       this._keyBufferArray = this._keyBufferArray.slice(-10);
 
       // not working
       if (this.$.postbooks.isNotifyPopupShowing()) {
-        this.$.postbooks.notifyKey(inEvent.keyCode, inEvent.shiftKey);
+        this.$.postbooks.notifyKey(keyCode, inEvent.shiftKey);
         return;
       }
 
       if (inEvent.altKey) {
         inEvent.cancelBubble = true;
         inEvent.returnValue = false;
-        this.processHotKey(inEvent.keyCode);
+        this.processHotKey(keyCode);
         return true;
       }
       if (this._keyBufferEndPattern) {
         // we're in record mode, so record.
-        this._keyBuffer = this._keyBuffer + String.fromCharCode(inEvent.keyCode);
+        this._keyBuffer = this._keyBuffer + String.fromCharCode(keyCode);
       }
 
       if (this._keyBufferEndPattern &&
@@ -74,6 +90,10 @@ white:true*/
 
       } else if (this._keyBufferEndPattern &&
           _.isEqual(this._keyBufferArray.slice(-1 * this._keyBufferEndPattern.length), this._keyBufferEndPattern)) {
+
+        // first slice the end pattern off the payload
+        this._keyBuffer = this._keyBuffer.substring(0, this._keyBuffer.length - this._keyBufferEndPattern.length);
+
         // we've matched an end pattern. Send the recorded buffer to the appropriate method
         this[this._keyBufferMethod](this._keyBuffer);
         this._keyBuffer = "";
@@ -311,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);
 
@@ -335,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