ED = {}; Views = {}; Models = {}; var _rootApplication; edApplication = function(oInit) { if (typeof edContext() === "undefined") { console.error("edContext has not been initialized. Do it by calling edContext(initObject)"); } else { if (typeof _rootApplication === "undefined") { this.initialize(oInit); } } return _rootApplication; }; window.edApplication = edApplication; edApplication.prototype.setDefaultParameters = function() { this.path = "./"; this.skin = "default"; this.softwareid = Utils.getParameterByName("SfwID"); this.edTagsList = {}; //enabling cors support $.support.cors = true; }; edApplication.prototype.initialize = function(oInit) { $(document).trigger("edApplication_preInitialize"); _rootApplication = this; this.setDefaultParameters(); if (typeof oInit !== "undefined") { for (var attrname in oInit) { _rootApplication[attrname] = oInit[attrname]; } } $(document).one("labels_loaded", this.loadJS); $(document).one("js_loaded", this.normalizeEdDescriptor); $(document).one("js_loaded", this.loadCSS); $(document).one("js_loaded", function() { edManager.edViews = new Backbone.Collection(); edManager.edGroups = new Backbone.Collection(); }); $(document).one("js_loaded", function() { edContext().loadLocaleDependencies(); }); $(document).one("css_loaded", this.loadTemplates); $(document).one("templates_loaded", function(){$(document).trigger("edApplication_onInitialize");}); Utils.loadGoogleAPIsLoader(); //this.loadJS(); this.loadLabels(); return _rootApplication; }; edApplication.prototype.getImagePath = function() { return this.path + "skins/" + this.skin + "/images/"; }; edApplication.prototype.getCssPath = function() { return this.path + "skins/" + this.skin + "/css/"; }; edApplication.prototype.check = function() { if (typeof _rootApplication === "undefined") { console.error("edApplication has not been initialized. Do it by calling TODO"); return false; } return true; }; edApplication.prototype.get = function(sPropertyName) { if (!this.check()) return undefined; return _rootApplication[sPropertyName]; }; edApplication.prototype.normalizeEdDescriptor = function() { var that = edApplication(); for (var attrname in ED.Descriptor) { if (ED.Descriptor[attrname].addView) { ED.Descriptor[attrname].addView = ED.Descriptor[ED.Descriptor[attrname].addView]; } var isList = (attrname.substring(attrname.length-4, attrname.length) == "List"); if (isList) { if (ED.Descriptor[attrname].viewItem) { ED.Descriptor[attrname].viewItem = ED.Descriptor[ED.Descriptor[attrname].viewItem]; } else { var viewItemName = attrname.substring(0, attrname.length-4); ED.Descriptor[attrname].viewItem = ED.Descriptor[viewItemName]; } } else { if (ED.Descriptor[attrname].viewList) { ED.Descriptor[attrname].viewList = ED.Descriptor[ED.Descriptor[attrname].viewList]; } else { var viewListName = attrname + "List"; ED.Descriptor[attrname].viewList = ED.Descriptor[viewListName]; } } if (ED.Descriptor[attrname].edTag) { that.edTagsList[ED.Descriptor[attrname].edTag] = ED.Descriptor[attrname]; } } }; edApplication.prototype.loadLabels = function() { //before loading templates, we need to load labels.jsp that contains all messages needed by templates ans views var url = this.path + 'js/edeal/config/labels.jsp'; $.ajax({ url: url, dataType: "json", timeout: 20000, cache: true }) .success(function(data) { edApplication().labels = data; /*console.log(data); console.log("labels loading complete"); console.log(edApplication().labels);*/ $(document).trigger("labels_loaded"); }) .error(function(jqXHR, textStatus, errorThrown) { console.error("unable to load js/edeal/config/labels.jsp."); $(document).trigger("labels_loaded"); }); }; edApplication.prototype.loadJS = function() { var that = edApplication(); include(that.path + "js/edeal/config/jsDependencies.js", function(){ that.loadAllJS(); }); }; edApplication.prototype.loadAllJS = function() { var dependencies = ED.JSDependencies; var that = edApplication(); var includeJS = function(files, subDependencies) { var filesToInclude = new Array(); for (var i=0;i 0) { include(filesToInclude, function(){ if (subDependencies) { var callbackLoadSub = $.Callbacks("once"); callbackLoadSub.add( function(){ includeJS(subDependencies.files, subDependencies.subDependencies); }); callbackLoadSub.fireWith( this ); } else { $(document).trigger("js_loaded"); } }); } }; includeJS(dependencies.files, dependencies.subDependencies); }; edApplication.prototype.loadCSS = function() { var that = edApplication(); include(that.path + "js/edeal/config/cssDependencies.js", function(){ that.loadAllCSS(); }); }; edApplication.prototype.loadAllCSS = function() { var dependencies = ED.CSSDependencies; var files; for (var filesgroup in dependencies) { files = dependencies[filesgroup]; for (var i=0;i"); } } $(document).trigger("css_loaded"); }; edApplication.prototype.loadTemplates = function() { var that = edApplication(); //load all the templates needed by views var templateNamesArray = new Array(); templateNamesArray.push("nowLoading.html"); for (var attrname in ED.Descriptor) { //templates var templateList = ED.Descriptor[attrname].templates; for (var templatename in templateList) { if (!templateNamesArray[templateList[templatename]]) { templateNamesArray.push(templateList[templatename]); } } } that.templatesNames = templateNamesArray; that.templates= {}; var loadTemplate = function(index) { var tplname = that.templatesNames[index]; if (!that.templates[tplname]) { //console.log("loading " + tplname); var url = that.path + 'skins/' + edApplication().skin + '/templates/' + tplname; $.ajax({ url: url, dataType: "html", timeout: 20000, cache: true }) .success(function(data) { //console.log(data); that.templates[tplname] = data; index++; if (index < that.templatesNames.length) { loadTemplate(index); } else { $(document).trigger("templates_loaded"); } }) .error(function(jqXHR, textStatus, errorThrown) { console.error(tplname + " is not defined. You must create this template, or correct your edDescriptor."); console.error("jqXHR object :"); console.error(jqXHR); console.error("textStatus :"); console.error(textStatus); console.error("errorThrown : "); console.error(errorThrown); index++; if (index < that.templatesNames.length) { loadTemplate(index); } else { $(document).trigger("templates_loaded"); } }); } else { //console.log("already loaded !"); index++; if (index < that.templatesNames.length) { loadTemplate(index); } else { $(document).trigger("templates_loaded"); } } }; loadTemplate(0); }; edApplication.prototype.getTemplateByName = function(sTemplateName) { return this.templates[sTemplateName]; }; edApplication.prototype.getViewByID = function(sID) { console.log("edApplication().getViewByID() is deprecated, please call edManager.getViewByID() instead"); return edManager.getViewByID(sID); }; edApplication.prototype.getGroupByID = function(sID) { console.log("edApplication().getGroupByID() is deprecated, please call edManager.getGroupByID() instead"); return edManager.getGroupByID(sID); };