|
| 1 | +/** @class Used for communicating between Tableau desktop/server and the WDC's |
| 2 | +* Javascript. is predominantly a pass-through to the Qt WebBridge methods |
| 3 | +* @param nativeApiRootObj {Object} - The root object where the native Api methods |
| 4 | +* are available. For WebKit, this is window. |
| 5 | +*/ |
| 6 | +function NativeDispatcher (nativeApiRootObj) { |
| 7 | + this.nativeApiRootObj = nativeApiRootObj; |
| 8 | + this._initPublicInterface(); |
| 9 | + this._initPrivateInterface(); |
| 10 | +} |
| 11 | + |
| 12 | +NativeDispatcher.prototype._initPublicInterface = function() { |
| 13 | + console.log("Initializing public interface for NativeDispatcher"); |
| 14 | + this._submitCalled = false; |
| 15 | + |
| 16 | + var publicInterface = {}; |
| 17 | + publicInterface.abortForAuth = this._abortForAuth.bind(this); |
| 18 | + publicInterface.abortWithError = this._abortWithError.bind(this); |
| 19 | + publicInterface.addCrossOriginException = this._addCrossOriginException.bind(this); |
| 20 | + publicInterface.log = this._log.bind(this); |
| 21 | + publicInterface.submit = this._submit.bind(this); |
| 22 | + publicInterface.reportProgress = this._reportProgress.bind(this); |
| 23 | + |
| 24 | + this.publicInterface = publicInterface; |
| 25 | +} |
| 26 | + |
| 27 | +NativeDispatcher.prototype._abortForAuth = function(msg) { |
| 28 | + this.nativeApiRootObj.WDCBridge_Api_abortForAuth.api(msg); |
| 29 | +} |
| 30 | + |
| 31 | +NativeDispatcher.prototype._abortWithError = function(msg) { |
| 32 | + this.nativeApiRootObj.WDCBridge_Api_abortWithError.api(msg); |
| 33 | +} |
| 34 | + |
| 35 | +NativeDispatcher.prototype._addCrossOriginException = function(destOriginList) { |
| 36 | + this.nativeApiRootObj.WDCBridge_Api_addCrossOriginException.api(destOriginList); |
| 37 | +} |
| 38 | + |
| 39 | +NativeDispatcher.prototype._log = function(msg) { |
| 40 | + this.nativeApiRootObj.WDCBridge_Api_log.api(msg); |
| 41 | +} |
| 42 | + |
| 43 | +NativeDispatcher.prototype._submit = function() { |
| 44 | + if (this._submitCalled) { |
| 45 | + console.log("submit called more than once"); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + this._submitCalled = true; |
| 50 | + this.nativeApiRootObj.WDCBridge_Api_submit.api(); |
| 51 | +}; |
| 52 | + |
| 53 | +NativeDispatcher.prototype._initPrivateInterface = function() { |
| 54 | + console.log("Initializing private interface for NativeDispatcher"); |
| 55 | + |
| 56 | + this._initCallbackCalled = false; |
| 57 | + this._shutdownCallbackCalled = false; |
| 58 | + |
| 59 | + var privateInterface = {}; |
| 60 | + privateInterface._initCallback = this._initCallback.bind(this); |
| 61 | + privateInterface._shutdownCallback = this._shutdownCallback.bind(this); |
| 62 | + privateInterface._schemaCallback = this._schemaCallback.bind(this); |
| 63 | + privateInterface._tableDataCallback = this._tableDataCallback.bind(this); |
| 64 | + privateInterface._dataDoneCallback = this._dataDoneCallback.bind(this); |
| 65 | + |
| 66 | + this.privateInterface = privateInterface; |
| 67 | +} |
| 68 | + |
| 69 | +NativeDispatcher.prototype._initCallback = function() { |
| 70 | + if (this._initCallbackCalled) { |
| 71 | + console.log("initCallback called more than once"); |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + this._initCallbackCalled = true; |
| 76 | + this.nativeApiRootObj.WDCBridge_Api_initCallback.api(); |
| 77 | +} |
| 78 | + |
| 79 | +NativeDispatcher.prototype._shutdownCallback = function() { |
| 80 | + if (this._shutdownCallbackCalled) { |
| 81 | + console.log("shutdownCallback called more than once"); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + this._shutdownCallbackCalled = true; |
| 86 | + this.nativeApiRootObj.WDCBridge_Api_shutdownCallback.api(); |
| 87 | +} |
| 88 | + |
| 89 | +NativeDispatcher.prototype._schemaCallback = function(schema, standardConnections) { |
| 90 | + // Check to make sure we are using a version of desktop which has the WDCBridge_Api_schemaCallbackEx defined |
| 91 | + if (!!this.nativeApiRootObj.WDCBridge_Api_schemaCallbackEx) { |
| 92 | + // Providing standardConnections is optional but we can't pass undefined back because Qt will choke |
| 93 | + this.nativeApiRootObj.WDCBridge_Api_schemaCallbackEx.api(schema, standardConnections || []); |
| 94 | + } else { |
| 95 | + this.nativeApiRootObj.WDCBridge_Api_schemaCallback.api(schema); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +NativeDispatcher.prototype._tableDataCallback = function(tableName, data) { |
| 100 | + this.nativeApiRootObj.WDCBridge_Api_tableDataCallback.api(tableName, data); |
| 101 | +} |
| 102 | + |
| 103 | +NativeDispatcher.prototype._reportProgress = function (progress) { |
| 104 | + this.nativeApiRootObj.WDCBridge_Api_reportProgress.api(progress); |
| 105 | +} |
| 106 | + |
| 107 | +NativeDispatcher.prototype._dataDoneCallback = function() { |
| 108 | + this.nativeApiRootObj.WDCBridge_Api_dataDoneCallback.api(); |
| 109 | +} |
| 110 | + |
| 111 | +module.exports = NativeDispatcher; |
0 commit comments