This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved script injection back inline, #36
- Loading branch information
Showing
5 changed files
with
126 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,58 @@ | ||
define( [ 'mockForms' ], function( mockForms ) { | ||
return { | ||
if ( !window.androidContext ) { | ||
var getURLParameter, loadScript; | ||
|
||
console.log( 'loading the things' ); | ||
|
||
loadScript = function( filename ) { | ||
//var fileref = document.createElement( 'script' ); | ||
//fileref.setAttribute( "type", "text/javascript" ); | ||
//fileref.setAttribute( "src", filename ); | ||
//document.getElementsByTagName( "head" )[ 0 ].appendChild( fileref ) | ||
// get some kind of XMLHttpRequest | ||
var xhrObj = new XMLHttpRequest(); | ||
// open and send a synchronous request | ||
xhrObj.open( 'GET', filename, false ); | ||
xhrObj.send( '' ); | ||
// add the returned content to a newly created script tag | ||
var se = document.createElement( 'script' ); | ||
se.type = "text/javascript"; | ||
se.text = xhrObj.responseText; | ||
document.getElementsByTagName( 'head' )[ 0 ].appendChild( se ); | ||
}; | ||
|
||
getURLParameter = function( name ) { | ||
return decodeURI( | ||
( RegExp( name + '=' + '(.+?)(&|$)' ).exec( location.search ) || [ , null ] )[ 1 ] | ||
); | ||
}; | ||
|
||
loadScript( '../build/mock/transforms.mock.js' ); | ||
loadScript( '../build/mock/instances.mock.js' ); | ||
|
||
window.ENVIRONMENT = 'web'; | ||
|
||
window.androidContext = { | ||
//formName: 'ANC_Registration_24_5_12', | ||
//formName: 'EC_Registration_24_5_12', | ||
formName: getURLParameter( 'formName' ), | ||
|
||
getForm: function() { | ||
if(window.androidContext){ | ||
return window.androidContext.getForm(); | ||
} | ||
return mockForms[ this.formName ].html_form; | ||
}, | ||
|
||
getModel: function() { | ||
if(window.androidContext){ | ||
return window.androidContext.getModel(); | ||
} | ||
return mockForms[ this.formName ].xml_model; | ||
}, | ||
|
||
goBack: function() { | ||
if(window.androidContext){ | ||
window.androidContext.goBack(); | ||
} | ||
console.log( 'Wut?' ); | ||
} | ||
}; | ||
} ); | ||
|
||
// what is this? | ||
/* | ||
var logContext = { | ||
logError: function( e ) { | ||
console.log( e ); | ||
} | ||
}; | ||
*/ | ||
|
||
String.prototype.format = function( a, b, c ) { | ||
return a + b + c; | ||
}; | ||
|
||
function getURLParameter( name ) { | ||
return decodeURI( | ||
( RegExp( name + '=' + '(.+?)(&|$)' ).exec( location.search ) || [ , null ] )[ 1 ] | ||
); | ||
} | ||
|
||
//this happens automatically in main app for mobiles | ||
/* | ||
function setToMobileMode() { | ||
require( [ 'Modernizr' ], function( Modernizr ) { | ||
Modernizr.touch = true; | ||
var html = document.getElementsByTagName( 'html' )[ 0 ]; | ||
html.className = html.className.replace( /no-touch/, 'touch' ); | ||
} ); | ||
}; | ||
*/ | ||
String.prototype.format = function( a, b, c ) { | ||
return a + b + c; | ||
}; | ||
|
||
} else { | ||
window.ENVIROMENT = 'dristhi'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,48 @@ | ||
/*global mockForms2, mockInstances*/ | ||
|
||
define( [ 'ziggy/FormDataController', 'mockInstances' ], | ||
function( formDataController, mockInstances ) { | ||
// in Dristhi app, do not load mockForms | ||
if ( window.ENVIRONMENT === 'web' ) { | ||
define( 'ziggy/FormDataController', null ); | ||
} | ||
|
||
define( [ 'ziggy/FormDataController' ], function( ziggyController ) { | ||
|
||
/** | ||
* [FormDataController description] | ||
* @param {{instanceId: string, entityId: string}} params [description] | ||
* @constructor | ||
*/ | ||
function FormDataController( params ) { | ||
params = params || {}; | ||
|
||
/** | ||
* [FormDataController description] | ||
* @param {{instanceId: string, entityId: string}} params [description] | ||
* @constructor | ||
* Gets instance as JSON from Dristhi DB - Should this be asynchronous? | ||
* @return {?*} Form Data JSON object | ||
*/ | ||
function FormDataController( params ) { | ||
params = params || {}; | ||
var androidContext = window.androidContext; | ||
/** | ||
* Gets instance as JSON from Dristhi DB - Should this be asynchronous? | ||
* @return {?*} Form Data JSON object | ||
*/ | ||
this.get = function() { | ||
if ( !androidContext ) { | ||
return mockInstances[ params.instanceId ] || null; | ||
} | ||
return formDataController.get( params ) || null; | ||
}; | ||
this.get = function() { | ||
if ( window.ENVIRONMENT === 'web' ) { | ||
return mockInstances[ params.instanceId ] || null; | ||
} | ||
return ziggyController.get( params ) || null; | ||
}; | ||
|
||
/** | ||
* Passes instance as JSON to store in Dristhi DB - Should this be asynchronous? | ||
* @param {string} instanceId the new instanceID of the record | ||
* @param {*} data Form Data JSON object | ||
* @return {boolean} | ||
*/ | ||
this.save = function( instanceId, data ) { | ||
if ( !androidContext ) { | ||
console.log( 'saving...', data ); | ||
} else { | ||
formDataController.save( params, data ); | ||
androidContext.goBack(); | ||
} | ||
}; | ||
/** | ||
* Passes instance as JSON to store in Dristhi DB - Should this be asynchronous? | ||
* @param {string} instanceId the new instanceID of the record | ||
* @param {*} data Form Data JSON object | ||
* @return {boolean} | ||
*/ | ||
this.save = function( instanceId, data ) { | ||
if ( window.ENVIRONMENT === 'web' ) { | ||
console.log( 'saving...', data ); | ||
} else { | ||
ziggyController.save( params, data ); | ||
androidContext.goBack(); | ||
} | ||
}; | ||
|
||
this.remove = function( instanceId ) {}; | ||
} | ||
this.remove = function( instanceId ) {}; | ||
} | ||
|
||
return FormDataController; | ||
} ); | ||
return FormDataController; | ||
} ); |