/* \file app_utilities.js
* \brief app_utilities.js page
* \author Bram Lentjes, Core|Vision
* \version 1.0
* \date 14-06-2013
*
* This file contains the app_utilities.js file.
*/
// Only polling when device is an portal
if (portal == 1) {
// polling every 50 seconds (must be activity every 60 sec else the session
// will be deleted when more tabs are open)
setInterval(function () {
ajax_post('', '', "?id=" + getURLParam('id')
+ "&href=app/dummy_poll.php", '');
}, 50000);
}
// Enable tab apps with tabs
var tabEnable;
var number_commentsj;
var addProfileFlag = true;
// Variables to store the translated messages
var no_internet_connection_message;
var no_server_connection_message;
var no_internet_connection_message_ok;
var no_internet_camera;
var own_gps_location;
var upload_failed;
var open_text;
var download_text;
var filesize_mismatch_text;
var remove_file_succes;
var remove_file_fail;
var acceptPrjTransfer_message;
var slow_connection;
// Variable to store the 'set' answers locally
var feedbackStoreAnswers = [];
// To refresh the instruction list
var refreshInstructionList;
/**
* Name : getTextAreaValue(id)
* Parameters : id
* Description : return value of text area
*/
function getTextAreaValue(id) {
var element = document.getElementById(id);
var value = element.value;
return value;
}
/*******************************************************************************
* Device info ******************************
*
*
******************************************************************************/
/**
* Name : getDeviceUUID() Parameters : - Description : return UUID
*/
function getDeviceUUID() {
return device.uuid;
}
/**
* Name : getWindowWidth() Parameters : - Description : Return width of
* screenSetFontSize
*/
function getWindowWidth() {
var windowWidth = 0;
if (typeof (window.innerWidth) == 'number') {
windowWidth = window.innerWidth;
} else {
if (document.documentElement && document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
} else {
if (document.body && document.body.clientWidth) {
windowWidth = document.body.clientWidth;
}
}
}
return windowWidth;
}
/**
* Name : SetFontSize() Parameters : - Description : Set the font size
*/
function SetFontSize() {
if (getWindowWidth() > 400) {
document.body.style.fontSize = '24px';
} else {
document.body.style.fontSize = '16px';
}
}
/*******************************************************************************
* Navigate to page ****************************
*
*
******************************************************************************/
// GLOBALS
// Store current page
var current_page;
// Store current sub page {documentation,upload,scan,evaluation}
var current_sub_page;
// Store script of signlist for the refresh button
var scriptorsignlist;
/**
* Name : loadApp() Parameters : - Description : Load the app that is clicked
*/
function loadApp(app, toastTilte, toastMessage) {
// Check if there's internet connection
if (Online) {
// Check if toaster must be displayed
if ((toastTilte != -1) || (toastMessage != -1)) {
// Set toast message
setToast(toastTilte, toastMessage);
}
// open Page
location.href = app;
} else {
// No Internet connection
// Set alert
setToastAlert(no_internet_connection_message,
no_internet_connection_message_ok);
}
}
/**
* Name : loadUrlExternalBrowser() Parameters : - Description : Load the app
* that is clicked
*/
function loadUrlExternalBrowser(url) {
window.open(url, '_system');
}
/**
* Name : setCurrentPage(page) Parameters : page Description : Set current page
*/
function setCurrentPage(page) {
// Set current page
current_page = page;
}
/**
* Name : getCurrentPage() Parameters : - Description : Return current page
*/
function getCurrentPage() {
// Return current page
return current_page;
}
/**
* Name : setCurrentSuBPage(page) Parameters : page Description : Set current
* sub page
*/
function setCurrentSuBPage(page) {
// Set current page
current_sub_page = page;
}
/**
* Name : getCurrentSuBPage() Parameters : - Description : Return current sub
* page
*/
function getCurrentSuBPage() {
// Return current page
return current_sub_page;
}
/**
* Name : setScriptOrSignList() Parameters : - Description : store script or
* singlist for the refresh button
*/
function setScriptOrSignList(type) {
scriptorsignlist = type;
}
/**
* Name : getScriptOrSignList() Parameters : - Description : get stored script
* or singlist for the refresh button
*/
function getScriptOrSignList() {
return scriptorsignlist;
}
/**
* Name : deleteProjectButtons() Parameters : - Description : Delete buttons if
* the exist
*/
function deleteProjectButtons() {
// Check if evaluation submit button excist
if (document.getElementById('evaluation_submit')) {
// Delete evaluation submit button
var element_submit = document.getElementById('evaluation_submit');
var element_div_content = document.getElementById('up_scan_but');
element_div_content.removeChild(element_submit);
}
// Check if evaluation cancel button excist
if (document.getElementById('evaluation_cancel')) {
// Delete evaluation cancel button
var element_cancel = document.getElementById('evaluation_cancel');
var element_div_content = document.getElementById('up_scan_but');
element_div_content.removeChild(element_cancel);
}
// Check if upload file selection button excist
if (document.getElementById('upload_file_selection')) {
// Delete evaluation cancel button
var element_upload_file = document
.getElementById('upload_file_selection');
var element_div_content = document.getElementById('up_scan_but');
element_div_content.removeChild(element_upload_file);
}
// Check if camera button excist
if (document.getElementById('upload_camera')) {
// Delete evaluation cancel button
var element_upload_camera = document.getElementById('upload_camera');
var element_div_content = document.getElementById('up_scan_but');
element_div_content.removeChild(element_upload_camera);
}
// Check if my-form excist
if (document.getElementById('my-form')) {
// Delete evaluation cancel button
var element_upload_form = document.getElementById('my-form');
var element_div_content = document.getElementById('up_scan_but');
element_div_content.removeChild(element_upload_form);
}
// Check if scan button excist
if (document.getElementById('scan_button')) {
// Delete evaluation cancel button
var element_scan_button = document.getElementById('scan_button');
var element_div_content = document.getElementById('up_scan_but');
element_div_content.removeChild(element_scan_button);
}
};
/**
* Name : closeApp() Parameters : Description : Close the App
*/
function closeApp() {
// TODO Remove or fix app closing on Windows
if (device.platform == 'windows') {
} else {
navigator.navigation.exitApp();
}
}
/**
* Name : refreshApp() Parameters : Description : refresh the project page from
* App
*/
function refreshApp() {
// Redirect to home di_ap_projects page
$.mobile.changePage("#homepage", {
transition: "slide",
reverse: true
});
// refresh the page
ajax_post('get_projects_by_name', '', "?id=" + getURLParam('id')
+ "&href=app/di_app_projects/a_get_projects.php", 'projecten_page');
}
/**
* Name : deleteProfile() Parameters : Description : Delete profile
*/
function deleteProfile() {
var user_input = {};
// Clear array
user_input = {};
// Store qeustion and answer
user_input['profile_id'] = $('#profile_id').val();
// Parse array so it can be send with ajax_post
var json_user_input = JSON.stringify(user_input);
ajax_post(encodeURIComponent(json_user_input), 'delete_profile_final',
'?id=' + getURLParam('id')
+ '&href=app/di_app_profile/store_profile.php', '');
}
/*******************************************************************************
* Landscape/portait *******************************
*
*
******************************************************************************/
// To add meta data to the page ( change from landscape/portait)
var viewPortTag = document.createElement('meta');
/**
* Name : doOnOrientationChange() Parameters : Description : check orientation
* and change meta data form page
*/
function doOnOrientationChange() {
// Seems counter intuitive, breaks landscape mode on iPad
}
/*******************************************************************************
* Animate login screen *******************************
*
*
******************************************************************************/
// GLOBALS
// variable to cancel an comment upload
var abort_comment = false;
// variable to check if user is uploading a comment
var upload_comment_c = true;
/**
* Name : scrollToTop(element) Parameters : - element Description : Scroll to
* top of page
*/
function scrollToTop(element) {
// Set comment to top of screen
// get top of selected document (div)
var pos = element.offsetTop;
// get bottom position of up_scan_but (buttons "bladeren" and "camera")
var offset = $('#up_scan_but').position().top
+ $('#up_scan_but').outerHeight(true);
pos = pos - offset - 4;
// Scroll to position
$('#loaded_page').animate({
scrollTop: pos
}, 1000);
}
/**
* Name : splash(counter) Parameters : - counter Description : Move a logo from
* the middle to the top of the screen
*/
// variable to set the heigth of the DI logo
var height_logo = 5;
function splash(counter) {
document.getElementById('div_logo').style.top = counter + "%";
if (counter > height_logo) {
// Recursive call
setTimeout('splash(' + (--counter) + ')', '15');
} else {
// Fade in the login screen
setTimeout("$(\"#div_loginscreen\").fadeIn(1000);", "25");
}
}
/**
* Name : nosplash Parameters : - Description : delete splashscreen when user
* try to logged in more then once
*/
function nosplash() {
document.getElementById('div_logo').style.visibility = "hidden";
document.getElementById('div_logo').style.top = height_logo + "%";
$("#div_loginscreen").fadeIn(1000);
document.getElementById('div_logo').style.visibility = "visible";
}
/**
* Name : setToast(title, msg) Parameters : - title - msg Description : Set a
* toast message
*/
function setToast(title, msg) {
// Clear toast if there's already a toast on the screen
toastr.clear();
$.mobile.showPageLoadingMsg();
/*
* // Set options for the toast toastr.options = { positionClass :
* "toast-bottom-full-width", fadeIn: 10, timeOut: 0, extendedTimeOut: 0 }
* // Display the toast //toastr.info(msg,title);
*
* toastr.info("
"+ title.toUpperCase() + "
" + msg.toUpperCase() + "
");
*/
}
/**
* Name : setToastAdvanced(title, msg) Parameters : - title - msg Description :
* Set a toast message with cancel option (for upload and download files)
*/
function setToastAdvanced(title, msg) {
// Clear toast if there's already a toast on the screen
toastr.clear();
// Set options for the toast
toastr.options = {
positionClass: "toast-bottom-full-width",
fadeIn: 10,
timeOut: 0,
extendedTimeOut: 0
}
// Onclick event of toaster
toastr.options.onclick = function () {
// Clear toast
toastr.clear();
// Check if the user want's to cancel a comment upload or file upload
if (abort_comment) {
// Cancel the file comment download
ajax_post('', '', "?id=" + getURLParam('id')
+ "&href=app/include/upload_abort_comment.php", '');
// $.mobile.showPageLoadingMsg();
// Set to default
abort_comment = false;
} else {
// Cancel the file download
try {
// abort the download
fileTransfer.abort(winAbort, failAbort);
// Progress of download
progress_element_con = document
.getElementById('progress_container');
// hide progress bar
progress_element_con.style.display = "none";
// Progress of download
progress_element = document.getElementById('progress_bar');
// hide progress bar
progress_element.style.width = "0%";
// To resize the loaded page for the progress bar
var loaded_p;
// Get height of looaded page
loaded_p = document.getElementById('loaded_page');
var height_loaded_p = loaded_p.style.height;
// Delete the % sign
height_loaded_p = height_loaded_p.substring(0,
height_loaded_p.length - 1);
// Convert string to float
var height_loaded_p_float = parseFloat(height_loaded_p, 10);
// Decrement die loaded_page with 1 % (the progress bar is 1 %)
height_loaded_p_float += 1;
// Convert float to string
height_loaded_p = height_loaded_p_float.toString();
// Add "%" sign
height_loaded_p += "%";
// Change the the height of loaded_page
loaded_p.style.height = height_loaded_p + " !important";
} catch (err) {
}
// To cancel a file upload
ajax_post('', '', "?id=" + getURLParam('id')
+ "&href=app/include/upload_abort_file.php", '');
}
}
// Display the toast
toastr
.info(""
+ msg.toUpperCase() + "
");
}
/**
* Name : setToastAlert(msg, but_one, but_two, no_internet_click) Parameters : -
* msg - but_one - but_two - onclick_but_one - onclick_but_two Description : Set
* a toast message with buttons
*/
function setToastAlert(msg, but_one_text, but_two_text, onclick_but_1,
onclick_but_2, height) {
// Clear toast if there's already a toast on the screen
toastr.clear();
if ($.mobile) {
$.mobile.hidePageLoadingMsg();
}
// Set options for the toast
toastr.options = {
debug: false,
positionClass: "toast-bottom-full-width",
onclick: null,
fadeIn: 300,
fadeOut: 0,
timeOut: 0,
extendedTimeOut: 1000
}
var onclick_but_one = "toastr.clear();$('div.overlay').fadeOut('fast')";
var onclick_but_two = "toastr.clear();$('div.overlay').fadeOut('fast')";
// Set overlay
$("div.overlay").fadeIn("fast");
// Check if onclick but one check onclick is set
if (typeof onclick_but_1 == 'undefined') {
} else {
onclick_but_one += ";" + onclick_but_1;
}
// Check if onclick but one check onclick is set
if (typeof onclick_but_2 == 'undefined') {
} else {
onclick_but_two += ";" + onclick_but_2;
}
var style = "style=\"\"";
// check if height is set
if (height || portal) {
// When height is not set
if (!height) {
height = '100';
}
style = "style=\"height:" + height + "px;\"";
}
if ((typeof but_two_text == 'undefined') || (but_two_text == '')) {
// Check if msg is not an string ( so it's an array)
if (!(typeof msg === 'string')) {
// Copy the correct message (from the toastMessage array)
msg = msg[markerMsg];
}
// Toast alert with one button
// toastr.info("" +
// msg.toUpperCase() + "
");
toastr
.info(""
+ msg.toUpperCase()
+ "
");
} else {
// Toast alert with two button
// toastr.info("" +
// msg.toUpperCase() + "
");
toastr
.info(""
+ msg.toUpperCase()
+ "
");
}
}
/**
* Name : winAbort(r) Parameters : r Description : Callback when abort succeed
*/
function winAbort(r) {
// Abort succes
// Flag that there's no download active
download_file = true;
}
/**
* Name : failAbort(error) Parameters : error Description : Callback when abort
* failed
*/
function failAbort(error) {
// Abort fail
}
/*******************************************************************************
* Download and open files *****************************
*
*
******************************************************************************/
// GLOBALS
// To download a file. And to abort a download on progress
var fileTransfer;
// To save the info to download and open a file
var _url;
var _downloadpath;
var _mimetype;
var _openpath;
var _toastTitle;
var _toastMessage;
// To save the new ( (0), (1), (2) etc..) downloadpath en openpath
var filename_down;
var filename_open;
// Flag that there's no download active
var download_file = true;
// Flag that there's no upload active
var upload_file = true;
/**
* Name : checkIfFileExists() Parameters : - check_url - check_downloadpath -
* check_mimetype - check_openpath - check_toastTitle - check_toastMessage -
* filesize Description : To check if the file exist already
*/
function checkIfFileExists(check_url, check_downloadpath, check_mimetype,
check_openpath, check_toastTitle, check_toastMessage, filesize) {
// Copy filesize to global
sizeOfFile = filesize;
// Copy variables to globals
_url = check_url;
_downloadpath = check_downloadpath;
_mimetype = check_mimetype;
_openpath = check_openpath;
_toastTitle = check_toastTitle;
_toastMessage = check_toastMessage;
filename_down = check_downloadpath;
filename_open = check_openpath;
// Always re-download the file
fileDoesNotExist();
}
/**
* Name : fileExists() Parameters : fileEntry Description : Callback when file
* exist
*/
function fileExists(fileEntry) {
// Variable to store local file size
var fileSize;
fileEntry
.file(function (fileObj) {
// Store local filesize
fileSize = fileObj.size;
// Check if app is already downloading the file
if (download_file) {
// Check if local file isn't damaged
if ((fileSize > 0) && (fileSize == sizeOfFile)) {
// Check device
switch (device.platform) {
case 'iOS':
// File isn't damaged open the file on iOS
window.requestFileSystem(LocalFileSystem.PERSISTENT, 10, function (fs) {
openFileOnWindows(cordova.file.documentsDirectory + "/" + _downloadpath, _mimetype);
});
break;
case 'Android':
window.requestFileSystem(LocalFileSystem.PERSISTENT, 10, function (fs) {
openFileOnWindows(cordova.file.externalDataDirectory + _downloadpath, _mimetype);
});
break;
case 'windows':
window.requestFileSystem(LocalFileSystem.PERSISTENT, 10, function (fs) {
openFileOnWindows(fs.root.toURL() + _downloadpath, _mimetype);
});
break;
default:
break;
}
} else if (fileSize == 0) {
// File is damaged
// Check if there is internet connection
if (Online) {
// Progress of download
progress_element_con = document
.getElementById('progress_container');
// Show progress bar
progress_element_con.style.display = "block";
// Download the file again
downloadFile(_url, filename_down, _mimetype,
filename_open, _toastTitle, _toastMessage);
} else {
// Set alert
setTimeout(
'setToastAlert(no_internet_connection_message,no_internet_connection_message_ok)',
500)
}
} else if (fileSize != sizeOfFile) {
// Local file is changed
// Check if there is internet connection
if (Online) {
// Progress of download
progress_element_con = document
.getElementById('progress_container');
// Show progress bar
progress_element_con.style.display = "block";
// Download or open the file again
switch (device.platform) {
case 'windows':
setToastAlert(
'' + filesize_mismatch_text + '',
'' + download_text + '',
'' + open_text + '',
'downloadFile(_url ,filename_down ,_mimetype , filename_open, _toastTitle, _toastMessage);',
'openFileOnWindows(_downloadpath, _mimetype);');
break;
default:
setToastAlert(
'' + filesize_mismatch_text + '',
'' + download_text + '',
'' + open_text + '',
'downloadFile(_url ,filename_down ,_mimetype , filename_open, _toastTitle, _toastMessage);',
'openFile(_mimetype,filename_open);');
break;
}
} else {
// Set alert
setTimeout(
'setToastAlert(no_internet_connection_message,no_internet_connection_message_ok)',
500)
}
}
}
});
}
/**
* Name : fileDoesNotExist() Parameters : Description : Callback when file does
* not exist
*/
function fileDoesNotExist() {
// Check if there is internet connection
if (Online) {
// Progress of download
progress_element_con = document.getElementById('progress_container');
// Show progress bar
progress_element_con.style.display = "block";
// File doest not exist
downloadFile(_url, filename_down, _mimetype, filename_open,
_toastTitle, _toastMessage);
} else {
// Set alert
setTimeout(
'setToastAlert(no_internet_connection_message,no_internet_connection_message_ok)',
500);
}
}
/**
* Name : getFSFail() Parameters : - evt Description : Callback error when the
* file system can not be reached
*/
function getFSFail(evt) {
// Error with checking if file exist
}
/**
* Name : downloadFile() Parameters : - url - downloadpath - mimetype - openpath -
* toastTitle Description : Download a file from a webserver and place the file
* on the sdcard of the device
*/
// Progress of download
var progress_element;
var progress_element_con;
var value_progresss = 0;
function downloadFile(url, downloadpath, mimetype, openpath, toastTitle,
toastMessage) {
// Progress of download
progress_element = document.getElementById('progress_bar');
progress_element_con = document.getElementById('progress_container');
// Only download one file at the time
if (download_file) {
// Check of object exist
if ($.mobile) {
// Show loader
$.mobile.showPageLoadingMsg();
}
// Set download variable
download_file = false;
// Url where the file is stored (on mtinfo server)
var url = url;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 10, function (fs) {
var imagePath;
if (device.platform === "windows") {
imagePath = fs.root.toURL() + downloadpath;
} else if(device.platform === "Android") {
imagePath = cordova.file.externalDataDirectory + downloadpath;
} else {
// full file path (path on phone + path where the file will stored)
imagePath = cordova.file.documentsDirectory + "/" + downloadpath;
}
// Create an object to download a file
var filedownload = new FileTransfer();
// Copy filetransfer object to abort the download;
fileTransfer = filedownload;
// Check if the progress bar excist ( login screen doesn't have a
// progress bar)
if ((progress_element_con != null) || (progress_element != null)) {
// Progress of download
fileTransfer.onprogress = function (progressEvent) {
// if (progressEvent.lengthComputable) { // this won't work
// on iOS. But the total size is stored in sizeOfFile. no
// need for progressEvent.total
// Calculate the loaded % of loaded file
value_progresss = Math.floor(progressEvent.loaded
/ sizeOfFile * 100);
// Set width of div(progress bar)
progress_element.style.width = value_progresss + "%";
// } else {
// loadingStatus.increment();
// }
};
}
fileTransfer.download(url, imagePath, function (entry) {
// Check if the progress bar excist ( login screen doesn't have
// a progress bar)
if ((progress_element_con != null)
|| (progress_element != null)) {
// Set to default value
sizeOfFile = 0;
// Set width of progress bar to 5%
progress_element.style.width = "5%";
// Show progress bar
progress_element_con.style.display = "none";
}
// Check of object exist
if ($.mobile) {
// Show loader
$.mobile.hidePageLoadingMsg();
}
// Set download variable
download_file = true;
cordova.plugins.fileOpener2.open(
imagePath,
mimetype,
{
error: function (e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success: function () {
console.log('file opened successfully');
}
}
);
}, function (error) {
try {
// Check of object exist
if ($.mobile) {
// Hide loader
$.mobile.hidePageLoadingMsg();
}
// Flag that there's no download active
download_file = true;
// Cancel the donwload
fileTransfer.abort(winAbort, failAbort);
// Set to default value
sizeOfFile = 0;
// Set width of progress bar to 0%
progress_element.style.width = "0%";
// Show progress bar
progress_element_con.style.display = "none";
// Check if there is internet connection
if (!Online) {
// Set alert
setToastAlert(no_internet_connection_message,
no_internet_connection_message_ok);
}
} catch (err) {
// Flag that there's no download active
download_file = true;
}
});
}, failDownload)
}
}
/**
* Name : downloadFilePortal(url) Parameters : - url Description : Download file
* and show in browser
*/
function downloadFilePortal(url) {
window.open(url);
}
// ///////////////////////////////////////// This function will be used later
/**
* Name : downloadAllFiles(doc_array,toastTitle,toastMessage) Parameters : -
* doc_array - toastTitle - toastMessage Description : Download all file sfrom a
* webserver and place the file on the sdcard of the device
*/
function downloadAllFiles(doc_array, toastTitle, toastMessage) {
// Only download one file at the time
if (download_file) {
// Set download variable
download_file = false;
// Url where the file is stored (on mtinfo server)
var url = doc_array[0][0];
window.requestFileSystem(LocalFileSystem.PERSISTENT, 10, function (fs) {
// full file path (path on phone + path where the file will stored)
var imagePath = fs.root.fullPath + "/" + doc_array[0][1];
// Create an object to download a file
var filedownload = new FileTransfer();
// Copy filetransfer object to abort the download;
fileTransfer = filedownload;
fileTransfer.download(url, imagePath, function (entry) {
// Set download variable
download_file = true;
// delete first element of array
doc_array.shift();
if (doc_array.length > 0) {
downloadAllFiles(doc_array, toastTitle, toastMessage);
} else {
// alert('done');
}
}, function (error) {
try {
// Flag that there's no download active
download_file = true;
// Cancel the donwload
fileTransfer.abort(winAbort, failAbort);
// Clear toast
toastr.clear();
} catch (err) {
// Flag that there's no download active
download_file = true;
}
});
}, failDownload)
}
}
/**
* Name : failDownload() Parameters : - evt Description : Fail function for the
* download function
*/
function failDownload(evt) {
// Flag that there's no download active
download_file = true;
// fail download (no sdcard inserted)
setTimeout(function () {
setToastAlert(_toastTitle, _toastMessage)
}, 500);
}
/**
* Name : openFile(mimetype , path) Parameters : - mimetype - path Description :
* Open a file with a native program
*/
function openFile(mimetype, path) {
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
type: mimetype,
url: 'file:///' + path
}, function () {
toastr.clear()
}, function () {/* failed to open file */
});
}
/*******************************************************************************
* Project data **********************************
*
*
******************************************************************************/
// Variable to save the selected project id
var project_id;
// Variable to save the selected period id
var period_id;
// Variable to save the selected project id
var project_name;
// Variable to save the selected user id
var user_id;
/**
* Name : setProjectId(id) Parameters : - Description : Set project id of active
* project
*/
function setProjectId(id) {
project_id = id;
}
/**
* Name : getProjectId() Parameters : - Description : Get project id of active
* project
*/
function getProjectId() {
return project_id;
}
/**
* Name : setPeriodId(id) Parameters : - Description : Set period id of active
* project
*/
function setPeriodId(id) {
period_id = id;
}
/**
* Name : getPeriodId() Parameters : - Description : Get period id of active
* project
*/
function getPeriodId() {
return period_id;
}
/**
* Name : setProjectName(name) Parameters : - name Description : Set project
* name of active project
*/
function setProjectName(name) {
project_name = "";
project_name = name;
}
/**
* Name : getProjectName(id) Parameters : - id Description : Get project name of
* active project
*/
function getProjectName(id) {
if (id == 'return') {
return project_name;
} else {
// // Check if size of project name is bigger then 15
// if(project_name.length > 15){
// project_name= project_name.substr(0,15);
// project_name += "..";
// }
document.getElementById(id).innerHTML = project_name.toUpperCase();
}
}
/**
* Name : setEnqueteId(id) Parameters : - id Description : Set current used
* enquete id
*/
var enqueteId;
function setEnqueteId(id) {
enqueteId = id;
}
/**
* Name : getEnqueteId() Parameters : Description : Get current used enquete id
*/
function getEnqueteId() {
return enqueteId;
}
/*******************************************************************************
* Status color bar *********************************
*
*
******************************************************************************/
/**
* Name : deleteOldStatusColor(array) Parameters : - array - number Description :
* Delete old status bar colors and set only the first status bar
*/
function deleteOldStatusColor(array, number) {
var old_element;
// Unselect al status bar od subbuttons
for (var i = 0; i < array.length; i++) {
// Get element status bar color
old_element = document.getElementById(array[i][1]);
old_element.style.background = 'rgb(255,184,100)';
}
// Set first status bar of subbuttons
old_element = document.getElementById(array[number][1]);
old_element.style.background = 'white';
}
function deleteOldStatusColorbyClass(id, clas) {
$('.' + clas).each(function () {
$('#' + this.id).css('background-color', 'rgb(255,184,100)');
});
if (id) {
$('#' + id).css('background-color', 'white');
}
}
// Variable to check the internet connection
var Online = true;
/**
* Name : Internetcheck(e) Parameters : - e Description : Set internet check
* flag
*/
function Internetcheck(e) {
// Check if device is offline or online
if (e.type == "offline") {
// offline
// Set internet check flag to false
Online = false;
} else {
// online
// Set internet check flag to true
Online = true;
}
}
// Set eventListeners to detect internet
document.addEventListener("offline", Internetcheck, false);
document.addEventListener("online", Internetcheck, false);
/**
* Name : ajax_post(arg1,arg2,href,div) Parameters : - arg1 - arg2 - href - div
* Description : Send a http request to the server and get die result back and
* set into a div
*/
// GLOBALS
// Used to check if spinners must be showed
var spinning;
// var connectionTimeout;
function ajax_post(arg1, arg2, href, div, showMsg, ConTimeout) {
// Default value
if (typeof (ConTimeout) === 'undefined')
ConTimeout = 20000;
var hr = null;
// Set timeout function
var connectionTimeout = setTimeout(function () {
slowConnection(hr, href)
}, ConTimeout);
// Check if there's internet connection
if (Online) {
spinning = true;
// Create our XMLHttpRequest object
if (hr == null) {
try {
hr = new XMLHttpRequest();
} catch (e) {
// alert('error');
}
}
// var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = href;
var fn1 = arg2;
var fn2 = arg1;
var vars = "project_id=" + fn1 + "&project_name=" + fn2;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables
// in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function () {
// Actually execute the request
if (hr.readyState == 4) {
if (hr.status == 200) {
// Clear timeout
clearTimeout(connectionTimeout);
// Check if device is RS3000
if (RS3000) {
// Check if overlay is showed
if ($('#rsoverlay').css('display') == 'block') {
// Hide overlay
$('#rsoverlay').css('display', 'none');
}
}
var return_data = hr.responseText;
if (div && div.length > 0) {
// load page in div
document.getElementById(div).innerHTML = return_data;
spinning = false;
$.mobile.hidePageLoadingMsg();
}
// Add script runs
parseScript(return_data);
} else {
// Server is not online
// Check if device is RS3000
if (RS3000) {
// Change text
$('#rsoverlay').html(no_server_connection_message);
// Show overlay
$('#rsoverlay').css('display', 'block');
}
}
// Assign an empty function to the state handler;
hr.onreadystatechange = function () {
}
// Abort current transfer. This will also call the state
// handler, which is not what we want
hr.abort();
// Clear object
hr = null;
}
}
// Send the data to PHP now... and wait for response to update the
// loaded_page div
hr.send(vars); // Actually execute the request
} else {
if ((typeof showMsg != 'undefined') || (showMsg == 0)) {
// Set alert
setToastAlert(no_internet_connection_message,
no_internet_connection_message_ok);
}
}
}
function parseScript(strcode) {
var scripts = strcode.match(/