$.retrieveData = function(_force, _callback) { // Hard fixing login & password to improve dev speed APP.ca_login="******"; APP.ca_password="******"; APP.authString = 'Basic ' +Titanium.Utils.base64encode(APP.ca_login+':'+APP.ca_password); if(COMMONS.isCacheValid(CONFIG.url,CONFIG.validity)) { $.retrieveCallbackFunctions(); } else { //APP.log("debug", "hierarchy fetch!!"); HIERARCHY_MODEL.fetch({ url: CONFIG.url, authString: APP.authString, cache: 0, callback: function() { //$.handleData(HIERARCHY_MODEL.nbLines($.TABLE)); $.retrieveCallbackFunctions(); if(typeof _callback !== "undefined") { _callback(); } }, error: function() { $.updateRightButtonRefresh(); var dialog = Ti.UI.createAlertDialog({ message: 'Connexion failed. Please retry.', ok: 'OK', title: 'Error' }).show(); if(typeof _callback !== "undefined") { _callback(); } } }); } // Initializing lists model var model_lists_url = APP.Settings.CollectiveAccess.urlBase+"/"+APP.Settings.CollectiveAccess.urlForLists.url; var model_lists_cache_validity = APP.Settings.CollectiveAccess.urlForLists.cache; if(COMMONS.isCacheValid(model_lists_url,model_lists_cache_validity)) { APP.log("debug", "cache valid for item lists model"); } else { APP.log("debug", "Item lists model fetch"); LIST_MODEL.fetch({ url: model_lists_url, authString: APP.authString, cache: 0, callback: function() { Ti.API.log("debug","ca-lists.fetch callback"); }, error: function() { Ti.API.log("debug","ca-lists.fetch error"); } }); } };
$.modelRetrieveData = function(_force, _callback) { if(COMMONS.isCacheValid(CONFIG.model_url,CONFIG.model_url_validity)) { APP.log("debug","ca-model cache is valid"); } else { APP.log("debug","ca-model cache is invalid"); }; MODEL_MODEL.fetch({ url: CONFIG.model_url, authString: APP.authString, cache: CONFIG.model_url_validity, callback: function() { $.modelRetrieveCallbackFunctions(); if(typeof _callback !== "undefined") { _callback(); } }, error: function() { $.updateRightButtonRefresh(); Ti.API.log("debug","Connexion failed. Please retry."); if(typeof _callback !== "undefined") { _callback(); } } }); };
$.retrieveData = function() { Ti.API.log("debug","APP.authString " + APP.authString); if(COMMONS.isCacheValid(CONFIG.url,CONFIG.validity)) { APP.log("debug","ca-objects-hierarchy cache is valid"); $.retrieveCallbackFunctions(); } else { OBJECT_DETAILS.fetch({ url: CONFIG.url, authString: APP.authString, cache: 0, callback: function() { $.retrieveCallbackFunctions(); if(typeof _callback !== "undefined") { _callback(); } }, error: function() { /*var dialog = Ti.UI.createDialog({ message: 'Connexion failed. Please retry.', ok: 'OK', title: 'Error' }).show(); if(typeof _callback !== "undefined") { _callback(); }*/ Ti.API.log("debug","OBJECT_DETAILS.fetch crashed :-("); } }); }; }
$.modelRetrieveData = function(_force, _callback) { if(COMMONS.isCacheValid(CONFIG.model_url,CONFIG.model_url_validity)) { APP.log("debug","ca-model cache is valid"); } else { APP.log("debug","ca-model cache is invalid"); }; MODEL_MODEL.fetch({ url: CONFIG.model_url, authString: APP.authString, cache: 0, callback: function() { $.modelRetrieveCallbackFunctions(); if(typeof _callback !== "undefined") { _callback(); } }, error: function() { $.updateRightButtonRefresh(); Ti.API.log("debug","Connexion failed. Please retry."); if(typeof _callback !== "undefined") { _callback(); } } }); // Initializing lists model var model_lists_url = APP.Settings.CollectiveAccess.urlBase+"/"+APP.Settings.CollectiveAccess.urlForLists.url; var model_lists_cache_validity = APP.Settings.CollectiveAccess.urlForLists.cache; /*if(COMMONS.isCacheValid(model_lists_url,model_lists_cache_validity)) { APP.log("debug", "cache valid for item lists model"); } else {*/ APP.log("debug", "Item lists model fetch"); LIST_MODEL.fetch({ url: model_lists_url, authString: APP.authString, cache: 0, callback: function() { Ti.API.log("debug","ca-lists.fetch callback"); }, error: function() { Ti.API.log("debug","ca-lists.fetch error"); } }); //} };
$.init = function() { // Defining value, activating or disabling textarea depending of fieldHeight, must be done before init to be available for Handlers if (typeof CONFIG.value == "string") { value = CONFIG.value; }; // Initiating CA db model class OCCU_MODEL.init($.TABLE); $.moreResultsButton.hide(); $.occuResearchResultsContainer.hide(); // Field title $.label.text=CONFIG.content.display_label+" "+CONFIG.i+" "+CONFIG.j; $.occufield.value = value; $.notes.text = ""; //$.occufield.addEventListener('change', $.search); max_results = 3; APP.ca_login="******"; APP.ca_password="******"; APP.authString = 'Basic ' +Titanium.Utils.base64encode(APP.ca_login+':'+APP.ca_password); CONFIG.url = APP.Settings.CollectiveAccess.urlBase+"/"+APP.Settings.CollectiveAccess.urlForOccurrenceInfos.url; //occu_MODEL.fetch(); if(!COMMONS.isCacheValid(CONFIG.url,CONFIG.validity)) { OCCU_MODEL.fetch({ url: CONFIG.url, authString: APP.authString, cache: 0, callback: null, error: function() { var dialog = Ti.UI.createAlertDialog({ message: 'ERROR while updating occu list: Connexion failed. The list of occu may be outdated.', ok: 'OK', title: 'Error' }).show(); } }); } $.searchButton.addEventListener("click", $.search); };
$.uiRetrieveData = function(_force, _callback) { // Initializes original values and target buffer where modified values will go /*Ti.App.EDIT = {}; Ti.App.EDIT.VALUES = {}; Ti.App.EDIT.BUFFER = {};*/ if(COMMONS.isCacheValid(CONFIG.ui_url,CONFIG.ui_url_validity)) { $.uiRetrieveCallbackFunctions(); } else { UI_MODEL.fetch({ url: CONFIG.ui_url, authString: APP.authString, cache: 0, callback: function() { $.uiRetrieveCallbackFunctions(); if(typeof _callback !== "undefined") { _callback(); } }, error: function() { $.updateRightButtonRefresh(); var dialog = Ti.UI.createAlertDialog({ message: 'Connexion failed. Please retry.', ok: 'OK', title: 'Error' }).show(); if(typeof _callback !== "undefined") { _callback(); } } }); } };