diff --git a/tracim/tracim/controllers/calendar.py b/tracim/tracim/controllers/calendar.py index 7277e952d3..5f752d9a51 100644 --- a/tracim/tracim/controllers/calendar.py +++ b/tracim/tracim/controllers/calendar.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- - +import re import tg from tg import tmpl_context @@ -45,6 +45,8 @@ def index(self): workspace_base_url = CalendarManager.get_workspace_base_url() workspace_calendar_urls = CalendarManager\ .get_workspace_readable_calendars_urls_for_user(user) + base_href_url = \ + re.sub(r"^http[s]?://", '', CalendarManager.get_base_url()) # Template will use User.auth_token, ensure it's validity user.ensure_auth_token() @@ -55,4 +57,5 @@ def index(self): workspace_base_url=workspace_base_url, workspace_clendar_urls=workspace_calendar_urls, auth_token=user.auth_token, + base_href_url=base_href_url, ) diff --git a/tracim/tracim/public/caldavzap/.gitignore b/tracim/tracim/public/caldavzap/.gitignore new file mode 100644 index 0000000000..e9b8ca71f3 --- /dev/null +++ b/tracim/tracim/public/caldavzap/.gitignore @@ -0,0 +1,3 @@ +*~ +#* +.idea diff --git a/tracim/tracim/public/caldavzap/cache.manifest b/tracim/tracim/public/caldavzap/cache.manifest index af6ef74a4b..98e6436fda 100644 --- a/tracim/tracim/public/caldavzap/cache.manifest +++ b/tracim/tracim/public/caldavzap/cache.manifest @@ -1,5 +1,5 @@ CACHE MANIFEST -#V 20160728145557 +#V 20160906103401 CACHE: common.js diff --git a/tracim/tracim/public/caldavzap/config.js b/tracim/tracim/public/caldavzap/config.js index 46bf2b31dd..8f2f35f6ab 100644 --- a/tracim/tracim/public/caldavzap/config.js +++ b/tracim/tracim/public/caldavzap/config.js @@ -306,27 +306,6 @@ along with this program. If not, see . // } //]; -var globalAccountSettings=[ - { - href: 'http://127.0.0.1:5232/user/3.ics/', - userAuth: - { - userName: 'bastien.sevajol@algoo.fr', - userPassword: 'bastien.sevajol@algoo.fr' - //userName: 'bastien', - //userPassword: 'bastien' - }, - timeOut: 90000, - lockTimeOut: 10000, - checkContentType: true, - settingsAccount: true, - delegation: true, - hrefLabel: null, - forceReadOnly: null, - ignoreAlarms: false, - backgroundCalendars: [] - } -]; // globalNetworkCheckSettings // Use this option if you want to use standard login screen without @@ -352,22 +331,22 @@ var globalAccountSettings=[ // Davical example which automatically detects the protocol, server name, // port, ... (client installed into Davical "htdocs" subdirectory; // works "out of the box", no additional setup required): -// var globalNetworkCheckSettings={ -// href: location.protocol+'//'+location.hostname+ -// (location.port ? ':'+location.port: '')+ -// location.pathname.replace(RegExp('/+[^/]+/*(index\.html)?$'),'')+ -// '/caldav.php/', -// timeOut: 90000, -// lockTimeOut: 10000, -// checkContentType: true, -// settingsAccount: true, -// delegation: true, -// additionalResources: [], -// hrefLabel: null, -// forceReadOnly: null, -// ignoreAlarms: false, -// backgroundCalendars: [] -// } +var globalNetworkCheckSettings={ + href: location.protocol+'//'+location.hostname+ + (location.port ? ':'+location.port: '')+ + location.pathname.replace(RegExp('/+[^/]+/*(index\.html)?$'),'')+ + '/caldav.php/', + timeOut: 90000, + lockTimeOut: 10000, + checkContentType: true, + settingsAccount: true, + delegation: true, + additionalResources: [], + hrefLabel: null, + forceReadOnly: null, + ignoreAlarms: false, + backgroundCalendars: [] +} // globalNetworkAccountSettings diff --git a/tracim/tracim/public/caldavzap/main.js b/tracim/tracim/public/caldavzap/main.js index 4021c6f316..9fcd7dc3bb 100644 --- a/tracim/tracim/public/caldavzap/main.js +++ b/tracim/tracim/public/caldavzap/main.js @@ -1936,3 +1936,23 @@ function setCalendarNumber(initSearch) globalTodoCalendarNumber++; } } + +function algoo_get_basehref_for_href(href, globalAccountSettings) { + for (config_key in globalAccountSettings) { + var config = globalAccountSettings[config_key]; + if (config.href == href && config.basehref) { + return config.basehref; + } + } +} + +function algoo_replace_regex(href, globalAccountSettings) { + var protocol_re = new RegExp('^(https?://)(.*)','i'); + + var base_href = algoo_get_basehref_for_href(href, globalAccountSettings); + var protocol_match = href.match(protocol_re); + var protocol = protocol_match[1]; + var path = protocol_match[2].replace(base_href, ''); + + return [href, protocol, base_href, path] +} diff --git a/tracim/tracim/public/caldavzap/webdav_protocol.js b/tracim/tracim/public/caldavzap/webdav_protocol.js index 604ce8605f..73d404d435 100644 --- a/tracim/tracim/public/caldavzap/webdav_protocol.js +++ b/tracim/tracim/public/caldavzap/webdav_protocol.js @@ -490,8 +490,7 @@ function netSaveProperty(inputCollection, hrefProperty, inputProperty, inputValu function DAVresourceDelegation(inputResource, index, lastIndex) { globalCalDAVResourceSync=false; - var re=new RegExp('^(https?://)([^/]+)(.*)', 'i'); - var tmp=inputResource.href.match(re); + var tmp=algoo_replace_regex(inputResource.href, globalAccountSettings); var baseHref=tmp[1]+tmp[2]; var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]; @@ -1039,8 +1038,7 @@ function netFindResource(inputResource, inputResourceIndex, forceLoad, indexR, l return false; } - var re=new RegExp('^(https?://)([^/]+)(.*)','i'); - var tmp=inputResource.href.match(re); + var tmp = algoo_replace_regex(inputResource.href, globalAccountSettings); var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]; var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; // for the error handler var settingsXML=''; @@ -1221,7 +1219,6 @@ function netFindResource(inputResource, inputResourceIndex, forceLoad, indexR, l function netLoadResource(inputResource, inputHref, hrefMode, inputResourceIndex, forceLoad, indexR, loadArray) { - var re=new RegExp('^(https?://)([^/]+)(.*)','i'); if(!isAvaible('CardDavMATE') || !globalCardDAVInitLoad || (globalCardDAVInitLoad && typeof inputResource.addressbookNo == 'undefined')) inputResource.addressbookNo=0; if(!isAvaible('CalDavZAP') || !globalCalDAVInitLoad || (globalCalDAVInitLoad && typeof inputResource.calendarNo=='undefined' && typeof inputResource.todoNo=='undefined')) @@ -1229,7 +1226,7 @@ function netLoadResource(inputResource, inputHref, hrefMode, inputResourceIndex, inputResource.calendarNo=0; inputResource.todoNo=0; } - var tmp=inputResource.abhref.match(re); + var tmp = algoo_replace_regex(inputResource.abhref, globalAccountSettings); var baseHref=tmp[1]+tmp[2]; var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]; var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; // for the error handler @@ -1482,7 +1479,7 @@ function netLoadResource(inputResource, inputHref, hrefMode, inputResourceIndex, var href=$(element).children().filterNsNode('href').text(); if(href.match(RegExp('^https?://','i'))!=null) { - var tmpH = href.match(RegExp('^(https?://)([^/]+)(.*)','i')) + var tmpH = algoo_replace_regex(href, globalAccountSettings); if(tmpH!=null) href = tmpH[3]; } @@ -1708,7 +1705,7 @@ function netLoadResource(inputResource, inputHref, hrefMode, inputResourceIndex, var href=$(element).children().filterNsNode('href').text(); if(href.match(RegExp('^https?://','i'))!=null) { - var tmpH = href.match(RegExp('^(https?://)([^/]+)(.*)','i')) + var tmpH = algoo_replace_regex(href, globalAccountSettings); if(tmpH!=null) href = tmpH[3]; } @@ -1898,8 +1895,7 @@ function netLoadResource(inputResource, inputHref, hrefMode, inputResourceIndex, }// Save the client settings (stored as DAV property on server) function netSaveSettings(inputResource, inputSettings, isFormSave, collectionLoad) { - var re=new RegExp('^(https?://)([^/]+)(.*)', 'i'); - var tmp=inputResource.href.match(re); + var tmp = algoo_replace_regex(inputResource.href, globalAccountSettings); var baseHref=tmp[1]+tmp[2]; var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]; var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; //for the error handler diff --git a/tracim/tracim/templates/calendar/config.mak b/tracim/tracim/templates/calendar/config.mak index f79ac58e2b..8fdce213b9 100644 --- a/tracim/tracim/templates/calendar/config.mak +++ b/tracim/tracim/templates/calendar/config.mak @@ -15,7 +15,8 @@ var globalAccountSettings=[ delegation: false, forceReadOnly: null, ignoreAlarms: false, - backgroundCalendars: ['1.ics'] + backgroundCalendars: [], + basehref: '${base_href_url}' }, % if workspace_clendar_urls: { @@ -32,7 +33,8 @@ var globalAccountSettings=[ delegation: false, forceReadOnly: null, ignoreAlarms: false, - backgroundCalendars: [] + backgroundCalendars: [], + basehref: '${base_href_url}' }, % endif ] ; diff --git a/uppgrade_caldavzap.sh b/uppgrade_caldavzap.sh index b96ecdce2b..b164e4ac0d 100755 --- a/uppgrade_caldavzap.sh +++ b/uppgrade_caldavzap.sh @@ -6,4 +6,4 @@ then rm -r tracim/tracim/public/caldavzap fi git clone https://github.com/algoo/caldavzap.git tracim/tracim/public/caldavzap -rm -r tracim/tracim/public/caldavzap/.git +rm -rf tracim/tracim/public/caldavzap/.git