diff --git a/onadata/apps/main/context_processors.py b/onadata/apps/main/context_processors.py index 265a6c243..a5f49c859 100644 --- a/onadata/apps/main/context_processors.py +++ b/onadata/apps/main/context_processors.py @@ -23,6 +23,7 @@ def site_name(request): site_name = site.name return {'SITE_NAME': site_name} + def base_url(request): """ Return a BASE_URL template context for the current request. @@ -31,5 +32,11 @@ def base_url(request): scheme = 'https://' else: scheme = 'http://' - - return {'BASE_URL': scheme + request.get_host(),} + + return {'BASE_URL': scheme + request.get_host(), } + + +def kobocat_root_uri_prefix(request): + # settings.KOBOCAT_ROOT_URI_PREFIX will have trailing and leading slashes, so we fall back to a + # single (leading) slash when it isn't set + return {'KOBOCAT_ROOT_URI_PREFIX': getattr(settings, 'KOBOCAT_ROOT_URI_PREFIX', '/')} diff --git a/onadata/apps/viewer/static/js/instance.js b/onadata/apps/viewer/static/js/instance.js index 76599a978..af1cadcb4 100644 --- a/onadata/apps/viewer/static/js/instance.js +++ b/onadata/apps/viewer/static/js/instance.js @@ -57,7 +57,9 @@ function addOrEditNote(){ if (note == ""){ return false; } - var notes_url = '/api/v1/notes', + // KOBOCAT_ROOT_URI_PREFIX variable will be set in the template using a context processor, in case kobocat + // is running under a URL path prefix (e.g. /kobocat/). In case the variable isn't set it will use / + var notes_url = ('KOBOCAT_ROOT_URI_PREFIX' in window ? KOBOCAT_ROOT_URI_PREFIX : '/') + 'api/v1/notes', post_data = {'note': note, 'instance': instance_id}; if($("#notesform #note-id").val() != undefined){ // Edit Note @@ -442,7 +444,7 @@ function deleteNote(obj){ var note_id = $(obj).data('note-id'); if(confirm("Are you sure you want to delete \"" + note + "\"?") == true){ $.ajax({ - url: "/api/v1/notes/" + note_id, + url: ('KOBOCAT_ROOT_URI_PREFIX' in window ? KOBOCAT_ROOT_URI_PREFIX : '/') + 'api/v1/notes/' + note_id, type: "DELETE", statusCode: { 404: function(){ diff --git a/onadata/apps/viewer/templates/instance.html b/onadata/apps/viewer/templates/instance.html index f4d2b0982..454efde4d 100644 --- a/onadata/apps/viewer/templates/instance.html +++ b/onadata/apps/viewer/templates/instance.html @@ -165,4 +165,7 @@