=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js 2014-10-14 11:49:12 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js 2014-10-14 15:40:58 +0000 @@ -7226,177 +7226,187 @@ success: function(r) { init.contextPath = Ext.decode(r.responseText).activities.dhis.href; - // user-account + // system info Ext.Ajax.request({ - url: init.contextPath + '/api/me/user-account.json', + url: init.contextPath + '/api/system/info.json', success: function(r) { - init.userAccount = Ext.decode(r.responseText); + init.systemInfo = Ext.decode(r.responseText); + init.contextPath = init.systemInfo.contextPath || init.contextPath; - // system info + // date, calendar Ext.Ajax.request({ - url: init.contextPath + '/api/system/info.json', + url: init.contextPath + '/api/systemSettings.json?key=keyCalendar&key=keyDateFormat', success: function(r) { - init.systemInfo = Ext.decode(r.responseText); - - // init - var defaultKeyUiLocale = 'en', - defaultKeyAnalysisDisplayProperty = 'name', - namePropertyUrl, - contextPath, - keyUiLocale, - dateFormat; - - init.contextPath = init.systemInfo.contextPath || init.contextPath; - init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; - init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; - init.systemInfo.dateFormat = init.systemInfo.dateFormat || 'yyyy-mm-dd'; - - contextPath = init.contextPath; - keyUiLocale = init.userAccount.settings.keyUiLocale; - keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; - namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; - dateFormat = init.systemInfo.dateFormat; - - init.namePropertyUrl = namePropertyUrl; - - // calendar - (function() { - var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', - defaultCalendarId = 'gregorian', - calendarIdMap = {'iso8601': defaultCalendarId}, - calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, - calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], - calendarScriptUrl, - createGenerator; - - // calendar - createGenerator = function() { - init.calendar = $.calendars.instance(calendarId); - init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); - }; - - if (Ext.Array.contains(calendarIds, calendarId)) { - calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; - - Ext.Loader.injectScriptElement(calendarScriptUrl, function() { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - }); - } - else { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - } - }()); - - // i18n - requests.push({ - url: 'i18n/' + keyUiLocale + '.properties', + var systemSettings = Ext.decode(r.responseText); + init.systemInfo.dateFormat = Ext.isString(systemSettings.keyDateFormat) ? systemSettings.keyDateFormat.toLowerCase() : 'yyyy-mm-dd'; + init.systemInfo.calendar = systemSettings.keyCalendar; + + // user-account + Ext.Ajax.request({ + url: init.contextPath + '/api/me/user-account.json', success: function(r) { - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.properties', - success: function(r) { - Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); - }, - callback: fn - }) - } - else { - fn(); - } - }, - failure: function() { - var onFailure = function() { - alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); - }; - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.json', - success: function(r) { - console.log('No translations found for system locale (' + keyUiLocale + ').'); - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - }, - failure: function() { + init.userAccount = Ext.decode(r.responseText); + + // init + var defaultKeyUiLocale = 'en', + defaultKeyAnalysisDisplayProperty = 'name', + namePropertyUrl, + contextPath, + keyUiLocale, + dateFormat; + + init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; + init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; + + // local vars + contextPath = init.contextPath; + keyUiLocale = init.userAccount.settings.keyUiLocale; + keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; + namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; + dateFormat = init.systemInfo.dateFormat; + + init.namePropertyUrl = namePropertyUrl; + + // calendar + (function() { + var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', + defaultCalendarId = 'gregorian', + calendarIdMap = {'iso8601': defaultCalendarId}, + calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, + calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], + calendarScriptUrl, + createGenerator; + + // calendar + createGenerator = function() { + init.calendar = $.calendars.instance(calendarId); + init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); + }; + + if (Ext.Array.contains(calendarIds, calendarId)) { + calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; + + Ext.Loader.injectScriptElement(calendarScriptUrl, function() { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + }); + } + else { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + } + }()); + + // i18n + requests.push({ + url: 'i18n/' + keyUiLocale + '.properties', + success: function(r) { + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.properties', + success: function(r) { + Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); + }, + callback: fn + }) + } + else { + fn(); + } + }, + failure: function() { + var onFailure = function() { + alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); + }; + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.json', + success: function(r) { + console.log('No translations found for system locale (' + keyUiLocale + ').'); + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + }, + failure: function() { + onFailure(); + }, + callback: fn + }); + } + else { + fn(); onFailure(); - }, - callback: fn - }); - } - else { - fn(); - onFailure(); - } - } - }); - - // root nodes - requests.push({ - url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', - success: function(r) { - init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; - fn(); - } - }); - - // organisation unit levels - requests.push({ - url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', - success: function(r) { - init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; - - if (!init.organisationUnitLevels.length) { - alert('No organisation unit levels'); - } - - fn(); - } - }); - - // user orgunits and children - requests.push({ - url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', - success: function(r) { - var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], - ou = [], - ouc = []; - - if (organisationUnits.length) { - for (var i = 0, org; i < organisationUnits.length; i++) { - org = organisationUnits[i]; - - ou.push(org.id); - - if (org.children) { - ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); - } - } - - init.user = init.user || {}; - init.user.ou = ou; - init.user.ouc = ouc; - } - else { - alert('User is not assigned to any organisation units'); - } - - fn(); - } - }); - - // dimensions - requests.push({ - url: init.contextPath + '/api/organisationUnitGroupSets.json?fields=id,' + namePropertyUrl + '&paging=false', - success: function(r) { - init.dimensions = Ext.decode(r.responseText).organisationUnitGroupSets || []; - fn(); - } - }); - - for (var i = 0; i < requests.length; i++) { - Ext.Ajax.request(requests[i]); - } + } + } + }); + + // root nodes + requests.push({ + url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', + success: function(r) { + init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; + fn(); + } + }); + + // organisation unit levels + requests.push({ + url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', + success: function(r) { + init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; + + if (!init.organisationUnitLevels.length) { + alert('No organisation unit levels'); + } + + fn(); + } + }); + + // user orgunits and children + requests.push({ + url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', + success: function(r) { + var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], + ou = [], + ouc = []; + + if (organisationUnits.length) { + for (var i = 0, org; i < organisationUnits.length; i++) { + org = organisationUnits[i]; + + ou.push(org.id); + + if (org.children) { + ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); + } + } + + init.user = init.user || {}; + init.user.ou = ou; + init.user.ouc = ouc; + } + else { + alert('User is not assigned to any organisation units'); + } + + fn(); + } + }); + + // dimensions + requests.push({ + url: init.contextPath + '/api/organisationUnitGroupSets.json?fields=id,' + namePropertyUrl + '&paging=false', + success: function(r) { + init.dimensions = Ext.decode(r.responseText).organisationUnitGroupSets || []; + fn(); + } + }); + + for (var i = 0; i < requests.length; i++) { + Ext.Ajax.request(requests[i]); + } + } + }); } }); } === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js 2014-10-14 11:49:12 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js 2014-10-14 15:40:58 +0000 @@ -6865,177 +6865,187 @@ success: function(r) { init.contextPath = Ext.decode(r.responseText).activities.dhis.href; - // user-account + // system info Ext.Ajax.request({ - url: init.contextPath + '/api/me/user-account.json', + url: init.contextPath + '/api/system/info.json', success: function(r) { - init.userAccount = Ext.decode(r.responseText); + init.systemInfo = Ext.decode(r.responseText); + init.contextPath = init.systemInfo.contextPath || init.contextPath; - // system info + // date, calendar Ext.Ajax.request({ - url: init.contextPath + '/api/system/info.json', + url: init.contextPath + '/api/systemSettings.json?key=keyCalendar&key=keyDateFormat', success: function(r) { - init.systemInfo = Ext.decode(r.responseText); - - // init - var defaultKeyUiLocale = 'en', - defaultKeyAnalysisDisplayProperty = 'name', - namePropertyUrl, - contextPath, - keyUiLocale, - dateFormat; - - init.contextPath = init.systemInfo.contextPath || init.contextPath; - init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; - init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; - init.systemInfo.dateFormat = init.systemInfo.dateFormat || 'yyyy-mm-dd'; - - contextPath = init.contextPath; - keyUiLocale = init.userAccount.settings.keyUiLocale; - keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; - namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; - dateFormat = init.systemInfo.dateFormat; - - init.namePropertyUrl = namePropertyUrl; - - // calendar - (function() { - var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', - defaultCalendarId = 'gregorian', - calendarIdMap = {'iso8601': defaultCalendarId}, - calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, - calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], - calendarScriptUrl, - createGenerator; - - // calendar - createGenerator = function() { - init.calendar = $.calendars.instance(calendarId); - init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); - }; - - if (Ext.Array.contains(calendarIds, calendarId)) { - calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; - - Ext.Loader.injectScriptElement(calendarScriptUrl, function() { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - }); - } - else { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - } - }()); - - // i18n - requests.push({ - url: 'i18n/' + keyUiLocale + '.properties', + var systemSettings = Ext.decode(r.responseText); + init.systemInfo.dateFormat = Ext.isString(systemSettings.keyDateFormat) ? systemSettings.keyDateFormat.toLowerCase() : 'yyyy-mm-dd'; + init.systemInfo.calendar = systemSettings.keyCalendar; + + // user-account + Ext.Ajax.request({ + url: init.contextPath + '/api/me/user-account.json', success: function(r) { - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.properties', - success: function(r) { - Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); - }, - callback: fn - }) - } - else { - fn(); - } - }, - failure: function() { - var onFailure = function() { - alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); - }; - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.json', - success: function(r) { - console.log('No translations found for system locale (' + keyUiLocale + ').'); - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - }, - failure: function() { + init.userAccount = Ext.decode(r.responseText); + + // init + var defaultKeyUiLocale = 'en', + defaultKeyAnalysisDisplayProperty = 'name', + namePropertyUrl, + contextPath, + keyUiLocale, + dateFormat; + + init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; + init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; + + // local vars + contextPath = init.contextPath; + keyUiLocale = init.userAccount.settings.keyUiLocale; + keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; + namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; + dateFormat = init.systemInfo.dateFormat; + + init.namePropertyUrl = namePropertyUrl; + + // calendar + (function() { + var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', + defaultCalendarId = 'gregorian', + calendarIdMap = {'iso8601': defaultCalendarId}, + calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, + calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], + calendarScriptUrl, + createGenerator; + + // calendar + createGenerator = function() { + init.calendar = $.calendars.instance(calendarId); + init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); + }; + + if (Ext.Array.contains(calendarIds, calendarId)) { + calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; + + Ext.Loader.injectScriptElement(calendarScriptUrl, function() { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + }); + } + else { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + } + }()); + + // i18n + requests.push({ + url: 'i18n/' + keyUiLocale + '.properties', + success: function(r) { + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.properties', + success: function(r) { + Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); + }, + callback: fn + }) + } + else { + fn(); + } + }, + failure: function() { + var onFailure = function() { + alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); + }; + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.json', + success: function(r) { + console.log('No translations found for system locale (' + keyUiLocale + ').'); + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + }, + failure: function() { + onFailure(); + }, + callback: fn + }); + } + else { + fn(); onFailure(); - }, - callback: fn - }); - } - else { - fn(); - onFailure(); - } - } - }); - - // root nodes - requests.push({ - url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', - success: function(r) { - init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; - fn(); - } - }); - - // organisation unit levels - requests.push({ - url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', - success: function(r) { - init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; - - if (!init.organisationUnitLevels.length) { - alert('No organisation unit levels'); - } - - fn(); - } - }); - - // user orgunits and children - requests.push({ - url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', - success: function(r) { - var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], - ou = [], - ouc = []; - - if (organisationUnits.length) { - for (var i = 0, org; i < organisationUnits.length; i++) { - org = organisationUnits[i]; - - ou.push(org.id); - - if (org.children) { - ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); - } - } - - init.user = init.user || {}; - init.user.ou = ou; - init.user.ouc = ouc; - } - else { - alert('User is not assigned to any organisation units'); - } - - fn(); - } - }); - - // dimensions - requests.push({ - url: init.contextPath + '/api/organisationUnitGroupSets.json?fields=id,' + namePropertyUrl + '&paging=false', - success: function(r) { - init.dimensions = Ext.decode(r.responseText).organisationUnitGroupSets || []; - fn(); - } - }); - - for (var i = 0; i < requests.length; i++) { - Ext.Ajax.request(requests[i]); - } + } + } + }); + + // root nodes + requests.push({ + url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', + success: function(r) { + init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; + fn(); + } + }); + + // organisation unit levels + requests.push({ + url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', + success: function(r) { + init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; + + if (!init.organisationUnitLevels.length) { + alert('No organisation unit levels'); + } + + fn(); + } + }); + + // user orgunits and children + requests.push({ + url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', + success: function(r) { + var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], + ou = [], + ouc = []; + + if (organisationUnits.length) { + for (var i = 0, org; i < organisationUnits.length; i++) { + org = organisationUnits[i]; + + ou.push(org.id); + + if (org.children) { + ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); + } + } + + init.user = init.user || {}; + init.user.ou = ou; + init.user.ouc = ouc; + } + else { + alert('User is not assigned to any organisation units'); + } + + fn(); + } + }); + + // dimensions + requests.push({ + url: init.contextPath + '/api/organisationUnitGroupSets.json?fields=id,' + namePropertyUrl + '&paging=false', + success: function(r) { + init.dimensions = Ext.decode(r.responseText).organisationUnitGroupSets || []; + fn(); + } + }); + + for (var i = 0; i < requests.length; i++) { + Ext.Ajax.request(requests[i]); + } + } + }); } }); } === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js 2014-10-14 12:08:08 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js 2014-10-14 15:40:58 +0000 @@ -1489,7 +1489,7 @@ if (items.length) { record.filter = 'IN:' + items.join(';'); } - + return record; }, setRecord: function(record) { @@ -1681,7 +1681,7 @@ }, setOptionValues: function(optionArray) { var options = []; - + for (var i = 0; i < optionArray.length; i++) { options.push({ code: optionArray[i], @@ -1693,7 +1693,7 @@ container.valueStore.loadData(options); this.setValue(options); - }, + }, listeners: { change: function(cmp, newVal, oldVal) { newVal = Ext.Array.from(newVal); @@ -3651,7 +3651,7 @@ }); if (id) { - legendStore.proxy.url = gis.init.contextPath + '/api/mapLegendSets/' + id + '.json?fields=mapLegends[id,name,startValue,endValue,color]'; + legendStore.proxy.url = gis.init.contextPath + '/api/mapLegendSets/' + id + '.json?fields=mapLegends[id,name,startValue,endValue,color]'; legendStore.load(); legendSetName.setValue(legendSetStore.getById(id).data.name); @@ -7350,7 +7350,7 @@ periodOffset = periodType.periodOffset, generator = gis.init.periodGenerator, periods; - + if (type === 'relativePeriods') { periodsByTypeStore.loadData(gis.conf.period.relativePeriods); @@ -7359,20 +7359,20 @@ } else { periods = generator.generateReversedPeriods(type, type === 'Yearly' ? periodOffset - 5 : periodOffset); - + for (var i = 0; i < periods.length; i++) { periods[i].id = periods[i].iso; } periodsByTypeStore.setIndex(periods); periodsByTypeStore.loadData(periods); - + periodPrev.enable(); periodNext.enable(); } period.selectFirst(); - }; + }; periodType = Ext.create('Ext.form.field.ComboBox', { cls: 'gis-combo', @@ -8594,7 +8594,7 @@ iconCls: 'gis-menu-item-datasource', disabled: true, xable: function() { - if (gis.map.id) { + if (gis.map && gis.map.id) { this.enable(); } else { @@ -8639,7 +8639,7 @@ iconCls: 'gis-menu-item-datasource', disabled: true, xable: function() { - if (gis.map.id) { + if (gis.map && gis.map.id) { this.enable(); } else { @@ -9213,217 +9213,227 @@ success: function(r) { init.contextPath = Ext.decode(r.responseText).activities.dhis.href; - // user-account + // system info Ext.Ajax.request({ - url: init.contextPath + '/api/me/user-account.json', + url: init.contextPath + '/api/system/info.json', success: function(r) { - init.userAccount = Ext.decode(r.responseText); + init.systemInfo = Ext.decode(r.responseText); + init.contextPath = init.systemInfo.contextPath || init.contextPath; - // system info + // date, calendar Ext.Ajax.request({ - url: init.contextPath + '/api/system/info.json', + url: init.contextPath + '/api/systemSettings.json?key=keyCalendar&key=keyDateFormat', success: function(r) { - init.systemInfo = Ext.decode(r.responseText); - - // init - var defaultKeyUiLocale = 'en', - defaultKeyAnalysisDisplayProperty = 'name', - namePropertyUrl, - contextPath, - keyUiLocale, - dateFormat; - - init.contextPath = init.systemInfo.contextPath || init.contextPath; - init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; - init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; - init.systemInfo.dateFormat = init.systemInfo.dateFormat || 'yyyy-mm-dd'; - - contextPath = init.contextPath; - keyUiLocale = init.userAccount.settings.keyUiLocale; - keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; - namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; - dateFormat = init.systemInfo.dateFormat; - - init.namePropertyUrl = namePropertyUrl; - - // calendar - (function() { - var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', - defaultCalendarId = 'gregorian', - calendarIdMap = {'iso8601': defaultCalendarId}, - calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, - calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], - calendarScriptUrl, - createGenerator; - - // calendar - createGenerator = function() { - init.calendar = $.calendars.instance(calendarId); - init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); - }; - - if (Ext.Array.contains(calendarIds, calendarId)) { - calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; - - Ext.Loader.injectScriptElement(calendarScriptUrl, function() { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - }); - } - else { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - } - }()); - - // i18n - requests.push({ - url: 'i18n/' + keyUiLocale + '.properties', + var systemSettings = Ext.decode(r.responseText); + init.systemInfo.dateFormat = Ext.isString(systemSettings.keyDateFormat) ? systemSettings.keyDateFormat.toLowerCase() : 'yyyy-mm-dd'; + init.systemInfo.calendar = systemSettings.keyCalendar; + + // user-account + Ext.Ajax.request({ + url: init.contextPath + '/api/me/user-account.json', success: function(r) { - GIS.i18n = dhis2.util.parseJavaProperties(r.responseText); - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.properties', - success: function(r) { - Ext.applyIf(GIS.i18n, dhis2.util.parseJavaProperties(r.responseText)); - }, - callback: fn - }) - } - else { - fn(); - } - }, - failure: function() { - var onFailure = function() { - alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); - }; - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.json', - success: function(r) { - console.log('No translations found for system locale (' + keyUiLocale + ').'); - GIS.i18n = dhis2.util.parseJavaProperties(r.responseText); - }, - failure: function() { + init.userAccount = Ext.decode(r.responseText); + + // init + var defaultKeyUiLocale = 'en', + defaultKeyAnalysisDisplayProperty = 'name', + namePropertyUrl, + contextPath, + keyUiLocale, + dateFormat; + + init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; + init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; + + // local vars + contextPath = init.contextPath; + keyUiLocale = init.userAccount.settings.keyUiLocale; + keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; + namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; + dateFormat = init.systemInfo.dateFormat; + + init.namePropertyUrl = namePropertyUrl; + + // calendar + (function() { + var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', + defaultCalendarId = 'gregorian', + calendarIdMap = {'iso8601': defaultCalendarId}, + calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, + calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], + calendarScriptUrl, + createGenerator; + + // calendar + createGenerator = function() { + init.calendar = $.calendars.instance(calendarId); + init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); + }; + + if (Ext.Array.contains(calendarIds, calendarId)) { + calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; + + Ext.Loader.injectScriptElement(calendarScriptUrl, function() { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + }); + } + else { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + } + }()); + + // i18n + requests.push({ + url: 'i18n/' + keyUiLocale + '.properties', + success: function(r) { + GIS.i18n = dhis2.util.parseJavaProperties(r.responseText); + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.properties', + success: function(r) { + Ext.applyIf(GIS.i18n, dhis2.util.parseJavaProperties(r.responseText)); + }, + callback: fn + }) + } + else { + fn(); + } + }, + failure: function() { + var onFailure = function() { + alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); + }; + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.json', + success: function(r) { + console.log('No translations found for system locale (' + keyUiLocale + ').'); + GIS.i18n = dhis2.util.parseJavaProperties(r.responseText); + }, + failure: function() { + onFailure(); + }, + callback: fn + }); + } + else { + fn(); onFailure(); - }, - callback: fn - }); - } - else { - fn(); - onFailure(); - } - } - }); - - // root nodes - requests.push({ - url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', - success: function(r) { - init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; - fn(); - } - }); - - // organisation unit levels - requests.push({ - url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', - success: function(r) { - init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; - - if (!init.organisationUnitLevels.length) { - alert('No organisation unit levels'); - } - - fn(); - } - }); - - // user orgunits and children - requests.push({ - url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', - success: function(r) { - var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], - ou = [], - ouc = []; - - if (organisationUnits.length) { - for (var i = 0, org; i < organisationUnits.length; i++) { - org = organisationUnits[i]; - - ou.push(org.id); - - if (org.children) { - ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); - } - } - - init.user = init.user || {}; - init.user.ou = ou; - init.user.ouc = ouc; - } - else { - alert('User is not assigned to any organisation units'); - } - - fn(); - } - }); - - // admin - requests.push({ - url: init.contextPath + '/api/me/authorization/F_GIS_ADMIN', - success: function(r) { - init.user.isAdmin = (r.responseText === 'true'); - fn(); - } - }); - - // indicator groups - requests.push({ - url: init.contextPath + '/api/indicatorGroups.json?fields=id,name&paging=false', - success: function(r) { - init.indicatorGroups = Ext.decode(r.responseText).indicatorGroups || []; - fn(); - } - }); - - // data element groups - requests.push({ - url: init.contextPath + '/api/dataElementGroups.json?fields=id,' + namePropertyUrl + '&paging=false', - success: function(r) { - init.dataElementGroups = Ext.decode(r.responseText).dataElementGroups || []; - fn(); - } - }); - - // infrastructural data element group - requests.push({ - url: init.contextPath + '/api/configuration/infrastructuralDataElements.json', - success: function(r) { - var obj = Ext.decode(r.responseText); - - init.systemSettings.infrastructuralDataElementGroup = Ext.isObject(obj) ? obj : null; - fn(); - } - }); - - // infrastructural period type - requests.push({ - url: init.contextPath + '/api/configuration/infrastructuralPeriodType.json', - success: function(r) { - var obj = Ext.decode(r.responseText); - - init.systemSettings.infrastructuralPeriodType = Ext.isObject(obj) ? obj : null; - fn(); - } - }); - - for (var i = 0; i < requests.length; i++) { - Ext.Ajax.request(requests[i]); - } + } + } + }); + + // root nodes + requests.push({ + url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', + success: function(r) { + init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; + fn(); + } + }); + + // organisation unit levels + requests.push({ + url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', + success: function(r) { + init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; + + if (!init.organisationUnitLevels.length) { + alert('No organisation unit levels'); + } + + fn(); + } + }); + + // user orgunits and children + requests.push({ + url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', + success: function(r) { + var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], + ou = [], + ouc = []; + + if (organisationUnits.length) { + for (var i = 0, org; i < organisationUnits.length; i++) { + org = organisationUnits[i]; + + ou.push(org.id); + + if (org.children) { + ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); + } + } + + init.user = init.user || {}; + init.user.ou = ou; + init.user.ouc = ouc; + } + else { + alert('User is not assigned to any organisation units'); + } + + fn(); + } + }); + + // admin + requests.push({ + url: init.contextPath + '/api/me/authorization/F_GIS_ADMIN', + success: function(r) { + init.user.isAdmin = (r.responseText === 'true'); + fn(); + } + }); + + // indicator groups + requests.push({ + url: init.contextPath + '/api/indicatorGroups.json?fields=id,name&paging=false', + success: function(r) { + init.indicatorGroups = Ext.decode(r.responseText).indicatorGroups || []; + fn(); + } + }); + + // data element groups + requests.push({ + url: init.contextPath + '/api/dataElementGroups.json?fields=id,' + namePropertyUrl + '&paging=false', + success: function(r) { + init.dataElementGroups = Ext.decode(r.responseText).dataElementGroups || []; + fn(); + } + }); + + // infrastructural data element group + requests.push({ + url: init.contextPath + '/api/configuration/infrastructuralDataElements.json', + success: function(r) { + var obj = Ext.decode(r.responseText); + + init.systemSettings.infrastructuralDataElementGroup = Ext.isObject(obj) ? obj : null; + fn(); + } + }); + + // infrastructural period type + requests.push({ + url: init.contextPath + '/api/configuration/infrastructuralPeriodType.json', + success: function(r) { + var obj = Ext.decode(r.responseText); + + init.systemSettings.infrastructuralPeriodType = Ext.isObject(obj) ? obj : null; + fn(); + } + }); + + for (var i = 0; i < requests.length; i++) { + Ext.Ajax.request(requests[i]); + } + } + }); } }); } === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js 2014-09-16 00:11:41 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js 2014-10-14 15:17:01 +0000 @@ -697,45 +697,6 @@ selectHandlers.activate(); }; - GIS.core.OrganisationUnitLevelStore = function(gis) { - var isPlugin = GIS.plugin && !GIS.app; - - return Ext.create('Ext.data.Store', { - fields: ['id', 'name', 'level'], - proxy: { - type: isPlugin ? 'jsonp' : 'ajax', - url: gis.init.contextPath + '/api/organisationUnitLevels.' + (isPlugin ? 'jsonp' : 'json') + '?fields=id,name,level&paging=false', - reader: { - type: 'json', - root: 'organisationUnitLevels' - } - }, - autoLoad: true, - cmp: [], - isLoaded: false, - loadFn: function(fn) { - if (this.isLoaded) { - fn.call(); - } - else { - this.load(fn); - } - }, - getRecordByLevel: function(level) { - return this.getAt(this.findExact('level', level)); - }, - listeners: { - load: function() { - if (!this.isLoaded) { - this.isLoaded = true; - gis.util.gui.combo.setQueryMode(this.cmp, 'local'); - } - this.sort('level', 'ASC'); - } - } - }); - }; - GIS.core.StyleMap = function(labelConfig) { var defaults = { fillOpacity: 1, @@ -3207,11 +3168,6 @@ }; }()); - // store - (function() { - store.organisationUnitLevels = GIS.core.OrganisationUnitLevelStore(gis); - }()); - gis.api = api; gis.store = store; === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js 2014-10-14 12:08:08 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js 2014-10-14 15:40:58 +0000 @@ -6171,186 +6171,196 @@ success: function(r) { init.contextPath = Ext.decode(r.responseText).activities.dhis.href; - // user-account + // system info Ext.Ajax.request({ - url: init.contextPath + '/api/me/user-account.json', + url: init.contextPath + '/api/system/info.json', success: function(r) { - init.userAccount = Ext.decode(r.responseText); + init.systemInfo = Ext.decode(r.responseText); + init.contextPath = init.systemInfo.contextPath || init.contextPath; - // system info + // date, calendar Ext.Ajax.request({ - url: init.contextPath + '/api/system/info.json', + url: init.contextPath + '/api/systemSettings.json?key=keyCalendar&key=keyDateFormat', success: function(r) { - init.systemInfo = Ext.decode(r.responseText); - - // init - var defaultKeyUiLocale = 'en', - defaultKeyAnalysisDisplayProperty = 'name', - namePropertyUrl, - contextPath, - keyUiLocale, - dateFormat; - - init.contextPath = init.systemInfo.contextPath || init.contextPath; - init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; - init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; - init.systemInfo.dateFormat = init.systemInfo.dateFormat || 'yyyy-mm-dd'; - - contextPath = init.contextPath; - keyUiLocale = init.userAccount.settings.keyUiLocale; - keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; - namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; - dateFormat = init.systemInfo.dateFormat; - - init.namePropertyUrl = namePropertyUrl; - - // calendar - (function() { - var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', - defaultCalendarId = 'gregorian', - calendarIdMap = {'iso8601': defaultCalendarId}, - calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, - calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], - calendarScriptUrl, - createGenerator; - - // calendar - createGenerator = function() { - init.calendar = $.calendars.instance(calendarId); - init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); - }; - - if (Ext.Array.contains(calendarIds, calendarId)) { - calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; - - Ext.Loader.injectScriptElement(calendarScriptUrl, function() { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - }); - } - else { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - } - }()); - - // i18n - requests.push({ - url: 'i18n/' + keyUiLocale + '.properties', + var systemSettings = Ext.decode(r.responseText); + init.systemInfo.dateFormat = Ext.isString(systemSettings.keyDateFormat) ? systemSettings.keyDateFormat.toLowerCase() : 'yyyy-mm-dd'; + init.systemInfo.calendar = systemSettings.keyCalendar; + + // user-account + Ext.Ajax.request({ + url: init.contextPath + '/api/me/user-account.json', success: function(r) { - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.properties', - success: function(r) { - Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); - }, - callback: fn - }) - } - else { - fn(); - } - }, - failure: function() { - var onFailure = function() { - alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); - }; - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.json', - success: function(r) { - console.log('No translations found for system locale (' + keyUiLocale + ').'); - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - }, - failure: function() { + init.userAccount = Ext.decode(r.responseText); + + // init + var defaultKeyUiLocale = 'en', + defaultKeyAnalysisDisplayProperty = 'name', + namePropertyUrl, + contextPath, + keyUiLocale, + dateFormat; + + init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; + init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; + + // local vars + contextPath = init.contextPath; + keyUiLocale = init.userAccount.settings.keyUiLocale; + keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; + namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; + dateFormat = init.systemInfo.dateFormat; + + init.namePropertyUrl = namePropertyUrl; + + // calendar + (function() { + var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', + defaultCalendarId = 'gregorian', + calendarIdMap = {'iso8601': defaultCalendarId}, + calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, + calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], + calendarScriptUrl, + createGenerator; + + // calendar + createGenerator = function() { + init.calendar = $.calendars.instance(calendarId); + init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); + }; + + if (Ext.Array.contains(calendarIds, calendarId)) { + calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; + + Ext.Loader.injectScriptElement(calendarScriptUrl, function() { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + }); + } + else { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + } + }()); + + // i18n + requests.push({ + url: 'i18n/' + keyUiLocale + '.properties', + success: function(r) { + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.properties', + success: function(r) { + Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); + }, + callback: fn + }) + } + else { + fn(); + } + }, + failure: function() { + var onFailure = function() { + alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); + }; + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.json', + success: function(r) { + console.log('No translations found for system locale (' + keyUiLocale + ').'); + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + }, + failure: function() { + onFailure(); + }, + callback: fn + }); + } + else { + fn(); onFailure(); - }, - callback: fn - }); - } - else { - fn(); - onFailure(); - } - } - }); - - // root nodes - requests.push({ - url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', - success: function(r) { - init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; - fn(); - } - }); - - // organisation unit levels - requests.push({ - url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', - success: function(r) { - init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; - - if (!init.organisationUnitLevels.length) { - alert('No organisation unit levels'); - } - - fn(); - } - }); - - // user orgunits and children - requests.push({ - url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', - success: function(r) { - var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], - ou = [], - ouc = []; - - if (organisationUnits.length) { - for (var i = 0, org; i < organisationUnits.length; i++) { - org = organisationUnits[i]; - - ou.push(org.id); - - if (org.children) { - ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); - } - } - - init.user = init.user || {}; - init.user.ou = ou; - init.user.ouc = ouc; - } - else { - alert('User is not assigned to any organisation units'); - } - - fn(); - } - }); - - // legend sets - requests.push({ - url: contextPath + '/api/mapLegendSets.json?fields=id,name,mapLegends[id,name,startValue,endValue,color]&paging=false', - success: function(r) { - init.legendSets = Ext.decode(r.responseText).mapLegendSets || []; - fn(); - } - }); - - // dimensions - requests.push({ - url: contextPath + '/api/dimensions.json?links=false&paging=false', - success: function(r) { - init.dimensions = Ext.decode(r.responseText).dimensions || []; - fn(); - } - }); - - for (var i = 0; i < requests.length; i++) { - Ext.Ajax.request(requests[i]); - } + } + } + }); + + // root nodes + requests.push({ + url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', + success: function(r) { + init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; + fn(); + } + }); + + // organisation unit levels + requests.push({ + url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', + success: function(r) { + init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; + + if (!init.organisationUnitLevels.length) { + alert('No organisation unit levels'); + } + + fn(); + } + }); + + // user orgunits and children + requests.push({ + url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', + success: function(r) { + var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], + ou = [], + ouc = []; + + if (organisationUnits.length) { + for (var i = 0, org; i < organisationUnits.length; i++) { + org = organisationUnits[i]; + + ou.push(org.id); + + if (org.children) { + ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); + } + } + + init.user = init.user || {}; + init.user.ou = ou; + init.user.ouc = ouc; + } + else { + alert('User is not assigned to any organisation units'); + } + + fn(); + } + }); + + // legend sets + requests.push({ + url: contextPath + '/api/mapLegendSets.json?fields=id,name,mapLegends[id,name,startValue,endValue,color]&paging=false', + success: function(r) { + init.legendSets = Ext.decode(r.responseText).mapLegendSets || []; + fn(); + } + }); + + // dimensions + requests.push({ + url: contextPath + '/api/dimensions.json?links=false&paging=false', + success: function(r) { + init.dimensions = Ext.decode(r.responseText).dimensions || []; + fn(); + } + }); + + for (var i = 0; i < requests.length; i++) { + Ext.Ajax.request(requests[i]); + } + } + }); } }); } === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js 2014-10-14 12:08:08 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js 2014-10-14 15:40:58 +0000 @@ -6106,177 +6106,187 @@ success: function(r) { init.contextPath = Ext.decode(r.responseText).activities.dhis.href; - // user-account + // system info Ext.Ajax.request({ - url: init.contextPath + '/api/me/user-account.json', + url: init.contextPath + '/api/system/info.json', success: function(r) { - init.userAccount = Ext.decode(r.responseText); + init.systemInfo = Ext.decode(r.responseText); + init.contextPath = init.systemInfo.contextPath || init.contextPath; - // system info + // date, calendar Ext.Ajax.request({ - url: init.contextPath + '/api/system/info.json', + url: init.contextPath + '/api/systemSettings.json?key=keyCalendar&key=keyDateFormat', success: function(r) { - init.systemInfo = Ext.decode(r.responseText); - - // init - var defaultKeyUiLocale = 'en', - defaultKeyAnalysisDisplayProperty = 'name', - namePropertyUrl, - contextPath, - keyUiLocale, - dateFormat; - - init.contextPath = init.systemInfo.contextPath || init.contextPath; - init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; - init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; - init.systemInfo.dateFormat = init.systemInfo.dateFormat || 'yyyy-mm-dd'; - - contextPath = init.contextPath; - keyUiLocale = init.userAccount.settings.keyUiLocale; - keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; - namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; - dateFormat = init.systemInfo.dateFormat; - - init.namePropertyUrl = namePropertyUrl; - - // calendar - (function() { - var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', - defaultCalendarId = 'gregorian', - calendarIdMap = {'iso8601': defaultCalendarId}, - calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, - calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], - calendarScriptUrl, - createGenerator; - - // calendar - createGenerator = function() { - init.calendar = $.calendars.instance(calendarId); - init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); - }; - - if (Ext.Array.contains(calendarIds, calendarId)) { - calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; - - Ext.Loader.injectScriptElement(calendarScriptUrl, function() { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - }); - } - else { - Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); - } - }()); - - // i18n - requests.push({ - url: 'i18n/' + keyUiLocale + '.properties', + var systemSettings = Ext.decode(r.responseText); + init.systemInfo.dateFormat = Ext.isString(systemSettings.keyDateFormat) ? systemSettings.keyDateFormat.toLowerCase() : 'yyyy-mm-dd'; + init.systemInfo.calendar = systemSettings.keyCalendar; + + // user-account + Ext.Ajax.request({ + url: init.contextPath + '/api/me/user-account.json', success: function(r) { - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.properties', - success: function(r) { - Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); - }, - callback: fn - }) - } - else { - fn(); - } - }, - failure: function() { - var onFailure = function() { - alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); - }; - - if (keyUiLocale !== defaultKeyUiLocale) { - Ext.Ajax.request({ - url: 'i18n/' + defaultKeyUiLocale + '.json', - success: function(r) { - console.log('No translations found for system locale (' + keyUiLocale + ').'); - NS.i18n = dhis2.util.parseJavaProperties(r.responseText); - }, - failure: function() { + init.userAccount = Ext.decode(r.responseText); + + // init + var defaultKeyUiLocale = 'en', + defaultKeyAnalysisDisplayProperty = 'name', + namePropertyUrl, + contextPath, + keyUiLocale, + dateFormat; + + init.userAccount.settings.keyUiLocale = init.userAccount.settings.keyUiLocale || defaultKeyUiLocale; + init.userAccount.settings.keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty || defaultKeyAnalysisDisplayProperty; + + // local vars + contextPath = init.contextPath; + keyUiLocale = init.userAccount.settings.keyUiLocale; + keyAnalysisDisplayProperty = init.userAccount.settings.keyAnalysisDisplayProperty; + namePropertyUrl = keyAnalysisDisplayProperty === defaultKeyAnalysisDisplayProperty ? keyAnalysisDisplayProperty : keyAnalysisDisplayProperty + '|rename(' + defaultKeyAnalysisDisplayProperty + ')'; + dateFormat = init.systemInfo.dateFormat; + + init.namePropertyUrl = namePropertyUrl; + + // calendar + (function() { + var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', + defaultCalendarId = 'gregorian', + calendarIdMap = {'iso8601': defaultCalendarId}, + calendarId = calendarIdMap[init.systemInfo.calendar] || init.systemInfo.calendar || defaultCalendarId, + calendarIds = ['coptic', 'ethiopian', 'islamic', 'julian', 'nepali', 'thai'], + calendarScriptUrl, + createGenerator; + + // calendar + createGenerator = function() { + init.calendar = $.calendars.instance(calendarId); + init.periodGenerator = new dhis2.period.PeriodGenerator(init.calendar, init.systemInfo.dateFormat); + }; + + if (Ext.Array.contains(calendarIds, calendarId)) { + calendarScriptUrl = '../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.' + calendarId + '.min.js'; + + Ext.Loader.injectScriptElement(calendarScriptUrl, function() { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + }); + } + else { + Ext.Loader.injectScriptElement(dhis2PeriodUrl, createGenerator); + } + }()); + + // i18n + requests.push({ + url: 'i18n/' + keyUiLocale + '.properties', + success: function(r) { + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.properties', + success: function(r) { + Ext.applyIf(NS.i18n, dhis2.util.parseJavaProperties(r.responseText)); + }, + callback: fn + }) + } + else { + fn(); + } + }, + failure: function() { + var onFailure = function() { + alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').'); + }; + + if (keyUiLocale !== defaultKeyUiLocale) { + Ext.Ajax.request({ + url: 'i18n/' + defaultKeyUiLocale + '.json', + success: function(r) { + console.log('No translations found for system locale (' + keyUiLocale + ').'); + NS.i18n = dhis2.util.parseJavaProperties(r.responseText); + }, + failure: function() { + onFailure(); + }, + callback: fn + }); + } + else { + fn(); onFailure(); - }, - callback: fn - }); - } - else { - fn(); - onFailure(); - } - } - }); - - // root nodes - requests.push({ - url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', - success: function(r) { - init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; - fn(); - } - }); - - // organisation unit levels - requests.push({ - url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', - success: function(r) { - init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; - - if (!init.organisationUnitLevels.length) { - alert('No organisation unit levels'); - } - - fn(); - } - }); - - // user orgunits and children - requests.push({ - url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', - success: function(r) { - var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], - ou = [], - ouc = []; - - if (organisationUnits.length) { - for (var i = 0, org; i < organisationUnits.length; i++) { - org = organisationUnits[i]; - - ou.push(org.id); - - if (org.children) { - ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); - } - } - - init.user = init.user || {}; - init.user.ou = ou; - init.user.ouc = ouc; - } - else { - alert('User is not assigned to any organisation units'); - } - - fn(); - } - }); - - // dimensions - requests.push({ - url: contextPath + '/api/dimensions.json?links=false&paging=false', - success: function(r) { - init.dimensions = Ext.decode(r.responseText).dimensions || []; - fn(); - } - }); - - for (var i = 0; i < requests.length; i++) { - Ext.Ajax.request(requests[i]); - } + } + } + }); + + // root nodes + requests.push({ + url: contextPath + '/api/organisationUnits.json?userDataViewFallback=true&paging=false&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']', + success: function(r) { + init.rootNodes = Ext.decode(r.responseText).organisationUnits || []; + fn(); + } + }); + + // organisation unit levels + requests.push({ + url: contextPath + '/api/organisationUnitLevels.json?fields=id,name,level&paging=false', + success: function(r) { + init.organisationUnitLevels = Ext.decode(r.responseText).organisationUnitLevels || []; + + if (!init.organisationUnitLevels.length) { + alert('No organisation unit levels'); + } + + fn(); + } + }); + + // user orgunits and children + requests.push({ + url: contextPath + '/api/organisationUnits.json?userOnly=true&fields=id,' + namePropertyUrl + ',children[id,' + namePropertyUrl + ']&paging=false', + success: function(r) { + var organisationUnits = Ext.decode(r.responseText).organisationUnits || [], + ou = [], + ouc = []; + + if (organisationUnits.length) { + for (var i = 0, org; i < organisationUnits.length; i++) { + org = organisationUnits[i]; + + ou.push(org.id); + + if (org.children) { + ouc = Ext.Array.clean(ouc.concat(Ext.Array.pluck(org.children, 'id') || [])); + } + } + + init.user = init.user || {}; + init.user.ou = ou; + init.user.ouc = ouc; + } + else { + alert('User is not assigned to any organisation units'); + } + + fn(); + } + }); + + // dimensions + requests.push({ + url: contextPath + '/api/dimensions.json?links=false&paging=false', + success: function(r) { + init.dimensions = Ext.decode(r.responseText).dimensions || []; + fn(); + } + }); + + for (var i = 0; i < requests.length; i++) { + Ext.Ajax.request(requests[i]); + } + } + }); } }); }