webdav_protocol.js 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310
  1. /*
  2. CardDavMATE - the open source CardDAV Web Client
  3. Copyright (C) 2011-2015
  4. Jan Mate <jan.mate@inf-it.com>
  5. Andrej Lezo <andrej.lezo@inf-it.com>
  6. Matej Mihalik <matej.mihalik@inf-it.com>
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU Affero General Public License as
  9. published by the Free Software Foundation, either version 3 of the
  10. License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // VersionCheck (check for new version)
  19. function netVersionCheck()
  20. {
  21. $.ajax({
  22. type: 'GET',
  23. url: globalVersionCheckURL,
  24. cache: false,
  25. crossDomain: false,
  26. timeout: 30000,
  27. beforeSend: function(req) {
  28. req.setRequestHeader('X-client', globalXClientHeader);
  29. },
  30. contentType: 'text/xml; charset=utf-8',
  31. processData: true,
  32. data: '',
  33. dataType: 'xml',
  34. error: function(objAJAXRequest, strError){
  35. console.log("Error: [netVersionCheck: 'GET "+globalVersionCheckURL+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'");
  36. return false;
  37. },
  38. success: function(data, textStatus, xml)
  39. {
  40. var count=0;
  41. var tmp=$(xml.responseXML).find('updates').find(globalAppName.toLowerCase());
  42. var type=tmp.attr('type');
  43. var home=tmp.attr('homeURL');
  44. var version_txt=tmp.attr('version');
  45. var build_no_txt=(typeof globalEnableDevelBuilds=='undefined' || globalEnableDevelBuilds!=true ? tmp.attr('build_no') : tmp.attr('dev_build_no'));
  46. if(type==undefined || type=='' || home==undefined || home=='' || version_txt==undefined || version_txt=='' || build_no_txt==undefined || build_no_txt=='')
  47. return false;
  48. var build_no=build_no_txt.match(RegExp('^([0-9]+)$'));
  49. if(build_no==null)
  50. return false;
  51. if(globalBuildNo<parseInt(build_no[1]))
  52. {
  53. var showNofication=false;
  54. if(globalNewVersionNotifyUsers.length==0)
  55. showNofication=true;
  56. else
  57. {
  58. for(var i=0;i<globalAccountSettings.length;i++)
  59. if(globalNewVersionNotifyUsers.indexOf(globalAccountSettings[i].userAuth.userName)!=-1)
  60. {
  61. showNofication=true;
  62. break;
  63. }
  64. }
  65. if(showNofication==true)
  66. {
  67. $('div.update_h').html(localization[globalInterfaceLanguage].updateNotification.replace('%name%',globalAppName).replace('%new_ver%','<span id="newversion" class="update_h"></span>').replace('%curr_ver%', '<span id="version" class="update_h"></span>').replace('%url%', '<span id="homeurl" class="update_h" onclick=""></span>'));
  68. $('div.update_h').find('span#version').text(globalVersion);
  69. $('div.update_h').find('span#newversion').text(version_txt);
  70. $('div.update_h').find('span#homeurl').attr('onclick','window.open(\''+home+'\')');
  71. $('div.update_h').find('span#homeurl').text(home);
  72. setTimeout(function(){
  73. var orig_width=$('div.update_d').width();
  74. $('div.update_d').css('width', '0px');
  75. $('div.update_d').css('display','');
  76. $('div.update_d').animate({width: '+='+orig_width+'px'}, 500);
  77. }, 5000);
  78. }
  79. }
  80. }
  81. });
  82. }
  83. // Load the configuration from XML file
  84. function netCheckAndCreateConfiguration(configurationURL)
  85. {
  86. $.ajax({
  87. type: 'PROPFIND',
  88. url: configurationURL.href,
  89. cache: false,
  90. crossDomain: (typeof configurationURL.crossDomain=='undefined' ? true : configurationURL.crossDomain),
  91. xhrFields: {
  92. withCredentials: (typeof configurationURL.withCredentials=='undefined' ? false : configurationURL.withCredentials)
  93. },
  94. timeout: configurationURL.timeOut,
  95. beforeSend: function(req){
  96. if(globalSettings.usejqueryauth.value!=true && globalLoginUsername!='' && globalLoginPassword!='')
  97. req.setRequestHeader('Authorization', basicAuth(globalLoginUsername,globalLoginPassword));
  98. req.setRequestHeader('X-client', globalXClientHeader);
  99. req.setRequestHeader('Depth', '0');
  100. },
  101. username: (globalSettings.usejqueryauth.value==true ? globalLoginUsername : null),
  102. password: (globalSettings.usejqueryauth.value==true ? globalLoginPassword : null),
  103. contentType: 'text/xml; charset=utf-8',
  104. processData: true,
  105. data: '<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop><D:current-user-principal/></D:prop></D:propfind>',
  106. dataType: 'xml',
  107. error: function(objAJAXRequest, strError){
  108. console.log("Error: [netCheckAndCreateConfiguration: 'PROPFIND "+configurationURL.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  109. $('#LoginLoader').fadeOut(1200);
  110. return false;
  111. },
  112. success: function(data, textStatus, xml)
  113. {
  114. var count=0;
  115. if($(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('status').text().match(RegExp('200 OK$')))
  116. {
  117. if(typeof globalAccountSettings=='undefined')
  118. globalAccountSettings=[];
  119. globalAccountSettings[globalAccountSettings.length]=$.extend({}, configurationURL);
  120. globalAccountSettings[globalAccountSettings.length-1].type='network';
  121. if(typeof(globalAccountSettingsHook)=='function') // Hook for globalAccountSettings (openCRX)
  122. globalAccountSettings[globalAccountSettings.length-1].href=globalAccountSettingsHook(configurationURL.href, globalLoginUsername);
  123. else // standard version
  124. globalAccountSettings[globalAccountSettings.length-1].href=configurationURL.href+globalLoginUsername+'/';
  125. globalAccountSettings[globalAccountSettings.length-1].userAuth={userName: globalLoginUsername, userPassword: globalLoginPassword};
  126. count++;
  127. if(configurationURL.additionalResources!=undefined && configurationURL.additionalResources.length>0)
  128. {
  129. for(var i=0;i<configurationURL.additionalResources.length;i++)
  130. {
  131. if(globalLoginUsername!=configurationURL.additionalResources[i])
  132. {
  133. globalAccountSettings[globalAccountSettings.length]=$.extend({}, configurationURL);
  134. globalAccountSettings[globalAccountSettings.length-1].type='network';
  135. globalAccountSettings[globalAccountSettings.length-1].href=configurationURL.href+configurationURL.additionalResources[i]+'/';
  136. globalAccountSettings[globalAccountSettings.length-1].userAuth={userName: globalLoginUsername, userPassword: globalLoginPassword};
  137. count++;
  138. }
  139. }
  140. }
  141. }
  142. if(count)
  143. {
  144. if(globalAccountSettings[0].delegation)
  145. DAVresourceDelegation(globalAccountSettings[0], 0, 0);
  146. else
  147. {
  148. // start the client
  149. if(isAvaible('CardDavMATE'))
  150. runCardDAV();
  151. if(isAvaible('CalDavZAP'))
  152. runCalDAV();
  153. if(isAvaible('Projects'))
  154. runProjects();
  155. if(isAvaible('Settings'))
  156. runSettings();
  157. globalResourceNumber=globalAccountSettings.length;
  158. loadAllResources();
  159. }
  160. }
  161. else
  162. $('#LoginLoader').fadeOut(1200);
  163. }
  164. });
  165. }
  166. // Load the configuration from XML file
  167. function netLoadConfiguration(configurationURL)
  168. {
  169. $.ajax({
  170. type: 'GET',
  171. url: configurationURL.href+'?browser_date='+$.datepicker.formatDate("yyyy-MM-dd", new Date())+(ignoreServerSettings==true ? '&ignore_settings=1' : ''),
  172. cache: false,
  173. crossDomain: (typeof configurationURL.crossDomain=='undefined' ? true : configurationURL.crossDomain),
  174. xhrFields: {
  175. withCredentials: (typeof configurationURL.withCredentials=='undefined' ? false : configurationURL.withCredentials)
  176. },
  177. timeout: configurationURL.timeOut,
  178. beforeSend: function(req) {
  179. if(globalSettings.usejqueryauth.value!=true && globalLoginUsername!='' && globalLoginPassword!='')
  180. req.setRequestHeader('Authorization', basicAuth(globalLoginUsername,globalLoginPassword));
  181. req.setRequestHeader('X-client', globalXClientHeader);
  182. },
  183. username: (globalSettings.usejqueryauth.value==true ? globalLoginUsername : null),
  184. password: (globalSettings.usejqueryauth.value==true ? globalLoginPassword : null),
  185. contentType: 'text/xml; charset=utf-8',
  186. processData: true,
  187. data: '',
  188. dataType: 'xml',
  189. error: function(objAJAXRequest, strError){
  190. console.log("Error: [loadConfiguration: 'GET "+configurationURL.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  191. $('#LoginLoader').fadeOut(1200);
  192. return false;
  193. },
  194. success: function(data, textStatus, xml)
  195. {
  196. if(typeof globalAccountSettings=='undefined')
  197. globalAccountSettings=[];
  198. var count=0;
  199. var rex=new RegExp('^re(\\|[^:]*|):(.+)$');
  200. $(xml.responseXML).children('resources').children('resource').each(
  201. function(index, element)
  202. {
  203. if($(element).children().filterNsNode('type').children().filterNsNode('addressbook').length==1 || $(element).children().filterNsNode('type').children().filterNsNode('calendar').length==1)
  204. {
  205. // numeric/text options
  206. var href=$(element).children('href').text();
  207. var tmp=$(element).children('hreflabel').text();
  208. var hreflabel=(tmp!='' && tmp!='null' ? tmp : null);
  209. var username=$(element).children('userauth').children('username').text();
  210. var password=$(element).children('userauth').children('password').text();
  211. var timeout=$(element).children('timeout').text();
  212. var locktimeout=$(element).children('locktimeout').text();
  213. // array options
  214. var collectionTypes=new Array();
  215. if($(element).children().filterNsNode('type').children().filterNsNode('addressbook').length==1)
  216. collectionTypes[collectionTypes.length]='addressbook';
  217. if($(element).children().filterNsNode('type').children().filterNsNode('calendar').length==1)
  218. collectionTypes[collectionTypes.length]='calendar';
  219. // boolean options
  220. var tmp=$(element).children('withcredentials').text();
  221. var withcredentials=((tmp=='true' || tmp=='yes' || tmp=='1') ? true : false);
  222. var tmp=$(element).children('crossdomain').text();
  223. var crossdomain=((tmp=='false' || tmp=='no' || tmp=='0') ? false : true);
  224. var tmp=$(element).find('settingsaccount').text();
  225. var settingsaccount=((tmp=='true' || tmp=='yes' || tmp=='1') ? true : false);
  226. var tmp=$(element).find('checkcontenttype').text();
  227. var checkcontenttype=((tmp=='false' || tmp=='no' || tmp=='0') ? false : true);
  228. var tmp=$(element).find('ignorebound').text();
  229. var ignorebound=((tmp=='true' || tmp=='yes' || tmp=='1') ? true : false);
  230. // special options
  231. var forcereadonly=null;
  232. var tmp=$(element).children('forcereadonly');
  233. if(tmp.text()=='true')
  234. var forcereadonly=true;
  235. else
  236. {
  237. var tmp_ro=[];
  238. tmp.children('collection').each(
  239. function(index, element)
  240. {
  241. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  242. tmp_ro[tmp_ro.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  243. else
  244. tmp_ro[tmp_ro.length]=$(element).text();
  245. }
  246. );
  247. if(tmp_ro.length>0)
  248. var forcereadonly=tmp_ro;
  249. }
  250. var delegation=false;
  251. var tmp=$(element).children('delegation');
  252. if(tmp.text()=='true')
  253. var delegation=true;
  254. else
  255. {
  256. var tmp_de=[];
  257. tmp.children('resource').each(
  258. function(index, element)
  259. {
  260. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  261. tmp_de[tmp_de.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  262. else
  263. tmp_de[tmp_de.length]=$(element).text();
  264. }
  265. );
  266. if(tmp_de.length>0)
  267. var delegation=tmp_de;
  268. }
  269. var extendedDelegation=false;
  270. var tmp=$(element).children('extendeddelegation');
  271. if(tmp.text()=='true')
  272. extendedDelegation=true;
  273. var ignoreAlarms=false;
  274. var tmp=$(element).children('ignorealarms');
  275. if(tmp.text()=='true')
  276. var ignoreAlarms=true;
  277. else
  278. {
  279. var tmp_ia=[];
  280. tmp.children('collection').each(
  281. function(index, element)
  282. {
  283. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  284. tmp_ia[tmp_ia.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  285. else
  286. tmp_ia[tmp_ia.length]=$(element).text();
  287. }
  288. );
  289. if(tmp_ia.length>0)
  290. var ignoreAlarms=tmp_ia;
  291. }
  292. var backgroundCalendars=[];
  293. var tmp=$(element).children('backgroundcalendars');
  294. if(tmp.text()!='')
  295. {
  296. tmp.children('collection').each(
  297. function(index, element)
  298. {
  299. if((matched=$(element).text().match(rex))!=null && matched.length==3)
  300. backgroundCalendars[backgroundCalendars.length]=new RegExp(matched[2], matched[1].substring(matched[1].length>0 ? 1 : 0));
  301. else
  302. backgroundCalendars[backgroundCalendars.length]=$(element).text();
  303. }
  304. );
  305. }
  306. globalAccountSettings[globalAccountSettings.length]={type: 'network', href: href, hrefLabel: hreflabel, crossDomain: crossdomain, settingsAccount: settingsaccount, checkContentType: checkcontenttype, forceReadOnly: forcereadonly, withCredentials: withcredentials, userAuth: {userName: username, userPassword: password}, timeOut: timeout, lockTimeOut: locktimeout, delegation: delegation, extendedDelegation: extendedDelegation, ignoreAlarms: ignoreAlarms, backgroundCalendars: backgroundCalendars, collectionTypes: collectionTypes, ignoreBound: ignorebound};
  307. count++;
  308. }
  309. }
  310. );
  311. if(count)
  312. {
  313. // store the pre-cached data for the client
  314. var tmp=$(xml.responseXML).children('resources').children('cache_data');
  315. if(tmp.length)
  316. globalXMLCache=tmp;
  317. if(globalAccountSettings[0].delegation)
  318. DAVresourceDelegation(globalAccountSettings[0], 0, 0);
  319. else
  320. {
  321. // start the client
  322. if(isAvaible('CardDavMATE'))
  323. {
  324. runCardDAV();
  325. }
  326. if(isAvaible('CalDavZAP'))
  327. runCalDAV();
  328. if(isAvaible('Projects'))
  329. runProjects();
  330. if(isAvaible('Settings'))
  331. runSettings();
  332. globalResourceNumber = globalAccountSettings.length;
  333. loadAllResources();
  334. }
  335. }
  336. else
  337. $('#LoginLoader').fadeOut(1200);
  338. }
  339. });
  340. }
  341. // Save the collection property (stored as DAV property on server)
  342. function netSaveProperty(inputCollection, hrefProperty, inputProperty, inputValue)
  343. {
  344. var dataXML = '<?xml version="1.0" encoding="utf-8"?><D:propertyupdate xmlns:D="DAV:"><D:set><D:prop><I:'+inputProperty+' xmlns:I="'+hrefProperty+'">'+inputValue+'</I:'+inputProperty+'></D:prop></D:set></D:propertyupdate>';
  345. $.ajax({
  346. type: 'PROPPATCH',
  347. url: inputCollection.url+inputCollection.href,
  348. cache: false,
  349. crossDomain: (typeof inputCollection.crossDomain=='undefined' ? true: inputCollection.crossDomain),
  350. xhrFields: {
  351. withCredentials: (typeof inputCollection.withCredentials=='undefined' ? false: inputCollection.withCredentials)
  352. },
  353. timeout: inputCollection.timeOut,
  354. beforeSend: function(req){
  355. if(globalSettings.usejqueryauth.value!=true && inputCollection.userAuth.userName!='' && inputCollection.userAuth.userPassword!='')
  356. req.setRequestHeader('Authorization', basicAuth(inputCollection.userAuth.userName, inputCollection.userAuth.userPassword));
  357. req.setRequestHeader('X-client', globalXClientHeader);
  358. req.setRequestHeader('Depth', '0');
  359. },
  360. username: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userName : null),
  361. password: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userPassword : null),
  362. contentType: 'text/xml',
  363. processData: true,
  364. data: dataXML,
  365. dataType: 'xml',
  366. error: function(objAJAXRequest, strError){
  367. console.log("Error: [netSaveProperty: 'PROPPATCH "+inputCollection.url+inputCollection.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' (this error code usually means network connection error, or your browser is trying to make a cross domain query, but it is not allowed by the destination server or the browser itself)': ''));
  368. if(inputProperty=='calendar-color')
  369. {
  370. if(inputCollection.listType=='vevent')
  371. {
  372. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',inputCollection.ecolor);
  373. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',inputCollection.ecolor);
  374. }
  375. else
  376. {
  377. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',inputCollection.ecolor);
  378. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',inputCollection.ecolor);
  379. }
  380. }
  381. else if(inputProperty=='addressbook-color')
  382. {
  383. $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCardDAVColor').css('background',inputCollection.color);
  384. $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',inputCollection.color);
  385. }
  386. return false;
  387. },
  388. success: function(data, textStatus, xml)
  389. {
  390. var color;
  391. if(inputProperty=='calendar-color')
  392. {
  393. var secondColl = null;
  394. if(inputCollection.listType=='vevent')
  395. {
  396. color = $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('get').toHexString();
  397. if(inputCollection.fcSource!=null)
  398. {
  399. inputCollection.fcSource.backgroundColor=hexToRgba(color,0.9);
  400. inputCollection.fcSource.borderColor=color;
  401. inputCollection.fcSource.textColor=checkFontColor(color);
  402. }
  403. secondColl = globalResourceCalDAVList.getTodoCollectionByUID(inputCollection.uid);
  404. if(secondColl!=null)
  405. {
  406. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',color);
  407. $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',color);
  408. if(secondColl.fcSource!=null)
  409. {
  410. secondColl.fcSource.backgroundColor=hexToRgba(color,0.9);
  411. secondColl.fcSource.borderColor=color;
  412. }
  413. }
  414. }
  415. else
  416. {
  417. color = $('#ResourceCalDAVTODOList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('get').toHexString();
  418. if(inputCollection.fcSource!=null)
  419. {
  420. inputCollection.fcSource.backgroundColor=hexToRgba(color,0.9);
  421. inputCollection.fcSource.borderColor=color;
  422. }
  423. secondColl = globalResourceCalDAVList.getEventCollectionByUID(inputCollection.uid);
  424. if(secondColl!=null)
  425. {
  426. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.resourceCalDAVColor').css('background',color);
  427. $('#ResourceCalDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('set',color);
  428. if(secondColl.fcSource!=null)
  429. {
  430. secondColl.fcSource.backgroundColor=hexToRgba(color,0.9);
  431. secondColl.fcSource.borderColor=color;
  432. secondColl.fcSource.textColor=checkFontColor(color);
  433. }
  434. }
  435. }
  436. inputCollection.ecolor = color;
  437. if(secondColl!=null)
  438. secondColl.ecolor = color;
  439. if(inputCollection.listType=='vevent' || secondColl!=null)
  440. $('#calendar').fullCalendar('refetchEvents');
  441. if(inputCollection.listType=='vtodo' || secondColl!=null)
  442. $('#todoList').fullCalendar('refetchEvents');
  443. }
  444. else if(inputProperty=='addressbook-color')
  445. {
  446. color = $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').find('.colorPicker').spectrum('get').toHexString();
  447. inputCollection.color = color;
  448. if($('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').parent().find('.contact_group').find('div[data-id]').length>0)
  449. $('#ResourceCardDAVList').find('[data-id="'+inputCollection.uid+'"]').parent().find('.contact_group').find('div[data-id]').find('.resourceCardDAVGroupColor').css('background',color);
  450. globalAddressbookList.applyABFilter(dataGetChecked('#ResourceCardDAVList'), false);
  451. var selUID = $('#vCardEditor').find('[data-attr-name="_DEST_"]').find('option:selected').attr('data-type');
  452. var selColl=globalResourceCardDAVList.getCollectionByUID(selUID);
  453. $('#ABContactColor').css('background-color', selColl.color);
  454. }
  455. }
  456. });
  457. }
  458. function DAVresourceDelegation(inputResource, index, lastIndex)
  459. {
  460. globalCalDAVResourceSync=false;
  461. var re=new RegExp('^(https?://)([^/]+)(.*)', 'i');
  462. var tmp=inputResource.href.match(re);
  463. var baseHref=tmp[1]+tmp[2];
  464. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  465. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; //for the error handler
  466. var settingsXML='';
  467. var delegationXML='';
  468. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation)
  469. {
  470. if(inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  471. settingsXML = '<D:property name="settings" namespace="http://inf-it.com/ns/dav/"/>';
  472. delegationXML='<?xml version="1.0" encoding="utf-8"?><D:expand-property xmlns:D="DAV:"><D:property name="calendar-proxy-read-for" namespace="http://calendarserver.org/ns/"><D:property name="resourcetype"/><D:property name="current-user-privilege-set"/><D:property name="displayname"/><D:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="calendar-home-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="addressbook-home-set" namespace="urn:ietf:params:xml:ns:carddav"/></D:property><D:property name="calendar-proxy-write-for" namespace="http://calendarserver.org/ns/"><D:property name="resourcetype"/><D:property name="current-user-privilege-set"/><D:property name="displayname"/><D:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="calendar-home-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="addressbook-home-set" namespace="urn:ietf:params:xml:ns:carddav"/></D:property>'+settingsXML+'<D:property name="resourcetype"/><D:property name="current-user-privilege-set"/><D:property name="displayname"/><D:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="calendar-home-set" namespace="urn:ietf:params:xml:ns:caldav"/><D:property name="addressbook-home-set" namespace="urn:ietf:params:xml:ns:carddav"/></D:expand-property>';
  473. }
  474. else
  475. delegationXML='<?xml version="1.0" encoding="utf-8"?><A:expand-property xmlns:A="DAV:"><A:property name="calendar-proxy-read-for" namespace="http://calendarserver.org/ns/"><A:property name="email-address-set" namespace="http://calendarserver.org/ns/"/><A:property name="displayname" namespace="DAV:"/><A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/></A:property><A:property name="calendar-proxy-write-for" namespace="http://calendarserver.org/ns/"><A:property name="email-address-set" namespace="http://calendarserver.org/ns/"/><A:property name="displayname" namespace="DAV:"/><A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/></A:property></A:expand-property>';
  476. function ajaxComplete(data, textStatus, xml)
  477. {
  478. if(typeof globalAccountSettings=='undefined')
  479. globalAccountSettings=[];
  480. var hostPart=tmp[1]+tmp[2];
  481. var propElement=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop');
  482. var searchR=new Array();
  483. searchR[searchR.length]=$(propElement).children().filterNsNode('calendar-proxy-read-for');
  484. searchR[searchR.length]=$(propElement).children().filterNsNode('calendar-proxy-write-for');
  485. for(var m=0; m<searchR.length; m++)
  486. {
  487. searchR[m].children().filterNsNode('response').each(
  488. function(dindex,delement){
  489. var href = $(delement).children().filterNsNode('href').text();
  490. var found=false;
  491. for(var i=0; i<globalAccountSettings.length; i++)
  492. if(decodeURIComponent(globalAccountSettings[i].href)==(hostPart+href))
  493. found=true;
  494. if(!found)
  495. {
  496. globalAccountSettings[globalAccountSettings.length]=$.extend({}, inputResource);
  497. globalAccountSettings[globalAccountSettings.length-1].type=inputResource.type;
  498. globalAccountSettings[globalAccountSettings.length-1].href=decodeURIComponent(hostPart+href);
  499. globalAccountSettings[globalAccountSettings.length-1].userAuth={userName: inputResource.userAuth.userName, userPassword: inputResource.userAuth.userPassword};
  500. }
  501. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation)
  502. {
  503. $(delement).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-user-address-set').children().each(
  504. function(ind, elm)
  505. {
  506. var pHref = $(elm).text();
  507. if(pHref.indexOf('mailto:')!=-1)
  508. globalAccountSettings[globalAccountSettings.length-1].principalEmail=pHref.split('mailto:')[1];
  509. });
  510. var addressbook_home=$(delement).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('addressbook-home-set').children().filterNsNode('href').text();
  511. if(addressbook_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  512. addressbook_home=$(delement).children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  513. if(addressbook_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  514. globalAccountSettings[globalAccountSettings.length-1].abhref=addressbook_home;
  515. else // relative URL returned
  516. globalAccountSettings[globalAccountSettings.length-1].abhref=baseHref+addressbook_home;
  517. var calendar_home=$(delement).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-home-set').children().filterNsNode('href').text();
  518. if(calendar_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  519. calendar_home=$(delement).children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  520. if(calendar_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  521. globalAccountSettings[globalAccountSettings.length-1].cahref=calendar_home;
  522. else // relative URL returned
  523. globalAccountSettings[globalAccountSettings.length-1].cahref=baseHref+calendar_home;
  524. }
  525. });
  526. }
  527. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation && !settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  528. {
  529. var settings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  530. if(settings!='')
  531. {
  532. if(!ignoreServerSettings)
  533. loadSettings(settings, true, false);
  534. else
  535. {
  536. delete globalSettings.version.value;
  537. loadSettings(JSON.stringify(globalSettings), false, false);
  538. console.log('Ignoring server settings: '+'\n'+settings);
  539. }
  540. }
  541. else
  542. {
  543. delete globalSettings.version.value;
  544. loadSettings(JSON.stringify(globalSettings), false, false);
  545. }
  546. }
  547. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation)
  548. {
  549. var response=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response');
  550. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-user-address-set').children().each(
  551. function(ind, elm)
  552. {
  553. var pHref = $(elm).text();
  554. if(pHref.indexOf('mailto:')!=-1)
  555. inputResource.principalEmail=pHref.split('mailto:')[1];
  556. });
  557. if(globalEmailAddress==''&&typeof inputResource.principalEmail!= 'undefined')
  558. globalEmailAddress=inputResource.principalEmail;
  559. var addressbook_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('addressbook-home-set').children().filterNsNode('href').text();
  560. if(addressbook_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  561. addressbook_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  562. if(addressbook_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  563. inputResource.abhref=addressbook_home;
  564. else // relative URL returned
  565. inputResource.abhref=baseHref+addressbook_home;
  566. var calendar_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-home-set').children().filterNsNode('href').text();
  567. if(calendar_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  568. calendar_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  569. if(calendar_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  570. inputResource.cahref=calendar_home;
  571. else // relative URL returned
  572. inputResource.cahref=baseHref+calendar_home;
  573. }
  574. if(index==lastIndex)
  575. {
  576. // start the client
  577. if(isAvaible('CardDavMATE'))
  578. runCardDAV();
  579. if(isAvaible('CalDavZAP'))
  580. runCalDAV();
  581. if(isAvaible('Projects'))
  582. runProjects();
  583. if(isAvaible('Settings'))
  584. runSettings();
  585. globalResourceNumber=globalAccountSettings.length;
  586. loadAllResources();
  587. }
  588. }
  589. // first try to process the cached data (if cached results are available in the "auth module" response)
  590. var tmpCache;
  591. var tmpDav = inputResource.href.match('^(.*/)([^/]+)/$');
  592. if(globalXMLCache!=null && (tmpCache=globalXMLCache.children('davprincipaldelegation[request_url="'+jqueryEscapeSelector(tmpDav[1]+encodeURIComponent(tmpDav[2])+'/')+'"]').remove()).length)
  593. {
  594. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  595. console.log('DBG Cache OK: '+arguments.callee.name+' url: \''+inputResource.href+'\': saved one request!');
  596. ajaxComplete('', 'success', {responseXML: tmpCache});
  597. }
  598. else
  599. {
  600. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  601. console.log('DBG Cache ERROR: '+arguments.callee.name+' url: \''+inputResource.href+'\': spend one request!');
  602. $.ajax({
  603. type: 'REPORT',
  604. url: inputResource.href,
  605. cache: false,
  606. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true: inputResource.crossDomain),
  607. xhrFields:
  608. {
  609. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false: inputResource.withCredentials)
  610. },
  611. timeout: inputResource.timeOut,
  612. beforeSend: function(req)
  613. {
  614. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  615. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName, inputResource.userAuth.userPassword));
  616. req.setRequestHeader('X-client', globalXClientHeader);
  617. req.setRequestHeader('Depth', '0');
  618. },
  619. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  620. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  621. contentType: 'text/xml',
  622. processData: true,
  623. data: delegationXML,
  624. dataType: 'xml',
  625. error: function(objAJAXRequest, strError)
  626. {
  627. console.log("Error: [DAVresourceDelegation: 'REPORT "+uidFull+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' (this error code usually means network connection error, or your browser is trying to make a cross domain query, but it is not allowed by the destination server or the browser itself)': ''));
  628. },
  629. success: ajaxComplete
  630. });
  631. }
  632. }
  633. function netFindResource(inputResource, inputResourceIndex, forceLoad, indexR, loadArray)
  634. {
  635. if(globalPreventLogoutSync)
  636. {
  637. logout(true);
  638. return false;
  639. }
  640. if(indexR<globalAccountSettings.length)
  641. {
  642. globalResourceNumberCount++;
  643. if((isAvaible('CardDavMATE') && globalCardDAVInitLoad) || (isAvaible('CalDavZAP') && globalCalDAVInitLoad) || (isAvaible('Projects') && !isProjectsLoaded) || (isAvaible('Settings') && !isSettingsLoaded))
  644. $('#MainLoaderInner').html(localization[globalInterfaceLanguage].loadingResources.replace('%act%', globalResourceNumberCount).replace('%total%', globalResourceNumber));
  645. }
  646. if((typeof inputResource!='undefined' && typeof inputResource.collectionTypes!='undefined' && inputResource.collectionTypes!=null && (inputResource.collectionTypes.indexOf('calendar')==-1) && inputResource.collectionTypes.indexOf('addressbook')==-1) || (typeof inputResource!='undefined' && typeof loadArray!='undefined' && loadArray!=null && loadArray.indexOf(inputResource.href)==-1))
  647. {
  648. indexR++;
  649. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  650. return false;
  651. }
  652. if(indexR>=globalAccountSettings.length && settingsLoaded)
  653. {
  654. if(globalResourceIntervalID==null)
  655. globalResourceIntervalID=setInterval(reloadResources, globalSettings.syncresourcesinterval.value);
  656. globalCalDAVResourceSync=false;
  657. globalCardDAVResourceSync=false;
  658. globalSyncSettingsSave=false;
  659. var rexo=new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)');
  660. var rex=new RegExp('^(https?://)(.*)', 'i');
  661. var accRex=new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)', 'i');
  662. if((isAvaible('CalDavZAP') && !isCalDAVLoaded) || (isAvaible('CardDavMATE') && !isCardDAVLoaded))
  663. {
  664. if(isAvaible('CalDavZAP'))
  665. {
  666. if(!globalDefaultCalendarCollectionActiveAll)
  667. {
  668. for(var i=0; i<globalSettings.activecalendarcollections.value.length; i++)
  669. {
  670. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  671. {
  672. var tmpParts2=globalSettings.activecalendarcollections.value[i].match('^(.*/)([^/]+)/([^/]+)/$');
  673. var checkHref2=tmpParts2[2]+'/'+tmpParts2[3]+'/';
  674. if($('#ResourceCalDAVList input[data-id$="'+checkHref2+'"]:visible').length>0)
  675. {
  676. var elm=$('#ResourceCalDAVList input[data-id$="'+checkHref2+'"]');
  677. elm.trigger('click');
  678. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, elm.attr('data-id'));
  679. }
  680. }
  681. else
  682. {
  683. var uidPart=globalSettings.activecalendarcollections.value[i].match(rex)[1];
  684. var uidPart2=globalSettings.activecalendarcollections.value[i].match(rex)[2];
  685. if(globalLoginUsername!='')
  686. var uidPart3=globalLoginUsername;
  687. else
  688. var uidPart3=globalAccountSettings[0].userAuth.userName;
  689. var uid = uidPart+uidPart3+'@'+uidPart2;
  690. if($('#ResourceCalDAVList input[data-id="'+uid+'"]:visible').length>0)
  691. {
  692. $('#ResourceCalDAVList input[data-id="'+uid+'"]').trigger('click');
  693. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, uid);
  694. }
  695. }
  696. }
  697. if(globalSettings.activecalendarcollections.value.length>0 && globalVisibleCalDAVCollections.length==0)
  698. globalDefaultCalendarCollectionActiveAll=true;
  699. }
  700. if(globalDefaultCalendarCollectionActiveAll)
  701. for(var i=0; i<globalResourceCalDAVList.collections.length; i++)
  702. {
  703. if(globalResourceCalDAVList.collections[i].uid!=undefined && $('#ResourceCalDAVList input[data-id="'+globalResourceCalDAVList.collections[i].uid+'"]:visible').length>0)
  704. {
  705. $('#ResourceCalDAVList input[data-id="'+globalResourceCalDAVList.collections[i].uid+'"]').trigger('click');
  706. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, globalResourceCalDAVList.collections[i].uid);
  707. }
  708. }
  709. if(!globalDefaultTodoCalendarCollectionActiveAll)
  710. {
  711. for(var i=0; i<globalSettings.activetodocollections.value.length; i++)
  712. {
  713. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  714. {
  715. var tmpParts2=globalSettings.activetodocollections.value[i].match('^(.*/)([^/]+)/([^/]+)/$');
  716. var checkHref2=tmpParts2[2]+'/'+tmpParts2[3]+'/';
  717. if($('#ResourceCalDAVTODOList input[data-id$="'+checkHref2+'"]:visible').length>0)
  718. {
  719. var elm=$('#ResourceCalDAVTODOList input[data-id$="'+checkHref2+'"]');
  720. elm.trigger('click');
  721. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, elm.attr('data-id'));
  722. }
  723. }
  724. else
  725. {
  726. var uidPart=globalSettings.activetodocollections.value[i].match(rex)[1];
  727. var uidPart2=globalSettings.activetodocollections.value[i].match(rex)[2];
  728. if(globalLoginUsername!='')
  729. var uidPart3=globalLoginUsername;
  730. else
  731. var uidPart3=globalAccountSettings[0].userAuth.userName;
  732. var uid=uidPart+uidPart3+'@'+uidPart2;
  733. if($('#ResourceCalDAVTODOList input[data-id="'+uid+'"]:visible').length>0)
  734. {
  735. $('#ResourceCalDAVTODOList input[data-id="'+uid+'"]').trigger('click');
  736. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, uid);
  737. }
  738. }
  739. }
  740. if(globalSettings.activetodocollections.value.length>0 && globalVisibleCalDAVTODOCollections.length==0)
  741. globalDefaultTodoCalendarCollectionActiveAll=true;
  742. }
  743. if(globalDefaultTodoCalendarCollectionActiveAll)
  744. for(var i=0; i<globalResourceCalDAVList.TodoCollections.length; i++)
  745. {
  746. if(globalResourceCalDAVList.TodoCollections[i].uid!=undefined && $('#ResourceCalDAVTODOList input[data-id="'+globalResourceCalDAVList.TodoCollections[i].uid+'"]:visible').length>0)
  747. {
  748. $('#ResourceCalDAVTODOList input[data-id="'+globalResourceCalDAVList.TodoCollections[i].uid+'"]').trigger('click');
  749. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, globalResourceCalDAVList.TodoCollections[i].uid);
  750. }
  751. }
  752. if($('#ResourceCalDAVList .resourceCalDAV_item[data-id]:visible').length==0 && globalResourceCalDAVList.collections.length>1)
  753. {
  754. var enabledArray=new Array();
  755. for(var c=0; c<globalResourceCalDAVList.collections.length; c++)
  756. if(globalResourceCalDAVList.collections[c].uid!=undefined)
  757. {
  758. var tmp=globalResourceCalDAVList.collections[c].accountUID.match(accRex);
  759. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  760. if(globalAccountSettings[0].href==resourceCalDAV_href && globalAccountSettings[0].userAuth.userName==globalResourceCalDAVList.collections[c].userAuth.userName)
  761. enabledArray.push(globalResourceCalDAVList.collections[c]);
  762. }
  763. if(enabledArray.length==0)
  764. enabledArray.push(globalResourceCalDAVList.collections[1]);
  765. for(var c=0; c<enabledArray.length; c++)
  766. {
  767. enabledArray[c].makeLoaded=true;
  768. var uidParts=enabledArray[c].uid.match(rexo);
  769. globalSettings.loadedcalendarcollections.value.push(uidParts[1]+uidParts[3]);
  770. var resDOMItem=$('#ResourceCalDAVList').find('.resourceCalDAV_item[data-id="'+jqueryEscapeSelector(enabledArray[c].uid)+'"]');
  771. var resDOMHeader=resDOMItem.prevUntil('.resourceCalDAV_header').last().prev();
  772. if(!resDOMHeader.length)
  773. resDOMHeader=resDOMItem.prev();
  774. resDOMHeader.css('display','block');
  775. resDOMItem.css('display','');
  776. resDOMItem.find('input[type=checkbox]').not('.unloadCheck').trigger('click');
  777. globalVisibleCalDAVCollections.splice(globalVisibleCalDAVCollections.length, 0, enabledArray[c].uid);
  778. }
  779. }
  780. if($('#ResourceCalDAVTODOList .resourceCalDAVTODO_item[data-id]:visible').length==0 && globalResourceCalDAVList.TodoCollections.length>1)
  781. {
  782. var enabledArray=new Array();
  783. for(var c=0; c<globalResourceCalDAVList.TodoCollections.length; c++)
  784. if(globalResourceCalDAVList.TodoCollections[c].uid!=undefined)
  785. {
  786. var tmp=globalResourceCalDAVList.TodoCollections[c].accountUID.match(accRex);
  787. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  788. if(globalAccountSettings[0].href==resourceCalDAV_href && globalAccountSettings[0].userAuth.userName==globalResourceCalDAVList.TodoCollections[c].userAuth.userName)
  789. enabledArray.push(globalResourceCalDAVList.TodoCollections[c]);
  790. }
  791. if(enabledArray.length==0)
  792. enabledArray.push(globalResourceCalDAVList.TodoCollections[1]);
  793. for(var c=0; c<enabledArray.length; c++)
  794. {
  795. $('#ResourceCalDAVTODOList .resourceCalDAVTODO_item[data-id="'+enabledArray[c].uid+'"]').css('display','block')
  796. enabledArray[c].makeLoaded=true;
  797. var uidParts=enabledArray[c].uid.match(rexo);
  798. globalSettings.loadedtodocollections.value.push(uidParts[1]+uidParts[3]);
  799. var resDOMItem=$('#ResourceCalDAVTODOList').find('.resourceCalDAVTODO_item[data-id="'+jqueryEscapeSelector(enabledArray[c].uid)+'"]');
  800. var resDOMHeader=resDOMItem.prevUntil('.resourceCalDAVTODO_header').last().prev();
  801. if(!resDOMHeader.length)
  802. resDOMHeader=resDOMItem.prev();
  803. resDOMHeader.css('display','block');
  804. resDOMItem.css('display','');
  805. resDOMItem.find('input[type=checkbox]').not('.unloadCheck').trigger('click');
  806. globalVisibleCalDAVTODOCollections.splice(globalVisibleCalDAVTODOCollections.length, 0, enabledArray[c].uid);
  807. }
  808. }
  809. $('#ResourceCalDAVList').children('.resourceCalDAV_header').each(function(){
  810. if(!$(this).nextUntil('.resourceCalDAV_header').filter(':visible').length)
  811. $(this).css('display','none');
  812. });
  813. $('#ResourceCalDAVTODOList').children('.resourceCalDAVTODO_header').each(function(){
  814. if(!$(this).nextUntil('.resourceCalDAVTODO_header').filter(':visible').length)
  815. $(this).css('display','none');
  816. });
  817. selectActiveCalendar();
  818. }
  819. if(isAvaible('CardDavMATE'))
  820. {
  821. if($('#ResourceCardDAVList .resourceCardDAV_item:visible').length==0 && globalResourceCardDAVList.collections.length>1)
  822. {
  823. var enabledArray=new Array();
  824. for(var c=0; c<globalResourceCardDAVList.collections.length; c++)
  825. if(globalResourceCardDAVList.collections[c].uid!=undefined)
  826. {
  827. var tmp=globalResourceCardDAVList.collections[c].accountUID.match(accRex);
  828. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  829. if(globalAccountSettings[0].href==resourceCalDAV_href && globalAccountSettings[0].userAuth.userName==globalResourceCardDAVList.collections[c].userAuth.userName)
  830. enabledArray.push(globalResourceCardDAVList.collections[c]);
  831. }
  832. if(enabledArray.length==0)
  833. enabledArray.push(globalResourceCardDAVList.collections[1]);
  834. for(var c=0; c<enabledArray.length; c++)
  835. {
  836. $('#ResourceCardDAVList .resourceCardDAV_item .resourceCardDAV[data-id="'+enabledArray[c].uid+'"]').parent().css('display','block')
  837. enabledArray[c].makeLoaded=true;
  838. //$('#ResourceCardDAVList').find('.resourceCardDAV_item .resourceCardDAV').find('input[data-id="'+enabledArray[c].uid+'"]').trigger('click');
  839. var uidParts=enabledArray[c].uid.match(rexo);
  840. globalSettings.loadedaddressbookcollections.value.push(uidParts[1]+uidParts[3]);
  841. globalSettings.activeaddressbookcollections.value.push(uidParts[1]+uidParts[3]);
  842. }
  843. }
  844. $('#ResourceCardDAVList').children('.resourceCardDAV_header').each(function(){
  845. if(!$(this).nextUntil('.resourceCardDAV_header').filter(':visible').length)
  846. $(this).css('display','none');
  847. });
  848. }
  849. loadNextApplication(true);
  850. }
  851. var isTodoAv=false,isEventAv=false;
  852. if(isAvaible('CalDavZAP'))
  853. {
  854. setCalendarNumber(false);
  855. selectActiveCalendar();
  856. var cals=globalResourceCalDAVList.TodoCollections;
  857. if(cals.length==0 || (cals.length==1 && typeof cals[0].uid=='undefined'))
  858. {
  859. $('#intCaldavTodo').css('display','none');
  860. isTodoAv=false;
  861. }
  862. else
  863. {
  864. $('#intCaldavTodo').css('display','block');
  865. isTodoAv=true;
  866. }
  867. var calendarsArray=new Array();
  868. for(var i=0; i<cals.length; i++)
  869. if(cals[i].uid!=undefined)
  870. calendarsArray[calendarsArray.length]={displayValue:cals[i].displayvalue,uid:cals[i].uid, permissions_read_only:cals[i].permissions.read_only,makeLoaded:cals[i].makeLoaded};
  871. calendarsArray.sort(customResourceCompare);
  872. globalResourceCalDAVList.sortedTodoCollections=calendarsArray;
  873. var cals=globalResourceCalDAVList.collections;
  874. if(cals.length==0 || (cals.length==1 && typeof cals[0].uid=='undefined'))
  875. {
  876. $('#intCaldav').css('display','none');
  877. isEventAv=false;
  878. }
  879. else
  880. {
  881. $('#intCaldav').css('display','block');
  882. isEventAv=true;
  883. }
  884. calendarsArray=new Array();
  885. for(var i=0; i<cals.length; i++)
  886. if(cals[i].uid!=undefined)
  887. calendarsArray[calendarsArray.length]={displayValue:cals[i].displayvalue,uid:cals[i].uid, permissions_read_only:cals[i].permissions.read_only, makeLoaded:cals[i].makeLoaded};
  888. calendarsArray.sort(customResourceCompare);
  889. globalResourceCalDAVList.sortedCollections = calendarsArray;
  890. }
  891. var isAddrAv=false;
  892. if(isAvaible('CardDavMATE'))
  893. {
  894. selectActiveAddressbook();
  895. for(var adr in globalAddressbookList.vcard_groups)
  896. {
  897. if(globalAddressbookList.vcard_groups[adr].length>0)
  898. {
  899. extendDestSelect();
  900. if(typeof $('#vCardEditor').attr('data-vcard-uid')=='undefined')
  901. $('#vCardEditor').find('[data-attr-name="_DEST_"]').find('optiotn[data-type$="'+$('#ResourceCardDAVList').find('.resourceCardDAV_selected').find(':input[data-id]').attr('data-id')+'"]').prop('selected',true);
  902. }
  903. }
  904. var addrs=globalResourceCardDAVList.collections;
  905. if(addrs.length==0 || (addrs.length==1 && typeof addrs[0].uid == 'undefined'))
  906. {
  907. $('#intCarddav').css('display','none');
  908. isAddrAv=false;
  909. }
  910. else
  911. {
  912. isAddrAv=true;
  913. $('#intCarddav').css('display','block');
  914. }
  915. }
  916. if((isAvaible('CalDavZAP') && !isCalDAVLoaded) || (isAvaible('CardDavMATE') && !isCardDAVLoaded))
  917. {
  918. if(isAvaible('CalDavZAP'))
  919. {
  920. if(globalActiveApp=='CalDavTODO')
  921. if(!isTodoAv)
  922. globalActiveApp=null;
  923. if(globalActiveApp==null || globalActiveApp=='CalDavZAP')
  924. {
  925. if(!isEventAv)
  926. globalActiveApp=null;
  927. else
  928. globalActiveApp='CalDavZAP';
  929. }
  930. }
  931. if(isAvaible('CardDavMATE') && (globalActiveApp==null || globalActiveApp=='CardDavMATE'))
  932. {
  933. if(!isAddrAv)
  934. globalActiveApp=null;
  935. else
  936. globalActiveApp='CardDavMATE';
  937. }
  938. if(globalActiveApp!=null)
  939. checkForApplication(globalActiveApp);
  940. }
  941. ifLoadCollections();
  942. if(isAvaible('CalDavZAP'))
  943. {
  944. if($('#ResourceCalDAVList .resourceCalDAV_item:visible').not('.resourceCalDAV_item_ro').length==0)
  945. {
  946. $('#eventFormShower').css('display','none');
  947. $('#calendar').fullCalendar('setOptions',{'selectable':false});
  948. }
  949. else
  950. {
  951. $('#eventFormShower').css('display','block');
  952. $('#calendar').fullCalendar('setOptions',{'selectable':true});
  953. }
  954. if($('#ResourceCalDAVTODOList .resourceCalDAVTODO_item:visible').not('.resourceCalDAV_item_ro').length==0)
  955. $('#eventFormShowerTODO').css('display','none');
  956. else
  957. $('#eventFormShowerTODO').css('display','block');
  958. }
  959. return false;
  960. }
  961. else if(indexR>=globalAccountSettings.length && !settingsLoaded)
  962. {
  963. console.log("Error: [netFindResource]: 'Unable to load resources'");
  964. return false;
  965. }
  966. var re=new RegExp('^(https?://)([^/]+)(.*)','i');
  967. var tmp=inputResource.href.match(re);
  968. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  969. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; // for the error handler
  970. var settingsXML='';
  971. if(inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  972. settingsXML='<I:settings xmlns:I="http://inf-it.com/ns/dav/"/>';
  973. var baseHref=tmp[1]+tmp[2];
  974. if(typeof inputResource.extendedDelegation!='undefined' && inputResource.extendedDelegation && (typeof inputResource.abhref!='undefined' || typeof inputResource.cahref!='undefined'))
  975. {
  976. if(isAvaible('CardDavMATE') && isAvaible('CalDavZAP'))
  977. {
  978. if(inputResource.abhref==inputResource.cahref)
  979. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  980. else
  981. netLoadResource(inputResource, inputResource.abhref, true, inputResourceIndex, forceLoad, indexR, loadArray);
  982. }
  983. else if(isAvaible('CardDavMATE'))
  984. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  985. else if(isAvaible('CalDavZAP'))
  986. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  987. return false;
  988. }
  989. $.ajax({
  990. type: 'PROPFIND',
  991. url: inputResource.href,
  992. cache: false,
  993. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true : inputResource.crossDomain),
  994. xhrFields: {
  995. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false : inputResource.withCredentials)
  996. },
  997. timeout: inputResource.timeOut,
  998. beforeSend: function(req) {
  999. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  1000. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName,inputResource.userAuth.userPassword));
  1001. req.setRequestHeader('X-client', globalXClientHeader);
  1002. req.setRequestHeader('Depth', '0');
  1003. if(globalSettingsSaving!=''||(isAvaible('CardDavMATE') && (!globalCardDAVInitLoad && !globalCardDAVResourceSync)) || (isAvaible('CalDavZAP') && (!globalCalDAVInitLoad && !globalCalDAVResourceSync))||(isAvaible('Projects') && isProjectsLoaded))
  1004. /* XXX - System display:none changes */
  1005. if(globalSettingsSaving!='' || (isAvaible('Settings') && $('#SystemSettings').css('visibility')=='visible' && $('.resourceSettings_item_selected').attr('data-type')=='setting_group_password'))
  1006. {
  1007. indexR++;
  1008. if(((isAvaible('CardDavMATE') && globalCardDAVInitLoad) || (isAvaible('CalDavZAP') && globalCalDAVInitLoad)) && indexR==globalAccountSettings.length)
  1009. $('#MainLoader').fadeOut(1200);
  1010. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1011. return false;
  1012. }
  1013. },
  1014. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  1015. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  1016. contentType: 'text/xml; charset=utf-8',
  1017. processData: true,
  1018. data: '<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop>'+settingsXML+'<D:current-user-privilege-set/><D:displayname/><D:resourcetype/><L:calendar-home-set xmlns:L="urn:ietf:params:xml:ns:caldav"/><R:addressbook-home-set xmlns:R="urn:ietf:params:xml:ns:carddav"/></D:prop></D:propfind>',
  1019. dataType: 'xml',
  1020. error: function(objAJAXRequest, strError){
  1021. console.log("Error: [netFindResource: 'PROPFIND "+uidFull+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  1022. indexR++;
  1023. inputResource.errorLoaded=true;
  1024. if(isAvaible('CalDavZAP'))
  1025. {
  1026. $('#intCaldav').find('.int_error').css('display', 'block');
  1027. $('#intCaldavTodo').find('.int_error').css('display', 'block');
  1028. }
  1029. if(isAvaible('CardDavMATE'))
  1030. $('#intCarddav').find('.int_error').css('display', 'block');
  1031. var allFail=true;
  1032. for(var i=0; i< globalAccountSettings.length; i++)
  1033. if(typeof globalAccountSettings[i].errorLoaded=='undefined' || globalAccountSettings[i].errorLoaded==null || globalAccountSettings[i].errorLoaded===false)
  1034. allFail=false;
  1035. if(((isAvaible('CardDavMATE') && globalCardDAVInitLoad) || (isAvaible('CalDavZAP' && globalCalDAVInitLoad))) && indexR==globalAccountSettings.length && allFail)
  1036. $('#MainLoader').fadeOut(1200);
  1037. else if((isAvaible('CardDavMATE') && !globalCardDAVInitLoad) || (isAvaible('CalDavZAP') && !globalCalDAVInitLoad))
  1038. {
  1039. if(isAvaible('CalDavZAP'))
  1040. handleCalDAVError(true, inputResource);
  1041. if(isAvaible('CardDavMATE'))
  1042. handleCardDAVError(true, inputResource)
  1043. }
  1044. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1045. return false;
  1046. },
  1047. success: function(data, textStatus, xml)
  1048. {
  1049. inputResource.errorLoaded=false;
  1050. if(isAvaible('CalDavZAP') && isEachResourceLoaded())
  1051. {
  1052. $('#intCaldav').find('.int_error').css('display', 'none');
  1053. $('#intCaldavTodo').find('.int_error').css('display', 'none');
  1054. }
  1055. if(isAvaible('CardDavMATE') && isEachResourceLoaded())
  1056. $('#intCarddav').find('.int_error').css('display','none');
  1057. if(isAvaible('CalDavZAP') && !globalCalDAVInitLoad)
  1058. handleCalDAVError(false, inputResource);
  1059. if(isAvaible('CardDavMATE') && !globalCardDAVInitLoad)
  1060. handleCardDAVError(false, inputResource);
  1061. if(!settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && (globalSettings.settingstype.value=='' || globalSettings.settingstype.value==null || (globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null && globalSettings.settingstype.value=='principal-URL')))
  1062. {
  1063. var settings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1064. if(settings!='')
  1065. {
  1066. if(!ignoreServerSettings)
  1067. loadSettings(settings, true, false);
  1068. else
  1069. {
  1070. delete globalSettings.version.value;
  1071. loadSettings(JSON.stringify(globalSettings), false, false);
  1072. console.log('Ignoring server settings: '+'\n'+settings);
  1073. }
  1074. }
  1075. else
  1076. {
  1077. delete globalSettings.version.value;
  1078. loadSettings(JSON.stringify(globalSettings), false, false);
  1079. }
  1080. }
  1081. else if(!globalSyncSettingsSave && inputResource.href.indexOf(globalLoginUsername)!=-1 && ((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync)))
  1082. {
  1083. globalSyncSettingsSave=true;
  1084. var loadedCals = new Array(), loadedTodoCals = new Array(), loadedAddrs = new Array();
  1085. if(isAvaible('CardDavMATE'))
  1086. loadedAddrs = globalSettings.loadedaddressbookcollections.value.slice();
  1087. if(isAvaible('CalDavZAP'))
  1088. {
  1089. loadedCals = globalSettings.loadedcalendarcollections.value.slice();
  1090. loadedTodoCals = globalSettings.loadedtodocollections.value.slice();
  1091. }
  1092. var settings = $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1093. if(typeof globalPreviousSupportedSettings !='undefined' && globalPreviousSupportedSettings!=null)
  1094. loadSettings(settings, true, true);
  1095. if(isAvaible('CardDavMATE'))
  1096. globalSettings.loadedaddressbookcollections.value = loadedAddrs.slice();
  1097. if(isAvaible('CalDavZAP'))
  1098. {
  1099. globalSettings.loadedcalendarcollections.value = loadedCals.slice();
  1100. globalSettings.loadedtodocollections.value = loadedTodoCals.slice();
  1101. }
  1102. checkBeforeClose(false);
  1103. }
  1104. var response=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response');
  1105. var addressbook_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('addressbook-home-set').children().filterNsNode('href').text();
  1106. if(addressbook_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  1107. addressbook_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  1108. if(addressbook_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  1109. inputResource.abhref=addressbook_home;
  1110. else // relative URL returned
  1111. inputResource.abhref=baseHref+addressbook_home;
  1112. var calendar_home=response.children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('calendar-home-set').children().filterNsNode('href').text();
  1113. if(calendar_home=='') // addressbook-home-set has no 'href' value -> SabreDav
  1114. calendar_home=response.children().filterNsNode('href').text().replace('/principals/users/caldav.php','/caldav.php');
  1115. if(calendar_home.match(RegExp('^https?://','i'))!=null) // absolute URL returned
  1116. inputResource.cahref=calendar_home;
  1117. else // relative URL returned
  1118. inputResource.cahref=baseHref+calendar_home;
  1119. if(isAvaible('CardDavMATE') && isAvaible('CalDavZAP'))
  1120. {
  1121. if(inputResource.abhref==inputResource.cahref)
  1122. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1123. else
  1124. netLoadResource(inputResource, inputResource.abhref, true, inputResourceIndex, forceLoad, indexR, loadArray);
  1125. }
  1126. else if(isAvaible('CardDavMATE'))
  1127. netLoadResource(inputResource, inputResource.abhref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1128. else if(isAvaible('CalDavZAP'))
  1129. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1130. }
  1131. });
  1132. }
  1133. function netLoadResource(inputResource, inputHref, hrefMode, inputResourceIndex, forceLoad, indexR, loadArray)
  1134. {
  1135. var re=new RegExp('^(https?://)([^/]+)(.*)','i');
  1136. if(!isAvaible('CardDavMATE') || !globalCardDAVInitLoad || (globalCardDAVInitLoad && typeof inputResource.addressbookNo == 'undefined'))
  1137. inputResource.addressbookNo=0;
  1138. if(!isAvaible('CalDavZAP') || !globalCalDAVInitLoad || (globalCalDAVInitLoad && typeof inputResource.calendarNo=='undefined' && typeof inputResource.todoNo=='undefined'))
  1139. {
  1140. inputResource.calendarNo=0;
  1141. inputResource.todoNo=0;
  1142. }
  1143. var tmp=inputResource.abhref.match(re);
  1144. var baseHref=tmp[1]+tmp[2];
  1145. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  1146. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; // for the error handler
  1147. var tmp=inputResource.href.match(RegExp('^(https?://)(.*)','i'));
  1148. var origUID=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  1149. if(typeof globalSubscribedCalendars!='undefined' && globalSubscribedCalendars!=null && typeof inputResource.calendars!='undefined' && inputResource.calendars!=null && inputResource.calendars.length>0)
  1150. {
  1151. var tmp1=inputResource.href.match(RegExp('^(https?://)(.*)', 'i'));
  1152. var origUID1=tmp1[1]+inputResource.userAuth.userName+'@'+tmp1[2];
  1153. var resultTimestamp=new Date().getTime();
  1154. for(var k=0; k<globalSubscribedCalendars.calendars.length; k++)
  1155. {
  1156. color=globalSubscribedCalendars.calendars[k].color;
  1157. if(color=='')
  1158. {
  1159. var par=(uidBase+globalSubscribedCalendars.calendars[k].href).split('/');
  1160. var hash=hex_sha256(hex_sha256(par[par.length-3]+'/'+par[par.length-2]+'/'));
  1161. var hex=hash.substring(0,6);
  1162. while(checkColorBrightness(hex)>=252)
  1163. hex=hex_sha256(hex_sha256(hash)).substring(0,6);
  1164. color='#'+hex;
  1165. }
  1166. var syncRequired=true;
  1167. var uidPArts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').split('/');
  1168. if(globalSubscribedCalendars.calendars[k].typeList.indexOf('vevent')!=-1)
  1169. {
  1170. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1171. var checkHref=uidParts[1]+uidParts[3];
  1172. if(!isHrefSet)
  1173. {
  1174. saveHref=uidBase+href;
  1175. isHrefSet=true;
  1176. }
  1177. if(!globalDefaultCalendarCollectionLoadAll)
  1178. {
  1179. var toBeLoad=false;
  1180. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1181. {
  1182. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('/([^/]+/[^/]+/)$'));
  1183. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1184. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1185. var found=false;
  1186. for(var l=0; l<globalSettings.loadedcalendarcollections.value.length; l++)
  1187. {
  1188. var tmpParts2=globalSettings.loadedcalendarcollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1189. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1190. if(checkHref3==checkHref2)
  1191. {
  1192. found=true;
  1193. globalSettings.loadedcalendarcollections.value[l]=checkHref;
  1194. break;
  1195. }
  1196. }
  1197. toBeLoad=found;
  1198. }
  1199. else
  1200. toBeLoad=globalSettings.loadedcalendarcollections.value.indexOf(checkHref)!=-1;
  1201. }
  1202. else
  1203. {
  1204. if(globalCalDAVInitLoad)
  1205. globalSettings.loadedcalendarcollections.value.push(checkHref);
  1206. var toBeLoad=true;
  1207. }
  1208. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:globalSubscribedCalendars.calendars[k].typeList, listType:'vevent', syncRequired:syncRequired, ecolor: color, timestamp: resultTimestamp, uid: uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/', timeOut: inputResource.timeOut, displayvalue: globalSubscribedCalendars.calendars[k].displayName, userAuth: globalSubscribedCalendars.calendars[k].userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID1, href: globalSubscribedCalendars.calendars[k].href, hrefLabel: globalSubscribedCalendars.hrefLabel, permissions: {full: [], read_only: true}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null,subscription: true, newlyAdded:toBeLoad, urlArray: new Array(), ignoreAlarms:globalSubscribedCalendars.calendars[k].ignoreAlarm,webdav_bind:false}, indexR, true);
  1209. if(inputResource!=undefined)
  1210. inputResource.calendarNo++;
  1211. syncRequired=false;
  1212. }
  1213. if(globalSubscribedCalendars.calendars[k].typeList.indexOf('vtodo')!=-1)
  1214. {
  1215. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1216. var checkHref=uidParts[1]+uidParts[3];
  1217. if(!isHrefSet)
  1218. {
  1219. saveHref=uidBase+href;
  1220. isHrefSet=true;
  1221. }
  1222. if(!globalDefaultTodoCalendarCollectionLoadAll)
  1223. {
  1224. var toBeLoad=false;
  1225. if(typeof globalCrossServerSettingsURL!='undefined'&&globalCrossServerSettingsURL!=null&globalCrossServerSettingsURL)
  1226. {
  1227. var uidParts=(uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/').match(RegExp('/([^/]+/[^/]+/)$'));
  1228. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1229. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1230. var found=false;
  1231. for(var l=0; l<globalSettings.loadedtodocollections.value.length; l++)
  1232. {
  1233. var tmpParts2=globalSettings.loadedtodocollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1234. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1235. if(checkHref3==checkHref2)
  1236. {
  1237. found=true;
  1238. globalSettings.loadedtodocollections.value[l]=checkHref;
  1239. break;
  1240. }
  1241. }
  1242. toBeLoad=found;
  1243. }
  1244. else
  1245. toBeLoad=globalSettings.loadedtodocollections.value.indexOf(checkHref)!=-1;
  1246. }
  1247. else
  1248. {
  1249. var toBeLoad=true;
  1250. if(globalCalDAVInitLoad)
  1251. globalSettings.loadedtodocollections.value.push(checkHref);
  1252. }
  1253. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:globalSubscribedCalendars.calendars[k].typeList, listType:'vtodo', syncRequired:syncRequired, ecolor: color, timestamp: resultTimestamp, uid: uidBase+'/'+globalSubscribedCalendars.calendars[k].href+'/', timeOut: inputResource.timeOut, displayvalue: globalSubscribedCalendars.calendars[k].displayName, userAuth: globalSubscribedCalendars.calendars[k].userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID1, href: globalSubscribedCalendars.calendars[k].href, hrefLabel: globalSubscribedCalendars.hrefLabel, permissions: {full: [], read_only: true}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null,subscription: true, newlyAdded:toBeLoad, urlArray: new Array(), ignoreAlarms:globalSubscribedCalendars.calendars[k].ignoreAlarm,webdav_bind:false}, indexR, false);
  1254. if(inputResource!=undefined)
  1255. inputResource.todoNo++;
  1256. }
  1257. }
  1258. //recursive call for resource loading
  1259. indexR++;
  1260. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1261. return true;
  1262. }
  1263. var settingsXML='';
  1264. if(inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null)
  1265. if((globalSettings.settingstype.value=='addressbook-home-set' && inputResource.abhref==inputHref) || (globalSettings.settingstype.value=='calendar-home-set' && inputResource.cahref==inputHref) || (globalSettings.settingstype.value=='principal-URL'&& ((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync))))
  1266. settingsXML='<I:settings xmlns:I="http://inf-it.com/ns/dav/"/>';
  1267. function ajaxComplete(data, textStatus, xml)
  1268. {
  1269. var Rname='';
  1270. inputResource.errorLoaded=false;
  1271. if(isAvaible('CalDavZAP') && isEachResourceLoaded())
  1272. {
  1273. $('#intCaldav').find('.int_error').css('display','none');
  1274. $('#intCaldavTodo').find('.int_error').css('display','none');
  1275. }
  1276. if(isAvaible('CardDavMATE') && isEachResourceLoaded())
  1277. $('#intCarddav').find('.int_error').css('display','none');
  1278. if(isAvaible('CalDavZAP') && !globalCalDAVInitLoad)
  1279. handleCalDAVError(false, inputResource);
  1280. if(isAvaible('CardDavMATE') && !globalCardDAVInitLoad)
  1281. handleCardDAVError(false, inputResource);
  1282. var saveHref='';
  1283. isHrefSet=false;
  1284. var calendarNo=0;
  1285. var resultTimestamp=new Date().getTime();
  1286. if(!settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1 && inputResource.settingsAccount && globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null)
  1287. {
  1288. if((globalSettings.settingstype.value=='addressbook-home-set' && inputResource.abhref==inputHref) || (globalSettings.settingstype.value=='calendar-home-set' && inputResource.cahref==inputHref))
  1289. {
  1290. var settings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1291. if(settings!='')
  1292. {
  1293. if(!ignoreServerSettings)
  1294. loadSettings(settings, true, false);
  1295. else
  1296. {
  1297. delete globalSettings.version.value;
  1298. loadSettings(JSON.stringify(globalSettings), false, false);
  1299. console.log('Ignoring server settings: '+'\n'+settings);
  1300. }
  1301. }
  1302. else
  1303. {
  1304. var calSettings=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('cal-settings').text();
  1305. if(calSettings!='')
  1306. {
  1307. if(!ignoreServerSettings)
  1308. loadSettings(calSettings, true, false);
  1309. else
  1310. {
  1311. delete globalSettings.version.value;
  1312. loadSettings(JSON.stringify(globalSettings), false, false);
  1313. console.log('Ignoring server settings: '+'\n'+calSettings);
  1314. }
  1315. }
  1316. else
  1317. {
  1318. delete globalSettings.version.value;
  1319. loadSettings(JSON.stringify(globalSettings), false, false);
  1320. }
  1321. }
  1322. }
  1323. }
  1324. else if(!settingsLoaded && inputResource.href.indexOf(globalLoginUsername)!=-1)
  1325. {
  1326. delete globalSettings.version.value;
  1327. loadSettings(JSON.stringify(globalSettings), false, false);
  1328. }
  1329. else if(!globalSyncSettingsSave && inputResource.href.indexOf(globalLoginUsername)!=-1 && ((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync)))
  1330. {
  1331. globalSyncSettingsSave=true;
  1332. var loadedCals = new Array(), loadedTodoCals = new Array(), loadedAddrs = new Array();
  1333. if(isAvaible('CardDavMATE'))
  1334. loadedAddrs = globalSettings.loadedaddressbookcollections.value.slice();
  1335. if(isAvaible('CalDavZAP'))
  1336. {
  1337. loadedCals = globalSettings.loadedcalendarcollections.value.slice();
  1338. loadedTodoCals = globalSettings.loadedtodocollections.value.slice();
  1339. }
  1340. var settings = $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('settings').text();
  1341. if(typeof globalPreviousSupportedSettings !='undefined' && globalPreviousSupportedSettings!=null)
  1342. loadSettings(settings, true, true);
  1343. if(isAvaible('CardDavMATE'))
  1344. globalSettings.loadedaddressbookcollections.value = loadedAddrs.slice();
  1345. if(isAvaible('CalDavZAP'))
  1346. {
  1347. globalSettings.loadedcalendarcollections.value = loadedCals.slice();
  1348. globalSettings.loadedtodocollections.value = loadedTodoCals.slice();
  1349. }
  1350. checkBeforeClose(false);
  1351. }
  1352. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').each(function(index, element){
  1353. $(element).children().filterNsNode('propstat').each(function(pindex, pelement){
  1354. var resources=$(pelement).children().filterNsNode('prop');
  1355. var color='';
  1356. var typeList=new Array();
  1357. resources.children().filterNsNode('supported-calendar-component-set').children().filterNsNode('comp').each(function(pindex, pelement){
  1358. typeList[typeList.length]=pelement.getAttribute('name').toLowerCase();
  1359. });
  1360. if(typeof inputResource!='undefined' && typeof inputResource.collectionTypes!='undefined' && inputResource.collectionTypes!=null && inputResource.collectionTypes.indexOf('calendar')!=-1 ||
  1361. typeof inputResource=='undefined' || inputResource.collectionTypes==null)
  1362. if((isAvaible('CalDavZAP') && resources.children().filterNsNode('resourcetype').children().filterNsNode('calendar').length==1 && resources.children().filterNsNode('resourcetype').children().filterNsNode('collection').length==1) && (inputResource.ignoreBound==undefined || !(inputResource.ignoreBound==true && resources.children().filterNsNode('resourcetype').children().filterNsNode('webdav-binding').length==1)))
  1363. {
  1364. if(resources.children().filterNsNode('calendar-color').length==1)
  1365. {
  1366. color=resources.children().filterNsNode('calendar-color').text();
  1367. if(color.length==9)
  1368. color=color.substring(0, 7);
  1369. }
  1370. var permissions=new Array();
  1371. resources.children().filterNsNode('current-user-privilege-set').children().filterNsNode('privilege').each(
  1372. function(index, element)
  1373. {
  1374. $(element).children().each(
  1375. function(index, element)
  1376. {
  1377. permissions[permissions.length]=$(element).prop('tagName').replace(/^[^:]+:/,'');
  1378. }
  1379. );
  1380. }
  1381. );
  1382. var read_only=false;
  1383. var href=$(element).children().filterNsNode('href').text();
  1384. if(href.match(RegExp('^https?://','i'))!=null)
  1385. {
  1386. var tmpH = href.match(RegExp('^(https?://)([^/]+)(.*)','i'))
  1387. if(tmpH!=null)
  1388. href = tmpH[3];
  1389. }
  1390. if(permissions.length>0 && permissions.indexOf('all')==-1 && permissions.indexOf('write')==-1 && permissions.indexOf('write-content')==-1)
  1391. read_only=true;
  1392. else if(inputResource.forceReadOnly!=undefined && (inputResource.forceReadOnly==true || inputResource.forceReadOnly instanceof Array))
  1393. {
  1394. if(inputResource.forceReadOnly instanceof Array)
  1395. {
  1396. for(var j=0; j<inputResource.forceReadOnly.length; j++)
  1397. if(typeof inputResource.forceReadOnly[j]=='string')
  1398. {
  1399. var index=href.indexOf(inputResource.forceReadOnly[j]);
  1400. if(index!=-1)
  1401. if(href.length==(index+inputResource.forceReadOnly[j].length))
  1402. read_only=true;
  1403. }
  1404. else if(typeof inputResource.forceReadOnly[j]=='object')
  1405. {
  1406. if(href.match(inputResource.forceReadOnly[j]) != null)
  1407. read_only=true;
  1408. }
  1409. }
  1410. else
  1411. read_only=true;
  1412. }
  1413. var displayvalue=resources.children().filterNsNode('displayname').text();
  1414. var headervalue=resources.children().filterNsNode('headervalue').text();
  1415. var synctoken=resources.children().filterNsNode('sync-token').text();
  1416. var oldSyncToken='';
  1417. var tmp_dv=href.match(RegExp('.*/([^/]+)/$', 'i'));
  1418. if(displayvalue=='') // MacOSX Lion Server
  1419. displayvalue=tmp_dv[1];
  1420. if(color=='')
  1421. {
  1422. var par=(uidBase+href).split('/');
  1423. var hash=hex_sha256(hex_sha256(par[par.length-3]+'/'+par[par.length-2]+'/'));
  1424. var hex=hash.substring(0,6);
  1425. while(checkColorBrightness(hex)>=252)
  1426. hex=hex_sha256(hex_sha256(hash)).substring(0,6);
  1427. color='#'+hex;
  1428. }
  1429. var ignoreAlarms=false;
  1430. var uidPArts=(uidBase+href).split('/');
  1431. if(typeof inputResource.ignoreAlarms=='boolean' && inputResource.ignoreAlarms)
  1432. ignoreAlarms = true;
  1433. else if(inputResource.ignoreAlarms instanceof Array && inputResource.ignoreAlarms.length>0)
  1434. {
  1435. for(var j=0; j<inputResource.ignoreAlarms.length; j++)
  1436. {
  1437. if(typeof inputResource.ignoreAlarms[j]=='string')
  1438. {
  1439. var index=href.indexOf(inputResource.ignoreAlarms[j]);
  1440. if(index!=-1)
  1441. if(href.length==(index+inputResource.ignoreAlarms[j].length))
  1442. ignoreAlarms=true;
  1443. }
  1444. else if (typeof inputResource.ignoreAlarms[j]=='object' && href.match(inputResource.ignoreAlarms[j])!=null)
  1445. ignoreAlarms = true;
  1446. }
  1447. }
  1448. // insert the resource
  1449. var webdav_bind=false;
  1450. if(resources.children().filterNsNode('resourcetype').children().filterNsNode('webdav-binding').length==1)
  1451. webdav_bind=true;
  1452. var checkContentType=(inputResource.checkContentType==undefined ? true : inputResource.checkContentType);
  1453. var syncRequired=true;
  1454. if(typeList.indexOf('vevent')!=-1)
  1455. {
  1456. var someChanged=false;
  1457. var existingResource=globalResourceCalDAVList.getEventCollectionByUID(uidBase+href);
  1458. if(existingResource!=null)
  1459. {
  1460. if(existingResource.syncToken!=synctoken)
  1461. someChanged=true;
  1462. }
  1463. else
  1464. {
  1465. someChanged=true;
  1466. if(synctoken=='')
  1467. synctoken=null;
  1468. }
  1469. var uidParts=(uidBase+href).match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1470. var checkHref=uidParts[1]+uidParts[3];
  1471. if(!isHrefSet)
  1472. {
  1473. saveHref=uidBase+href;
  1474. isHrefSet=true;
  1475. }
  1476. if(!globalDefaultCalendarCollectionLoadAll)
  1477. {
  1478. var toBeLoad=false;
  1479. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1480. {
  1481. var uidParts=(uidBase+href).match(RegExp('/([^/]+/[^/]+/)$'));
  1482. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1483. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1484. var found=false;
  1485. for(var l=0; l<globalSettings.loadedcalendarcollections.value.length; l++)
  1486. {
  1487. var tmpParts2=globalSettings.loadedcalendarcollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1488. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1489. if(checkHref3==checkHref2)
  1490. {
  1491. found=true;
  1492. globalSettings.loadedcalendarcollections.value[l]=checkHref;
  1493. break;
  1494. }
  1495. }
  1496. toBeLoad=found;
  1497. }
  1498. else
  1499. toBeLoad=globalSettings.loadedcalendarcollections.value.indexOf(checkHref)!=-1;
  1500. }
  1501. else
  1502. {
  1503. var toBeLoad=true;
  1504. if(globalCalDAVInitLoad)
  1505. globalSettings.loadedcalendarcollections.value.push(checkHref);
  1506. }
  1507. if(!toBeLoad)
  1508. oldSyncToken='';
  1509. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:typeList, listType:'vevent', ecolor: color, timestamp: resultTimestamp, uid: uidBase+href, timeOut: inputResource.timeOut, displayvalue: displayvalue, headervalue:headervalue, userAuth: inputResource.userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID, href: href, hrefLabel: inputResource.hrefLabel, permissions: {full: permissions, read_only: read_only}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null, subscription: false, newlyAdded:toBeLoad, urlArray:null, ignoreAlarms:ignoreAlarms,webdav_bind:webdav_bind, syncRequired:syncRequired, checkContentType: checkContentType, syncToken: synctoken, oldSyncToken: oldSyncToken, someChanged:someChanged}, indexR, true);
  1510. if(globalAccountSettings[indexR]!=undefined)
  1511. globalAccountSettings[indexR].calendarNo++;
  1512. syncRequired=false;
  1513. }
  1514. if(typeList.indexOf('vtodo')!=-1)
  1515. {
  1516. var someChanged=false;
  1517. var existingResource=globalResourceCalDAVList.getTodoCollectionByUID(uidBase+href);
  1518. if(syncRequired && existingResource!=null)
  1519. {
  1520. if(existingResource.syncToken!=synctoken)
  1521. someChanged=true;
  1522. }
  1523. else
  1524. {
  1525. someChanged=true;
  1526. if(synctoken=='')
  1527. synctoken=null;
  1528. }
  1529. var uidParts=(uidBase+href).match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1530. var checkHref=uidParts[1]+uidParts[3];
  1531. if(!isHrefSet)
  1532. {
  1533. saveHref=uidBase+href;
  1534. isHrefSet=true;
  1535. }
  1536. if(!globalDefaultTodoCalendarCollectionLoadAll)
  1537. {
  1538. var toBeLoad=false;
  1539. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1540. {
  1541. var uidParts=(uidBase+href).match(RegExp('/([^/]+/[^/]+/)$'));
  1542. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1543. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1544. var found=false;
  1545. for(var l=0; l<globalSettings.loadedtodocollections.value.length; l++)
  1546. {
  1547. var tmpParts2=globalSettings.loadedtodocollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1548. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1549. if(checkHref3==checkHref2)
  1550. {
  1551. found=true;
  1552. globalSettings.loadedtodocollections.value[l]=checkHref;
  1553. break;
  1554. }
  1555. }
  1556. toBeLoad=found;
  1557. }
  1558. else
  1559. toBeLoad=globalSettings.loadedtodocollections.value.indexOf(checkHref)!=-1;
  1560. }
  1561. else
  1562. {
  1563. var toBeLoad=true;
  1564. if(globalCalDAVInitLoad)
  1565. globalSettings.loadedtodocollections.value.push(checkHref);
  1566. }
  1567. if(!toBeLoad)
  1568. oldSyncToken='';
  1569. globalResourceCalDAVList.insertResource({makeLoaded:toBeLoad, typeList:typeList, hrefArray: new Array(), listType:'vtodo', ecolor: color, timestamp: resultTimestamp, uid: uidBase+href, timeOut: inputResource.timeOut, displayvalue: displayvalue, headervalue: headervalue, userAuth: inputResource.userAuth, resourceIndex: indexR, url: baseHref, accountUID: origUID, href: href, hrefLabel: inputResource.hrefLabel, permissions: {full: permissions, read_only: read_only}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, interval: null, waitInterval: null, displayEventsArray: new Array(), pastUnloaded: '', fcSource: null, subscription: false, newlyAdded:toBeLoad, urlArray:null, ignoreAlarms:ignoreAlarms,webdav_bind:webdav_bind,syncRequired:syncRequired, checkContentType: checkContentType, syncToken: synctoken, oldSyncToken: oldSyncToken, someChanged:someChanged}, indexR, false);
  1570. if(globalAccountSettings[indexR]!=undefined)
  1571. globalAccountSettings[indexR].todoNo++;
  1572. }
  1573. }
  1574. if(typeof inputResource!='undefined' && typeof inputResource.collectionTypes!='undefined' && inputResource.collectionTypes!=null && inputResource.collectionTypes.indexOf('addressbook')!=-1 || typeof inputResource=='undefined' || inputResource.collectionTypes==null)
  1575. if((isAvaible('CardDavMATE') && resources.children().filterNsNode('resourcetype').children().filterNsNode('addressbook').length==1 && resources.children().filterNsNode('resourcetype').children().filterNsNode('collection').length==1) && (inputResource.ignoreBound==undefined || !(inputResource.ignoreBound==true && resources.children().filterNsNode('resourcetype').children().filterNsNode('webdav-binding').length==1)))
  1576. {
  1577. if(resources.children().filterNsNode('addressbook-color').length==1)
  1578. {
  1579. color=resources.children().filterNsNode('addressbook-color').text();
  1580. if(color.length==9)
  1581. color=color.substring(0, 7);
  1582. }
  1583. var permissions=new Array();
  1584. resources.children().filterNsNode('current-user-privilege-set').children().filterNsNode('privilege').each(
  1585. function(index, element)
  1586. {
  1587. $(element).children().each(
  1588. function(index, element)
  1589. {
  1590. permissions[permissions.length]=$(element).prop('tagName').replace(/^[^:]+:/,'');
  1591. }
  1592. );
  1593. }
  1594. );
  1595. var disableLocking=false;
  1596. var tmp_lock_support=resources.children().filterNsNode('supportedlock').children().filterNsNode('lockentry').children().filterNsNode('lockscope').children().filterNsNode('exclusive');
  1597. if(typeof tmp_lock_support=='undefined' || tmp_lock_support.length==undefined || tmp_lock_support.length==0)
  1598. disableLocking=true;
  1599. var href=$(element).children().filterNsNode('href').text();
  1600. if(href.match(RegExp('^https?://','i'))!=null)
  1601. {
  1602. var tmpH = href.match(RegExp('^(https?://)([^/]+)(.*)','i'))
  1603. if(tmpH!=null)
  1604. href = tmpH[3];
  1605. }
  1606. var tmp_cn=href.match(RegExp('/([^/]+)/?$')); // collection name
  1607. var read_only=false;
  1608. if(((typeof globalDisablePermissionChecking=='undefined' || globalDisablePermissionChecking!=true) && (permissions.length>0 && permissions.indexOf('all')==-1 && permissions.indexOf('write')==-1 && permissions.indexOf('write-content')==-1)) || (inputResource.forceReadOnly!=undefined && (inputResource.forceReadOnly==true || inputResource.forceReadOnly instanceof Array && inputResource.forceReadOnly.indexOf(tmp_cn[1])!=-1)))
  1609. read_only=true;
  1610. var displayvalue=resources.children().filterNsNode('displayname').text();
  1611. var headervalue=resources.children().filterNsNode('headervalue').text();
  1612. var synctoken=resources.children().filterNsNode('sync-token').text();
  1613. var oldSyncToken='';
  1614. var tmp_dv=href.match(RegExp('.*/([^/]+)/$','i'));
  1615. if(displayvalue=='') // OS X Server
  1616. displayvalue=tmp_dv[1];
  1617. if(color=='')
  1618. {
  1619. var par=(uidBase+href).split('/');
  1620. var hash=hex_sha256(hex_sha256(par[par.length-3]+'/'+par[par.length-2]+'/'));
  1621. var hex=hash.substring(0,6);
  1622. while(checkColorBrightness(hex)>=252)
  1623. hex=hex_sha256(hex_sha256(hash)).substring(0,6);
  1624. color='#'+hex;
  1625. }
  1626. var checkContentType=(inputResource.checkContentType==undefined ? true : inputResource.checkContentType);
  1627. // insert the resource
  1628. var someChanged=false;
  1629. var existingResource=globalResourceCardDAVList.getCollectionByUID(uidBase+href);
  1630. if(existingResource!=null)
  1631. {
  1632. if(existingResource.syncToken!=synctoken)
  1633. someChanged=true;
  1634. if(typeof globalForceSyncURLArray!='undefined' && globalForceSyncURLArray.length>0 && globalForceSyncURLArray.indexOf(existingResource.uid)!=-1)
  1635. {
  1636. someChanged=true;
  1637. }
  1638. }
  1639. else
  1640. {
  1641. someChanged=true;
  1642. if(synctoken=='')
  1643. synctoken=null;
  1644. }
  1645. var uidParts=(uidBase+href).match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)'));
  1646. var checkHref=uidParts[1]+uidParts[3];
  1647. if(!isHrefSet)
  1648. {
  1649. saveHref=uidBase+href;
  1650. isHrefSet=true;
  1651. }
  1652. if(!globalDefaultAddrCollectionLoadAll)
  1653. {
  1654. var toBeLoad=false;
  1655. if(typeof globalCrossServerSettingsURL!='undefined' && globalCrossServerSettingsURL!=null && globalCrossServerSettingsURL)
  1656. {
  1657. var uidParts=(uidBase+href).match(RegExp('/([^/]+/[^/]+/)$'));
  1658. var tmpParts=uidParts[1].match('^(.*/)([^/]+)/$');
  1659. var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/';
  1660. var found=false;
  1661. for(var l=0; l<globalSettings.loadedaddressbookcollections.value.length; l++)
  1662. {
  1663. var tmpParts2=globalSettings.loadedaddressbookcollections.value[l].match('^(.*/)([^/]+)/([^/]+)/$');
  1664. var checkHref2=decodeURIComponent(tmpParts2[2])+'/'+tmpParts2[3]+'/';
  1665. if(checkHref3==checkHref2)
  1666. {
  1667. found=true;
  1668. globalSettings.loadedaddressbookcollections.value[l]=checkHref;
  1669. break;
  1670. }
  1671. }
  1672. toBeLoad=found;
  1673. }
  1674. else
  1675. toBeLoad=globalSettings.loadedaddressbookcollections.value.indexOf(checkHref)!=-1;
  1676. }
  1677. else
  1678. {
  1679. var toBeLoad=true;
  1680. if(globalCardDAVInitLoad)
  1681. globalSettings.loadedaddressbookcollections.value.push(checkHref);
  1682. }
  1683. globalResourceCardDAVList.insertResource({makeLoaded:toBeLoad, timestamp: resultTimestamp, uid: uidBase+href, timeOut: inputResource.timeOut, displayvalue: displayvalue, headervalue: headervalue, userAuth: inputResource.userAuth, url: baseHref, accountUID: origUID, href: href, hrefLabel: inputResource.hrefLabel, color: color, permissions: {full: permissions, read_only: read_only}, crossDomain: inputResource.crossDomain, withCredentials: inputResource.withCredentials, checkContentType: checkContentType, isLoaded:false, newlyAdded:toBeLoad, indexResource:indexR, disableLocking: disableLocking, syncToken: synctoken, oldSyncToken:oldSyncToken, someChanged:someChanged}, inputResourceIndex);
  1684. inputResource.addressbookNo++;
  1685. }
  1686. });
  1687. });
  1688. if(saveHref!='')
  1689. {
  1690. var saveUserHref=saveHref.replace(new RegExp('[^/]+/$'),'');
  1691. if(typeof globalResourceCalDAVList!='undefined' && globalResourceCalDAVList!=null)
  1692. globalResourceCalDAVList.removeOldResources(saveUserHref, resultTimestamp);
  1693. if(typeof globalResourceCardDAVList!='undefined' && globalResourceCardDAVList!=null)
  1694. globalResourceCardDAVList.removeOldResources(saveUserHref, resultTimestamp);
  1695. }
  1696. //recursive call for resource loading
  1697. if(hrefMode)
  1698. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray)
  1699. else
  1700. {
  1701. indexR++;
  1702. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1703. }
  1704. }
  1705. // first try to process the cached data (if cached results are available in the "auth module" response)
  1706. var tmpCache;
  1707. if(globalXMLCache!=null && (tmpCache=globalXMLCache.children('davprincipalcollections[request_url="'+jqueryEscapeSelector(inputHref)+'"]').remove()).length)
  1708. {
  1709. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  1710. console.log('DBG Cache OK: '+arguments.callee.name+' url: \''+inputHref+'\': saved one request!');
  1711. ajaxComplete('', 'success', {responseXML: tmpCache});
  1712. }
  1713. else
  1714. {
  1715. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  1716. console.log('DBG Cache ERROR: '+arguments.callee.name+' url: \''+inputHref+'\': spend one request!');
  1717. $.ajax({
  1718. type: 'PROPFIND',
  1719. url: inputHref,
  1720. cache: false,
  1721. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true : inputResource.crossDomain),
  1722. xhrFields: {
  1723. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false : inputResource.withCredentials)
  1724. },
  1725. timeout: inputResource.timeOut,
  1726. beforeSend: function(req){
  1727. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  1728. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName, inputResource.userAuth.userPassword));
  1729. req.setRequestHeader('X-client', globalXClientHeader);
  1730. req.setRequestHeader('Depth', '1');
  1731. if(globalSettingsSaving!=''||(isAvaible('CardDavMATE') && (!globalCardDAVInitLoad && !globalCardDAVResourceSync)) || (isAvaible('CalDavZAP') && (!globalCalDAVInitLoad && !globalCalDAVResourceSync))||(isAvaible('Projects') && isProjectsLoaded))
  1732. /* XXX - System display:none changes */
  1733. if(globalSettingsSaving!='' || (isAvaible('Settings') && $('#SystemSettings').css('visibility')=='visible' && $('.resourceSettings_item_selected').attr('data-type')=='setting_group_password'))
  1734. {
  1735. indexR++;
  1736. if(((isAvaible('CardDavMATE')&&globalCardDAVInitLoad) || (isAvaible('CalDavZAP'&&globalCalDAVInitLoad))) && indexR==globalAccountSettings.length)
  1737. $('#MainLoader').fadeOut(1200);
  1738. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1739. return false;
  1740. }
  1741. },
  1742. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  1743. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  1744. contentType: 'text/xml; charset=utf-8',
  1745. processData: true,
  1746. data: '<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop>'+settingsXML+'<D:current-user-privilege-set/><D:displayname/><D:supportedlock/><D:resourcetype/><D:supported-report-set/><D:sync-token/><A:calendar-color xmlns:A="'+(typeof globalCalendarColorPropertyXmlns!='undefined'&&globalCalendarColorPropertyXmlns!=null&&globalCalendarColorPropertyXmlns!='' ? globalCalendarColorPropertyXmlns : 'http://apple.com/ns/ical/')+'"/><I:headervalue xmlns:I="http://inf-it.com/ns/dav/"/><I:addressbook-color xmlns:I="'+(typeof globalAddrColorPropertyXmlns!='undefined'&&globalAddrColorPropertyXmlns!=null&&globalAddrColorPropertyXmlns!='' ? globalAddrColorPropertyXmlns : 'http://inf-it.com/ns/ab/')+'"/><L:supported-calendar-component-set xmlns:L="urn:ietf:params:xml:ns:caldav"/><R:max-image-size xmlns:R="urn:ietf:params:xml:ns:carddav"/></D:prop></D:propfind>',
  1747. dataType: 'xml',
  1748. error: function(objAJAXRequest, strError){
  1749. console.log("Error: [netLoadResource: 'PROPFIND "+uidFull+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  1750. inputResource.errorLoaded=true;
  1751. if(isAvaible('CalDavZAP'))
  1752. {
  1753. $('#intCaldav').find('.int_error').css('display','block');
  1754. $('#intCaldavTodo').find('.int_error').css('display','block');
  1755. }
  1756. if(isAvaible('CardDavMATE'))
  1757. $('#intCarddav').find('.int_error').css('display','block');
  1758. if(hrefMode)
  1759. netLoadResource(inputResource, inputResource.cahref, false, inputResourceIndex, forceLoad, indexR, loadArray);
  1760. else
  1761. {
  1762. indexR++;
  1763. var allFail=true;
  1764. for(var i=0; i< globalAccountSettings.length; i++)
  1765. if(typeof globalAccountSettings[i].errorLoaded=='undefined' || globalAccountSettings[i].errorLoaded==null || globalAccountSettings[i].errorLoaded===false)
  1766. allFail=false;
  1767. if(((isAvaible('CardDavMATE')&&globalCardDAVInitLoad) || (isAvaible('CalDavZAP')&&globalCalDAVInitLoad)) && indexR==globalAccountSettings.length && allFail)
  1768. $('#MainLoader').fadeOut(1200);
  1769. if(isAvaible('CalDavZAP') && !globalCalDAVInitLoad)
  1770. handleCalDAVError(true, inputResource);
  1771. if(isAvaible('CardDavMATE') && !globalCardDAVInitLoad)
  1772. handleCardDAVError(true, inputResource);
  1773. netFindResource(globalAccountSettings[indexR], inputResourceIndex, forceLoad, indexR,loadArray);
  1774. }
  1775. return false;
  1776. },
  1777. success: ajaxComplete
  1778. });
  1779. }
  1780. }// Save the client settings (stored as DAV property on server)
  1781. function netSaveSettings(inputResource, inputSettings, isFormSave, collectionLoad)
  1782. {
  1783. var re=new RegExp('^(https?://)([^/]+)(.*)', 'i');
  1784. var tmp=inputResource.href.match(re);
  1785. var baseHref=tmp[1]+tmp[2];
  1786. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  1787. var uidFull=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2]+tmp[3]; //for the error handler
  1788. var saveHref = inputResource.href;
  1789. var serverSettingss = transformToServer(inputSettings);
  1790. if(globalSettings.settingstype.value!='' && globalSettings.settingstype.value!=null)
  1791. {
  1792. if(globalSettings.settingstype.value=='addressbook-home-set')
  1793. saveHref = inputResource.abhref;
  1794. else if(globalSettings.settingstype.value=='calendar-home-set')
  1795. saveHref = inputResource.cahref;
  1796. }
  1797. $.ajax({
  1798. type: 'PROPPATCH',
  1799. url: saveHref,
  1800. cache: false,
  1801. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true: inputResource.crossDomain),
  1802. xhrFields: {
  1803. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false: inputResource.withCredentials)
  1804. },
  1805. timeout: inputResource.timeOut,
  1806. beforeSend: function(req){
  1807. if(globalSettings.usejqueryauth.value!=true && inputResource.userAuth.userName!='' && inputResource.userAuth.userPassword!='')
  1808. req.setRequestHeader('Authorization', basicAuth(inputResource.userAuth.userName, inputResource.userAuth.userPassword));
  1809. req.setRequestHeader('X-client', globalXClientHeader);
  1810. req.setRequestHeader('Depth', '0');
  1811. },
  1812. username: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userName : null),
  1813. password: (globalSettings.usejqueryauth.value==true ? inputResource.userAuth.userPassword : null),
  1814. contentType: 'text/xml',
  1815. processData: true,
  1816. data: '<?xml version="1.0" encoding="utf-8"?><D:propertyupdate xmlns:D="DAV:"><D:set><D:prop><I:settings xmlns:I="http://inf-it.com/ns/dav/">'+JSON.stringify(serverSettingss)+'</I:settings></D:prop></D:set></D:propertyupdate>',
  1817. dataType: 'xml',
  1818. error: function(objAJAXRequest, strError){
  1819. console.log("Error: [netSaveSettings: 'PROPPATCH "+uidFull+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' (this error code usually means network connection error, or your browser is trying to make a cross domain query, but it is not allowed by the destination server or the browser itself)': ''));
  1820. if(isAvaible('Settings'))
  1821. show_editor_loader_messageSettings('message_error', localization[globalInterfaceLanguage].errSettingsSaved);
  1822. var loader=null;
  1823. if(typeof globalSettingsSaving!='undefined')
  1824. {
  1825. if(globalSettingsSaving=='event')
  1826. loader=$('#CalendarLoader');
  1827. else if(globalSettingsSaving=='todo')
  1828. loader=$('#CalendarLoaderTODO');
  1829. else if(globalSettingsSaving=='addressbook')
  1830. loader=$('#AddressbookOverlay');
  1831. }
  1832. if(loader!=null)
  1833. {
  1834. loader.addClass('message_error').children('.loaderInfo').text(localization[globalInterfaceLanguage].errCollectionLoad);
  1835. setTimeout(function(){
  1836. loader.addClass('loader_hidden').removeClass('message_error').children('.loaderInfo').text('');
  1837. }, globalHideInfoMessageAfter);
  1838. }
  1839. globalSettingsSaving='';
  1840. return false;
  1841. },
  1842. success: function(data, textStatus, xml)
  1843. {
  1844. if(isAvaible('Settings')&&isFormSave)
  1845. {
  1846. /* if((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync))
  1847. {
  1848. var myInt = setInterval(function(){
  1849. if((isAvaible('CardDavMATE')&&!globalCardDAVResourceSync) && (isAvaible('CalDavZAP')&&!globalCalDAVResourceSync))
  1850. {
  1851. clearInterval(myInt);
  1852. applySettings(getChangedSettings(globalSettings, inputSettings));
  1853. globalSettings = inputSettings;
  1854. }
  1855. },100);
  1856. }
  1857. else
  1858. {*/
  1859. applySettings(getChangedSettings(globalSettings, inputSettings));
  1860. globalSettings = inputSettings;
  1861. // }
  1862. }
  1863. else if(collectionLoad)
  1864. {
  1865. /* if((isAvaible('CardDavMATE')&&globalCardDAVResourceSync) || (isAvaible('CalDavZAP')&&globalCalDAVResourceSync))
  1866. {
  1867. var myInt = setInterval(function(){
  1868. if((isAvaible('CardDavMATE')&&!globalCardDAVResourceSync) && (isAvaible('CalDavZAP')&&!globalCalDAVResourceSync))
  1869. {
  1870. clearInterval(myInt);
  1871. checkForLoadedCollections(inputSettings);
  1872. globalSettings = inputSettings;
  1873. }
  1874. },100);
  1875. }
  1876. else
  1877. {*/
  1878. checkForLoadedCollections(inputSettings);
  1879. globalSettings = inputSettings;
  1880. // }
  1881. }
  1882. }
  1883. });
  1884. }
  1885. function unlockCollection(inputContactObj)
  1886. {
  1887. var tmp=inputContactObj.uid.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)([^/]+/)([^/]*)','i'));
  1888. var collection_uid=tmp[1]+tmp[2]+'@'+tmp[3]+tmp[4]+tmp[5];
  1889. var lockToken=globalResourceCardDAVList.getCollectionByUID(collection_uid).lockToken;
  1890. // resource not locked, we cannot unlock it
  1891. if(lockToken=='undefined' || lockToken==null)
  1892. return false;
  1893. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5];
  1894. var put_href_part=tmp[4]+tmp[5];
  1895. var resourceSettings=null;
  1896. // find the original settings for the resource and user
  1897. var tmp=inputContactObj.accountUID.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)','i'));
  1898. var resource_href=tmp[1]+tmp[3]+tmp[4];
  1899. var resource_user=tmp[2];
  1900. for(var i=0;i<globalAccountSettings.length;i++)
  1901. if(globalAccountSettings[i].href==resource_href && globalAccountSettings[i].userAuth.userName==resource_user)
  1902. resourceSettings=globalAccountSettings[i];
  1903. if(resourceSettings==null)
  1904. return false;
  1905. // the begin of each error message
  1906. var errBegin=localization[globalInterfaceLanguage].errUnableUnlockBegin;
  1907. $.ajax({
  1908. type: 'UNLOCK',
  1909. url: put_href,
  1910. cache: false,
  1911. crossDomain: (typeof resourceSettings.crossDomain=='undefined' ? true : resourceSettings.crossDomain),
  1912. xhrFields: {
  1913. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false : resourceSettings.withCredentials)
  1914. },
  1915. timeout: resourceSettings.timeOut,
  1916. beforeSend: function(req) {
  1917. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  1918. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName,resourceSettings.userAuth.userPassword));
  1919. req.setRequestHeader('X-client', globalXClientHeader);
  1920. // req.setRequestHeader('Depth', '0');
  1921. if(lockToken!=null)
  1922. req.setRequestHeader('Lock-Token', '<'+lockToken+'>');
  1923. },
  1924. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  1925. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  1926. data: '',
  1927. error: function(objAJAXRequest, strError){
  1928. console.log("Error: [unlockCollection: 'UNLOCK "+put_href+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  1929. switch(objAJAXRequest.status)
  1930. {
  1931. case 401:
  1932. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp401),globalHideInfoMessageAfter);
  1933. break;
  1934. case 403:
  1935. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp403),globalHideInfoMessageAfter);
  1936. break;
  1937. case 405:
  1938. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp405),globalHideInfoMessageAfter);
  1939. break;
  1940. case 408:
  1941. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp408),globalHideInfoMessageAfter);
  1942. break;
  1943. case 500:
  1944. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp500),globalHideInfoMessageAfter);
  1945. break;
  1946. case 501:
  1947. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp501),globalHideInfoMessageAfter);
  1948. break;
  1949. default:
  1950. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttpCommon.replace('%%',objAJAXRequest.status)),globalHideInfoMessageAfter);
  1951. break;
  1952. }
  1953. return false;
  1954. },
  1955. success: function(data, textStatus, xml)
  1956. {
  1957. globalResourceCardDAVList.setCollectionFlagByUID(collection_uid, 'lockToken', null);
  1958. return true;
  1959. }
  1960. });
  1961. }
  1962. function operationPerform(inputPerformOperation, inputContactObj, inputFilterUID)
  1963. {
  1964. if(inputPerformOperation=='PUT')
  1965. {
  1966. var tmp=new Array();
  1967. var groupArr=new Array();
  1968. //check vcard groups to add
  1969. if(typeof inputContactObj.addToContactGroupUID!='undefined' && inputContactObj.addToContactGroupUID.length>0)
  1970. groupArr=globalAddressbookList.getAddMeToContactGroups(inputContactObj, inputContactObj.addToContactGroupUID);
  1971. else if(typeof inputContactObj.formSave=='undefined')
  1972. groupArr=globalAddressbookList.getAddMeToContactGroups(inputContactObj, inputFilterUID);
  1973. if(groupArr!=null)
  1974. tmp=tmp.concat(groupArr)
  1975. //check vcard groups to remove
  1976. groupArr=new Array();
  1977. if(typeof inputContactObj.removeToContactGroupUID!='undefined' && inputContactObj.removeToContactGroupUID.length>0)
  1978. groupArr=globalAddressbookList.getRemoveMeFromContactGroups(inputContactObj.uid, inputContactObj.removeToContactGroupUID);
  1979. else if(typeof inputContactObj.formSave=='undefined')
  1980. groupArr=globalAddressbookList.getRemoveMeFromContactGroups(inputContactObj.uid, null);
  1981. if(groupArr!=null)
  1982. tmp=tmp.concat(groupArr)
  1983. if(tmp.length>0)
  1984. var inputContactObjArr=new Array($.extend({withoutLockTocken: true}, inputContactObj));
  1985. else
  1986. var inputContactObjArr=new Array(inputContactObj);
  1987. inputContactObjArr=inputContactObjArr.concat(tmp);
  1988. putVcardToCollection(inputContactObjArr, inputFilterUID, 'PUT_ALL', null);
  1989. }
  1990. else if(inputPerformOperation=='DELETE')
  1991. {
  1992. var tmp=globalAddressbookList.getRemoveMeFromContactGroups(inputContactObj.uid, null);
  1993. var inputContactObjArr=new Array(inputContactObj);
  1994. inputContactObjArr=tmp.concat(inputContactObjArr);
  1995. if(inputContactObjArr.length==1)
  1996. deleteVcardFromCollection(inputContactObjArr[0], inputFilterUID, 'DELETE_LAST');
  1997. else
  1998. putVcardToCollection(inputContactObjArr, inputFilterUID, 'DELETE_LAST', null);
  1999. }
  2000. else if(inputPerformOperation=='ADD_TO_GROUP')
  2001. {
  2002. var tmp=globalAddressbookList.getAddMeToContactGroups(inputContactObj, [inputContactObj.addToContactGroupUID]);
  2003. tmp[0].uiObjects=inputContactObj.uiObjects
  2004. tmp[0].uidContact = inputContactObj.uid;
  2005. var inputContactObjArr=tmp;
  2006. putVcardToCollection(inputContactObjArr, inputFilterUID, 'ADD_TO_GROUP_LAST', null);
  2007. }
  2008. else if(inputPerformOperation=='DELETE_FROM_GROUP')
  2009. {
  2010. var inputContactObjArr=globalAddressbookList.getRemoveMeFromContactGroups(inputContactObj.uid, [inputFilterUID]);
  2011. putVcardToCollection(inputContactObjArr, inputFilterUID, 'DELETE_FROM_GROUP_LAST', null);
  2012. }
  2013. else if(inputPerformOperation=='IRM_DELETE')
  2014. {
  2015. var tmp=new Array();
  2016. if(typeof inputContactObj.addToContactGroupUID!='undefined' && inputContactObj.addToContactGroupUID.length>0)
  2017. tmp=tmp.concat(globalAddressbookList.getAddMeToContactGroups({vcard:inputContactObj.vcard,uid:inputContactObj.orgUID}, inputContactObj.addToContactGroupUID));
  2018. if(typeof inputContactObj.removeToContactGroupUID!='undefined' && inputContactObj.removeToContactGroupUID.length)
  2019. tmp=tmp.concat(globalAddressbookList.getRemoveMeFromContactGroups(inputContactObj.uid, inputContactObj.removeToContactGroupUID));
  2020. else
  2021. tmp=tmp.concat(globalAddressbookList.getRemoveMeFromContactGroups(inputContactObj.uid, null));
  2022. var inputContactObjArr=new Array($.extend({withoutLockTocken: true}, inputContactObj), inputContactObj); // first is used for PUT to destination resource (without lock token) and the second for the DELETE
  2023. inputContactObjArr=tmp.concat(inputContactObjArr);
  2024. putVcardToCollection(inputContactObjArr, inputFilterUID, 'IRM_DELETE_LAST', null);
  2025. }
  2026. else if(inputPerformOperation=='MOVE')
  2027. {
  2028. var tmp=globalAddressbookList.getRemoveMeFromContactGroups(inputContactObj.uid, null);
  2029. var inputContactObjArr=new Array(inputContactObj);
  2030. inputContactObjArr=tmp.concat(inputContactObjArr);
  2031. if(inputContactObjArr.length==1)
  2032. moveVcardToCollection(inputContactObjArr[0], inputFilterUID);
  2033. else
  2034. putVcardToCollection(inputContactObjArr, inputFilterUID, 'MOVE_LAST', null);
  2035. }
  2036. }
  2037. function operationPerformed(inputPerformOperation, inputContactObj, loadContactObj)
  2038. {
  2039. var collUID = inputContactObj.uid.replace(RegExp('[^/]*$'),'');
  2040. if(inputPerformOperation=='ADD_TO_GROUP_LAST' && typeof inputContactObj.uiObjects.contact!='undefined')
  2041. {
  2042. // success icon
  2043. setTimeout(function(){
  2044. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  2045. resource.addClass('r_success');
  2046. resource.removeClass('r_operate');
  2047. setTimeout(function(){
  2048. if($('#ExtendedDest').length>0)
  2049. extendDestSelect();
  2050. checkForVcardGroups(inputContactObj.uidContact);
  2051. inputContactObj.uiObjects.contact.animate({opacity: 1}, 750);
  2052. inputContactObj.uiObjects.contact.draggable('option', 'disabled', false);
  2053. resource.removeClass('r_success');
  2054. resource.droppable('option', 'disabled', false);
  2055. },1200);
  2056. },1000);
  2057. }
  2058. // contact group operation (only one contact group is changed at once)
  2059. else if(inputPerformOperation=='DELETE_FROM_GROUP_LAST')
  2060. {
  2061. // success message
  2062. var duration=show_editor_message('out','message_success',localization[globalInterfaceLanguage].succContactDeletedFromGroup,globalHideInfoMessageAfter);
  2063. // after the success message show the next automatically selected contact
  2064. var animation=400;
  2065. setTimeout(function(){
  2066. $('#ResourceCardDAVListOverlay').fadeOut(animation);
  2067. $('#ABListOverlay').fadeOut(animation,function(){});
  2068. $('#ABContactOverlay').fadeOut(animation,function(){globalRefAddContact.prop('disabled',false);});
  2069. },duration-animation);
  2070. }
  2071. // contact is added but it is hidden due to search filter
  2072. else if(typeof globalAddressbookList.contacts_hash[inputContactObj.uid]!='undefined' && (globalAddressbookList.contacts_hash[inputContactObj.uid].search_hide||!globalAddressbookList.contacts_hash[inputContactObj.uid].show))
  2073. {
  2074. // load the modified contact
  2075. globalAddressbookList.loadContactByUID(loadContactObj.uid);
  2076. // success message
  2077. var duration=show_editor_message('in','message_success',localization[globalInterfaceLanguage].succContactSaved,globalHideInfoMessageAfter);
  2078. // after the success message show the next automatically selected contact
  2079. // setTimeout(function(){
  2080. $('#ResourceCardDAVListOverlay').fadeOut(globalHideInfoMessageAfter);
  2081. $('#ABListOverlay').fadeOut(globalHideInfoMessageAfter,function(){});
  2082. $('#ABContactOverlay').fadeOut(globalHideInfoMessageAfter,function(){globalRefAddContact.prop('disabled',false);});
  2083. // },duration+globalHideInfoMessageAfter);
  2084. }
  2085. else
  2086. {
  2087. if(typeof inputContactObj.newUID!='undefined' && typeof globalAddressbookList.contacts_hash[inputContactObj.newUID]!='undefined' && (globalAddressbookList.contacts_hash[inputContactObj.newUID].search_hide||!globalAddressbookList.contacts_hash[inputContactObj.newUID].show))
  2088. globalDisableAnimationMessageHiding='errContactHidden';
  2089. // load the modified contact
  2090. if(typeof loadContactObj.isInterResource=='undefined' || loadContactObj.isInterResource==null || !loadContactObj.isInterResource)
  2091. globalAddressbookList.loadContactByUID(loadContactObj.uid);
  2092. // success message
  2093. show_editor_message('in','message_success',localization[globalInterfaceLanguage].succContactSaved,globalHideInfoMessageAfter);
  2094. // presunut do jednej funkcie s tym co je vyssie
  2095. $('#ResourceCardDAVListOverlay').fadeOut(globalHideInfoMessageAfter);
  2096. $('#ABListOverlay').fadeOut(globalHideInfoMessageAfter);
  2097. $('#ABContactOverlay').fadeOut(globalHideInfoMessageAfter,function(){globalRefAddContact.prop('disabled',false);});
  2098. }
  2099. unlockCollection(inputContactObj);
  2100. }
  2101. function lockAndPerformToCollection(inputContactObj, inputFilterUID, inputPerformOperation)
  2102. {
  2103. if(typeof(globalContactsExtLockAndPerformOverload)=='function')
  2104. {
  2105. globalContactsExtLockAndPerformOverload();
  2106. return;
  2107. }
  2108. var tmp=inputContactObj.uid.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)([^/]+/)([^/]*)','i'));
  2109. var collection_uid=tmp[1]+tmp[2]+'@'+tmp[3]+tmp[4]+tmp[5];
  2110. // If locking is unsupported or disabled we don't try to LOCK the collection
  2111. if(globalResourceCardDAVList.getCollectionByUID(collection_uid).disableLocking)
  2112. {
  2113. // perform the operation without locking
  2114. operationPerform(inputPerformOperation, inputContactObj, inputFilterUID);
  2115. return true;
  2116. }
  2117. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5];
  2118. var put_href_part=tmp[4]+tmp[5];
  2119. var resourceSettings=null;
  2120. // find the original settings for the resource and user
  2121. var tmp=inputContactObj.accountUID.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)','i'));
  2122. var resource_href=tmp[1]+tmp[3]+tmp[4];
  2123. var resource_user=tmp[2];
  2124. for(var i=0;i<globalAccountSettings.length;i++)
  2125. if(globalAccountSettings[i].href==resource_href && globalAccountSettings[i].userAuth.userName==resource_user)
  2126. resourceSettings=globalAccountSettings[i];
  2127. if(resourceSettings==null)
  2128. return false;
  2129. // the begin of each error message
  2130. var errBegin=localization[globalInterfaceLanguage].errUnableLockBegin;
  2131. $.ajax({
  2132. type: 'LOCK',
  2133. url: put_href,
  2134. cache: false,
  2135. crossDomain: (typeof resourceSettings.crossDomain=='undefined' ? true : resourceSettings.crossDomain),
  2136. xhrFields: {
  2137. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false : resourceSettings.withCredentials)
  2138. },
  2139. timeout: resourceSettings.timeOut,
  2140. beforeSend: function(req)
  2141. {
  2142. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  2143. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName,resourceSettings.userAuth.userPassword));
  2144. req.setRequestHeader('X-client', globalXClientHeader);
  2145. req.setRequestHeader('Depth', '0');
  2146. // we support only one contact group at once + the contact + reserve :)
  2147. req.setRequestHeader('Timeout', 'Second-'+Math.ceil((resourceSettings.lockTimeOut!=undefined ? resourceSettings.lockTimeOut : 10000)/1000));
  2148. },
  2149. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  2150. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  2151. contentType: 'text/xml; charset=utf-8',
  2152. processData: false,
  2153. data: '<?xml version="1.0" encoding="utf-8"?><D:lockinfo xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype><D:owner><D:href>'+escape(collection_uid)+'</D:href></D:owner></D:lockinfo>',
  2154. dataType: 'text',
  2155. error: function(objAJAXRequest, strError)
  2156. {
  2157. // if we tried to LOCK the collection but the server not supports this request we perform
  2158. // the operation without LOCK (even if it is dangerous and can cause data integrity errors)
  2159. if(objAJAXRequest.status==501)
  2160. operationPerform(inputPerformOperation, inputContactObj, inputFilterUID);
  2161. // if the operation type is 'MOVE' we cannot show error messages, error icon is used instead
  2162. else if(inputPerformOperation!='MOVE')
  2163. {
  2164. console.log("Error: [unlockCollection: 'LOCK "+put_href+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2165. switch(objAJAXRequest.status)
  2166. {
  2167. case 401:
  2168. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp401),globalHideInfoMessageAfter);
  2169. break;
  2170. case 403:
  2171. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp403),globalHideInfoMessageAfter);
  2172. break;
  2173. case 405:
  2174. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp405),globalHideInfoMessageAfter);
  2175. break;
  2176. case 408:
  2177. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp408),globalHideInfoMessageAfter);
  2178. break;
  2179. case 500:
  2180. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp500),globalHideInfoMessageAfter);
  2181. break;
  2182. default:
  2183. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttpCommon.replace('%%',objAJAXRequest.status)),globalHideInfoMessageAfter);
  2184. break;
  2185. }
  2186. // error icon
  2187. setTimeout(function(){
  2188. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  2189. resource.addClass('r_error');
  2190. resource.removeClass('r_operate');
  2191. setTimeout(function(){
  2192. inputContactObj.uiObjects.contact.animate({opacity: 1}, 1000);
  2193. inputContactObj.uiObjects.contact.draggable('option', 'disabled', false);
  2194. resource.removeClass('r_error');
  2195. resource.droppable('option', 'disabled', false);
  2196. },globalHideInfoMessageAfter);
  2197. },globalHideInfoMessageAfter/10);
  2198. }
  2199. $('#ABContactOverlay').fadeOut(globalEditorFadeAnimation,function(){globalRefAddContact.prop('disabled',false);});
  2200. return false;
  2201. },
  2202. success: function(data, textStatus, xml)
  2203. {
  2204. // workaround for jQuery 2.0.0
  2205. if(xml.responseXML==undefined)
  2206. xml.responseXML=$.parseXML(xml.responseText);
  2207. var lockToken=$(xml.responseXML).children().filterNsNode('prop').children().filterNsNode('lockdiscovery').children().filterNsNode('activelock').children().filterNsNode('locktoken').children().filterNsNode('href').text();
  2208. globalResourceCardDAVList.setCollectionFlagByUID(collection_uid, 'lockToken', (lockToken=='' ? null : lockToken));
  2209. // We have a lock!
  2210. if(lockToken!='')
  2211. {
  2212. // synchronously reload the contact changes (get the latest version of contact group vcards)
  2213. var collection=globalResourceCardDAVList.getCollectionByUID(collection_uid);
  2214. collection.filterUID=inputFilterUID;
  2215. CardDAVnetLoadCollection(collection, false, false, {call: 'operationPerform', args: {performOperation: inputPerformOperation, contactObj: inputContactObj, filterUID: inputFilterUID}}, 0, null, false);
  2216. return true;
  2217. }
  2218. else
  2219. {
  2220. // We assume that empty lockToken means 423 Resource Locked error
  2221. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errResourceLocked),globalHideInfoMessageAfter);
  2222. // error icon
  2223. if(inputContactObj.uiObjects!=undefined) // only for drag&drop operation
  2224. {
  2225. setTimeout(function(){
  2226. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  2227. resource.addClass('r_error');
  2228. resource.removeClass('r_operate');
  2229. setTimeout(function(){
  2230. inputContactObj.uiObjects.contact.animate({opacity: 1}, 1000);
  2231. inputContactObj.uiObjects.contact.draggable('option', 'disabled', false);
  2232. resource.removeClass('r_error');
  2233. resource.droppable('option', 'disabled', false);
  2234. },globalHideInfoMessageAfter);
  2235. },globalHideInfoMessageAfter/10);
  2236. }
  2237. $('#ABContactOverlay').fadeOut(globalEditorFadeAnimation,function(){globalRefAddContact.prop('disabled',false);});
  2238. }
  2239. return false;
  2240. }
  2241. });
  2242. }
  2243. function putVcardToCollectionMain(inputContactObj, inputFilterUID)
  2244. {
  2245. if(inputContactObj.etag=='')
  2246. {
  2247. if(inputFilterUID[inputFilterUID.length-1]!='/') // new contact with vCard group (we must use locking)
  2248. {
  2249. lockAndPerformToCollection(inputContactObj, inputFilterUID, 'PUT');
  2250. }
  2251. else // new contact without vCard group (no locking required)
  2252. putVcardToCollection(inputContactObj, inputFilterUID, 'PUT_ALL', null);
  2253. }
  2254. else // existing contact modification (there is no support for contact group modification -> no locking required)
  2255. putVcardToCollection(inputContactObj, inputFilterUID, 'PUT_ALL', null);
  2256. }
  2257. function putVcardToCollection(inputContactObjArr, inputFilterUID, recursiveMode, loadContactWithUID)
  2258. {
  2259. if(!(inputContactObjArr instanceof Array))
  2260. inputContactObjArr=[inputContactObjArr];
  2261. var inputContactObj=inputContactObjArr.splice(0,1);
  2262. inputContactObj=inputContactObj[0];
  2263. // drag & drop inter-resoruce move (we need to change the object parameters)
  2264. if(inputContactObj.newAccountUID!=undefined && inputContactObj.newUid!=undefined)
  2265. {
  2266. inputContactObj.accountUID=inputContactObj.newAccountUID;
  2267. inputContactObj.uid=inputContactObj.newUid;
  2268. inputContactObj.etag='';
  2269. }
  2270. var tmp=inputContactObj.uid.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)([^/]+/)([^/]*)','i'));
  2271. var collection_uid=tmp[1]+tmp[2]+'@'+tmp[3]+tmp[4]+tmp[5];
  2272. var lockToken=globalResourceCardDAVList.getCollectionByUID(collection_uid).lockToken;
  2273. var color=globalResourceCardDAVList.getCollectionByUID(collection_uid).color;
  2274. // if inputContactObj.etag is empty, we have a newly created contact and need to create a .vcf file name for it
  2275. if(inputContactObj.etag!='') // existing contact
  2276. {
  2277. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+tmp[6];
  2278. var put_href_part=tmp[4]+tmp[5]+tmp[6];
  2279. }
  2280. else // new contact
  2281. {
  2282. var vcardFile=hex_sha256(inputContactObj.vcard+(new Date().getTime()))+'.vcf';
  2283. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+vcardFile;
  2284. var put_href_part=tmp[4]+tmp[5]+vcardFile;
  2285. inputContactObj.uid+=vcardFile;
  2286. }
  2287. if(loadContactWithUID==null) // store the first contact (it will be reloaded and marked as active)
  2288. loadContactWithUID=inputContactObj;
  2289. var resourceSettings=null;
  2290. // find the original settings for the resource and user
  2291. var tmp=inputContactObj.accountUID.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)','i'));
  2292. var resource_href=tmp[1]+tmp[3]+tmp[4];
  2293. var resource_user=tmp[2];
  2294. for(var i=0;i<globalAccountSettings.length;i++)
  2295. if(globalAccountSettings[i].href==resource_href && globalAccountSettings[i].userAuth.userName==resource_user)
  2296. resourceSettings=globalAccountSettings[i];
  2297. if(resourceSettings==null)
  2298. return false;
  2299. // the begin of each error message
  2300. var errBegin=localization[globalInterfaceLanguage].errUnableSaveBegin;
  2301. var vcardList= new Array();
  2302. $.ajax({
  2303. type: 'PUT',
  2304. url: put_href,
  2305. cache: false,
  2306. crossDomain: (typeof resourceSettings.crossDomain=='undefined' ? true : resourceSettings.crossDomain),
  2307. xhrFields: {
  2308. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false : resourceSettings.withCredentials)
  2309. },
  2310. timeout: resourceSettings.timeOut,
  2311. beforeSend: function(req)
  2312. {
  2313. req.setRequestHeader('Prefer', 'return=representation');
  2314. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  2315. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName,resourceSettings.userAuth.userPassword));
  2316. req.setRequestHeader('X-client', globalXClientHeader);
  2317. if(lockToken!=null && inputContactObj.withoutLockTocken!=true)
  2318. req.setRequestHeader('Lock-Token', '<'+lockToken+'>');
  2319. if(inputContactObj.etag!='')
  2320. req.setRequestHeader('If-Match', inputContactObj.etag);
  2321. else // adding new contact
  2322. req.setRequestHeader('If-None-Match', '*');
  2323. },
  2324. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  2325. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  2326. contentType: 'text/vcard',
  2327. processData: true,
  2328. data: inputContactObj.vcard,
  2329. dataType: 'text',
  2330. error: function(objAJAXRequest, strError)
  2331. {
  2332. if(recursiveMode=='MOVE_LAST' || recursiveMode=='IRM_DELETE_LAST' || recursiveMode=='ADD_TO_GROUP_LAST')
  2333. {
  2334. // error icon
  2335. setTimeout(function(){
  2336. var moveContactObj=inputContactObjArr[inputContactObjArr.length-1];
  2337. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(moveContactObj.uiObjects.resource)+'"]');
  2338. resource.addClass('r_error');
  2339. resource.removeClass('r_operate');
  2340. setTimeout(function(){
  2341. moveContactObj.uiObjects.contact.animate({opacity: 1}, 1000);
  2342. moveContactObj.uiObjects.contact.draggable('option', 'disabled', false);
  2343. resource.removeClass('r_error');
  2344. resource.droppable('option', 'disabled', false);
  2345. },1200);
  2346. },1000);
  2347. }
  2348. else
  2349. {
  2350. console.log("Error: [putVcardToCollection: 'PUT "+put_href+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2351. switch(objAJAXRequest.status)
  2352. {
  2353. case 401:
  2354. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp401),globalHideInfoMessageAfter);
  2355. break;
  2356. case 403:
  2357. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp403),globalHideInfoMessageAfter);
  2358. break;
  2359. case 405:
  2360. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp405),globalHideInfoMessageAfter);
  2361. break;
  2362. case 408:
  2363. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp408),globalHideInfoMessageAfter);
  2364. break;
  2365. case 412:
  2366. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp412),globalHideInfoMessageAfter);
  2367. break;
  2368. case 500:
  2369. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp500),globalHideInfoMessageAfter);
  2370. break;
  2371. default:
  2372. show_editor_message('in','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttpCommon.replace('%%',objAJAXRequest.status)),globalHideInfoMessageAfter);
  2373. break;
  2374. }
  2375. }
  2376. // presunut do jednej funkcie s tym co je nizsie pri success
  2377. //$('#ResourceCardDAVListOverlay').fadeOut(1200);
  2378. //$('#ABListOverlay').fadeOut(1200);
  2379. $('#ABContactOverlay').fadeOut(globalEditorFadeAnimation,function(){globalRefAddContact.prop('disabled',false);});
  2380. unlockCollection(inputContactObj);
  2381. return false;
  2382. },
  2383. success: function(data, textStatus, xml)
  2384. {
  2385. if(inputContactObjArr.length==1 && (recursiveMode=='DELETE_LAST' || recursiveMode=='IRM_DELETE_LAST'))
  2386. {
  2387. inputContactObjArr[0].newUID=inputContactObj.uid;
  2388. deleteVcardFromCollection(inputContactObjArr[0], inputFilterUID, recursiveMode);
  2389. return true;
  2390. }
  2391. else if(inputContactObjArr.length==1 && recursiveMode=='MOVE_LAST')
  2392. {
  2393. moveVcardToCollection(inputContactObjArr[0], inputFilterUID);
  2394. return true;
  2395. }
  2396. var newEtag=xml.getResponseHeader('Etag');
  2397. // We get the Etag from the PUT response header instead of new collection sync (if the server supports this feature)
  2398. if(newEtag!=undefined && newEtag!=null && newEtag!='')
  2399. {
  2400. // do not remove the contact group from the interface (if removed there are many GUI animation inconsistencies)
  2401. if(!globalAddressbookList.isContactGroup(inputContactObj.vcard))
  2402. globalAddressbookList.removeContact(inputContactObj.uid,false);
  2403. var rawVcard=inputContactObj.vcard;
  2404. if(xml.getResponseHeader('Preference-Applied')=='return=representation' && xml.responseText)
  2405. rawVcard=additionalRFCFixes(basicRFCFixesAndCleanup(xml.responseText)); // we cannot expect RFC compliant result here
  2406. else
  2407. // remove line folding (added before the PUT operation)
  2408. // by default it is a part of basicRFCFixesAndCleanup but we don't need cleanup here!
  2409. rawVcard=rawVcard.replace(vCard.pre['basicRFCFixesAndCleanup_rnwsp-gm'], '');
  2410. var vcard=normalizeVcard(rawVcard);
  2411. var categories='';
  2412. if((vcard_element=vcard.match(vCard.pre['contentline_CATEGORIES']))!=null)
  2413. {
  2414. // parsed (contentline_parse) = [1]->"group.", [2]->"name", [3]->";param;param", [4]->"value"
  2415. parsed=vcard_element[0].match(vCard.pre['contentline_parse']);
  2416. categories=parsed[4];
  2417. }
  2418. globalAddressbookList.insertContact({timestamp: new Date().getTime(), accountUID: inputContactObj.accountUID, uid: inputContactObj.uid, etag: newEtag, color: color, vcard: vcard, categories: categories, normalized: true}, true, false);
  2419. globalQs.cache(); // update the active search
  2420. // XXX check this
  2421. // globalAddressbookList.applyABFilter(inputFilterUID, recursiveMode=='DELETE_FROM_GROUP_LAST' || globalRefABListTable.find('[data-id="'+jqueryEscapeSelector(inputContactObj.uid)+'"]').hasClass('search_hide') ? true : false);
  2422. globalAddressbookList.applyABFilter(dataGetChecked('#ResourceCardDAVList'), recursiveMode=='DELETE_FROM_GROUP_LAST' || (typeof globalAddressbookList.contacts_hash[inputContactObj.uid]!='undefined'&&(globalAddressbookList.contacts_hash[inputContactObj.uid].search_hide||!globalAddressbookList.contacts_hash[inputContactObj.uid].show)) ? true : false);
  2423. }
  2424. else // otherwise mark collection for full sync
  2425. globalResourceCardDAVList.setCollectionFlagByUID(collection_uid, 'forceSync', true);
  2426. if(inputContactObjArr.length>0)
  2427. putVcardToCollection(inputContactObjArr, inputFilterUID, recursiveMode, loadContactWithUID);
  2428. else
  2429. {
  2430. var collection=globalResourceCardDAVList.getCollectionByUID(collection_uid);
  2431. if(collection.forceSync===true)
  2432. {
  2433. globalResourceCardDAVList.setCollectionFlagByUID(collection_uid, 'forceSync', false);
  2434. collection.filterUID=inputFilterUID;
  2435. // for DELETE_FROM_GROUP_LAST we need to force reload the contact (because the editor is in "edit" state = the contact is not loaded automatically)
  2436. CardDAVnetLoadCollection(collection, false, recursiveMode=='DELETE_FROM_GROUP_LAST' ? true : false, {call: 'operationPerformed', args: {mode: recursiveMode, contactObj: inputContactObj, loadContact: loadContactWithUID, forceReload: true}}, 0, null, false);
  2437. return true;
  2438. }
  2439. operationPerformed(recursiveMode, inputContactObj, loadContactWithUID);
  2440. }
  2441. return true;
  2442. }
  2443. });
  2444. }
  2445. function moveVcardToCollection(inputContactObj, inputFilterUID)
  2446. {
  2447. var tmp=inputContactObj.uid.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)([^/]+/)([^/]*)','i'));
  2448. var collection_uid=tmp[1]+tmp[2]+'@'+tmp[3]+tmp[4]+tmp[5];
  2449. var lockToken=globalResourceCardDAVList.getCollectionByUID(collection_uid).lockToken;
  2450. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+tmp[6];
  2451. var put_href_part=tmp[4]+tmp[5]+tmp[6];
  2452. var resourceSettings=null;
  2453. // find the original settings for the resource and user
  2454. var tmp=inputContactObj.accountUID.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)','i'));
  2455. var resource_href=tmp[1]+tmp[3]+tmp[4];
  2456. var resource_user=tmp[2];
  2457. for(var i=0;i<globalAccountSettings.length;i++)
  2458. if(globalAccountSettings[i].href==resource_href && globalAccountSettings[i].userAuth.userName==resource_user)
  2459. resourceSettings=globalAccountSettings[i];
  2460. if(resourceSettings==null)
  2461. return false;
  2462. var vcardList= new Array();
  2463. $.ajax({
  2464. type: 'MOVE',
  2465. url: put_href,
  2466. cache: false,
  2467. crossDomain: (typeof resourceSettings.crossDomain=='undefined' ? true : resourceSettings.crossDomain),
  2468. xhrFields: {
  2469. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false : resourceSettings.withCredentials)
  2470. },
  2471. timeout: resourceSettings.timeOut,
  2472. beforeSend: function(req)
  2473. {
  2474. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  2475. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName,resourceSettings.userAuth.userPassword));
  2476. req.setRequestHeader('X-client', globalXClientHeader);
  2477. if(lockToken!=null)
  2478. req.setRequestHeader('Lock-Token', '<'+lockToken+'>');
  2479. req.setRequestHeader('Destination', inputContactObj.moveDest);
  2480. },
  2481. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  2482. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  2483. contentType: typeof inputContactObj.finalContactUID!='undefined' ? 'text/vcard' : '',
  2484. processData: typeof inputContactObj.finalContactUID!='undefined' ? true : false,
  2485. data: typeof inputContactObj.finalContactUID!='undefined' ? inputContactObj.vcard : '',
  2486. dataType: typeof inputContactObj.finalContactUID!='undefined' ? 'text' : '',
  2487. error: function(objAJAXRequest, strError)
  2488. {
  2489. // error icon
  2490. setTimeout(function(){
  2491. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  2492. resource.addClass('r_error');
  2493. resource.removeClass('r_operate');
  2494. setTimeout(function(){
  2495. inputContactObj.uiObjects.contact.animate({opacity: 1}, 1000);
  2496. inputContactObj.uiObjects.contact.draggable('option', 'disabled', false);
  2497. resource.removeClass('r_error');
  2498. resource.droppable('option', 'disabled', false);
  2499. },1200);
  2500. },1000);
  2501. unlockCollection(inputContactObj);
  2502. },
  2503. success: function(data,textStatus,xml)
  2504. {
  2505. // success icon
  2506. setTimeout(function(){
  2507. // move is successfull we can remove the contact (no sync required)
  2508. globalAddressbookList.removeContact(inputContactObj.uid,true);
  2509. // XXX check this
  2510. // globalAddressbookList.applyABFilter(inputFilterUID, globalRefABListTable.find('[data-id="'+jqueryEscapeSelector(inputContactObj.uid)+'"]').hasClass('search_hide') ? true : false);
  2511. globalAddressbookList.applyABFilter(dataGetChecked('#ResourceCardDAVList'), (typeof globalAddressbookList.contacts_hash[inputContactObj.uid]!='undefined'&&(globalAddressbookList.contacts_hash[inputContactObj.uid].search_hide||!globalAddressbookList.contacts_hash[inputContactObj.uid].show)) ? true : false);
  2512. if(typeof inputContactObj.finalContactUID=='undefined')
  2513. {
  2514. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  2515. resource.addClass('r_success');
  2516. resource.removeClass('r_operate');
  2517. setTimeout(function(){
  2518. resource.removeClass('r_success');
  2519. resource.droppable('option', 'disabled', false);
  2520. },1200);
  2521. }
  2522. else
  2523. operationPerformed('PUT_ALL', inputContactObj, {uid:inputContactObj.finalContactUID});
  2524. },1000);
  2525. unlockCollection(inputContactObj);
  2526. // if the destination addressbook is already loaded re-sync it (to get the moved contact immediately)
  2527. var collection=globalResourceCardDAVList.getCollectionByUID(inputContactObj.moveDestUID);
  2528. CardDAVnetLoadCollection(collection, false, false, null, 0, null, false);
  2529. }
  2530. });
  2531. }
  2532. function deleteVcardFromCollection(inputContactObj, inputFilterUID, recursiveMode)
  2533. {
  2534. var tmp=inputContactObj.uid.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)([^/]+/)([^/]*)','i'));
  2535. var collection_uid=tmp[1]+tmp[2]+'@'+tmp[3]+tmp[4]+tmp[5];
  2536. var lockToken=globalResourceCardDAVList.getCollectionByUID(collection_uid).lockToken;
  2537. var put_href=tmp[1]+tmp[3]+tmp[4]+tmp[5]+tmp[6];
  2538. var resourceSettings=null;
  2539. // find the original settings for the resource and user
  2540. var tmp=inputContactObj.accountUID.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)','i'));
  2541. var resource_href=tmp[1]+tmp[3]+tmp[4];
  2542. var resource_user=tmp[2];
  2543. for(var i=0;i<globalAccountSettings.length;i++)
  2544. if(globalAccountSettings[i].href==resource_href && globalAccountSettings[i].userAuth.userName==resource_user)
  2545. resourceSettings=globalAccountSettings[i];
  2546. if(resourceSettings==null)
  2547. return false;
  2548. // the begin of each error message
  2549. var errBegin=localization[globalInterfaceLanguage].errUnableDeleteBegin;
  2550. $.ajax({
  2551. type: 'DELETE',
  2552. url: put_href,
  2553. cache: false,
  2554. crossDomain: (typeof resourceSettings.crossDomain=='undefined' ? true : resourceSettings.crossDomain),
  2555. xhrFields: {
  2556. withCredentials: (typeof resourceSettings.withCredentials=='undefined' ? false : resourceSettings.withCredentials)
  2557. },
  2558. timeout: resourceSettings.timeOut,
  2559. beforeSend: function(req) {
  2560. if(globalSettings.usejqueryauth.value!=true && resourceSettings.userAuth.userName!='' && resourceSettings.userAuth.userPassword!='')
  2561. req.setRequestHeader('Authorization', basicAuth(resourceSettings.userAuth.userName,resourceSettings.userAuth.userPassword));
  2562. req.setRequestHeader('X-client', globalXClientHeader);
  2563. if(lockToken!=null)
  2564. req.setRequestHeader('Lock-Token', '<'+lockToken+'>');
  2565. },
  2566. username: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userName : null),
  2567. password: (globalSettings.usejqueryauth.value==true ? resourceSettings.userAuth.userPassword : null),
  2568. data: '',
  2569. error: function(objAJAXRequest, strError)
  2570. {
  2571. // if the DELETE is performed as a part of inter-resource move operation (drag&drop)
  2572. if(recursiveMode=='IRM_DELETE_LAST' && typeof inputContactObj.finalContactUID=='undefined')
  2573. {
  2574. // error icon
  2575. setTimeout(function(){
  2576. if(typeof inputContactObj.finalContactUID=='undefined')
  2577. {
  2578. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  2579. resource.addClass('r_error');
  2580. resource.removeClass('r_operate');
  2581. setTimeout(function(){
  2582. inputContactObj.uiObjects.contact.animate({opacity: 1}, 1000);
  2583. inputContactObj.uiObjects.contact.draggable('option', 'disabled', false);
  2584. resource.removeClass('r_error');
  2585. resource.droppable('option', 'disabled', false);
  2586. },1200);
  2587. }
  2588. else
  2589. operationPerformed('PUT_ALL', inputContactObj, {uid:inputContactObj.uid, isInterResource:true});
  2590. },1000);
  2591. }
  2592. else
  2593. {
  2594. console.log("Error: [deleteVcardFromCollection: 'DELETE "+put_href+"']: code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2595. switch(objAJAXRequest.status)
  2596. {
  2597. case 401:
  2598. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp401),globalHideInfoMessageAfter);
  2599. break;
  2600. case 403:
  2601. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp403),globalHideInfoMessageAfter);
  2602. break;
  2603. case 405:
  2604. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp405),globalHideInfoMessageAfter);
  2605. break;
  2606. case 408:
  2607. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp408),globalHideInfoMessageAfter);
  2608. break;
  2609. case 410:
  2610. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp410),globalHideInfoMessageAfter);
  2611. break;
  2612. case 500:
  2613. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttp500),globalHideInfoMessageAfter);
  2614. break;
  2615. default:
  2616. show_editor_message('out','message_error',errBegin.replace('%%',localization[globalInterfaceLanguage].errHttpCommon.replace('%%',objAJAXRequest.status)),globalHideInfoMessageAfter);
  2617. break;
  2618. }
  2619. }
  2620. // presunut do jednej funkcie s tym co je nizsie pri success
  2621. $('#ResourceCardDAVListOverlay').fadeOut(globalEditorFadeAnimation);
  2622. $('#ABListOverlay').fadeOut(globalEditorFadeAnimation);
  2623. $('#ABContactOverlay').fadeOut(globalEditorFadeAnimation,function(){globalRefAddContact.prop('disabled',false);});
  2624. unlockCollection(inputContactObj);
  2625. },
  2626. success: function(data,textStatus,xml)
  2627. {
  2628. if(recursiveMode=='IRM_DELETE_LAST')
  2629. {
  2630. // success icon
  2631. setTimeout(function(){
  2632. // move is successfull we can remove the contact (no sync required)
  2633. globalAddressbookList.removeContact(inputContactObj.uid,true,true);
  2634. if(typeof inputContactObj.finalContactUID=='undefined')
  2635. {
  2636. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  2637. resource.addClass('r_success');
  2638. resource.removeClass('r_operate');
  2639. setTimeout(function(){
  2640. resource.removeClass('r_success');
  2641. resource.droppable('option', 'disabled', false);
  2642. },1200);
  2643. }
  2644. else
  2645. operationPerformed('PUT_ALL', inputContactObj, {newUID:inputContactObj.newUID,uid:inputContactObj.uid, isInterResource:true});
  2646. },1000);
  2647. }
  2648. else
  2649. {
  2650. // success message
  2651. var duration=show_editor_message('out','message_success',localization[globalInterfaceLanguage].succContactDeleted,globalHideInfoMessageAfter);
  2652. var prevConSearchHide = false;
  2653. if(typeof globalAddressbookList.contacts_hash[inputContactObj.uid]!='undefined'&&(globalAddressbookList.contacts_hash[inputContactObj.uid].search_hide||!globalAddressbookList.contacts_hash[inputContactObj.uid].show))
  2654. prevConSearchHide = true;
  2655. globalAddressbookList.removeContact(inputContactObj.uid,true);
  2656. // XXX check this
  2657. // globalAddressbookList.applyABFilter(inputFilterUID, globalRefABListTable.find('[data-id="'+jqueryEscapeSelector(inputContactObj.uid)+'"]').hasClass('search_hide') ? true : false);
  2658. globalAddressbookList.applyABFilter(dataGetChecked('#ResourceCardDAVList'), prevConSearchHide ? true : false);
  2659. var animation=400;
  2660. // after the success message show the next automatically selected contact
  2661. setTimeout(function(){
  2662. // presunut do jednej funkcie s tym co je vyssie
  2663. $('#ResourceCardDAVListOverlay').fadeOut(animation);
  2664. $('#ABListOverlay').fadeOut(animation);
  2665. $('#ABContactOverlay').fadeOut(animation,function(){globalRefAddContact.prop('disabled',false);});
  2666. },duration-animation);
  2667. }
  2668. unlockCollection(inputContactObj);
  2669. // if the destination addressbook is already loaded re-sync it (to get the moved contact immediately)
  2670. if(recursiveMode=='IRM_DELETE_LAST')
  2671. {
  2672. var collection=globalResourceCardDAVList.getCollectionByUID(inputContactObj.newUid);
  2673. CardDAVnetLoadCollection(collection, false, false, null, 0, null, false);
  2674. }
  2675. }
  2676. });
  2677. }
  2678. /*
  2679. iCloud auth (without this we have no access to iCloud photos)
  2680. function netiCloudAuth(inputResource)
  2681. {
  2682. var re=new RegExp('^(https?://)([^/]+)','i');
  2683. var tmp=inputResource.href.match(re);
  2684. var uidBase=tmp[1]+inputResource.userAuth.userName+'@'+tmp[2];
  2685. $.ajax({
  2686. type: 'POST',
  2687. url: 'https://setup.icloud.com/setup/ws/1/login',
  2688. cache: false,
  2689. crossDomain: (typeof inputResource.crossDomain=='undefined' ? true : inputResource.crossDomain),
  2690. xhrFields: {
  2691. withCredentials: (typeof inputResource.withCredentials=='undefined' ? false : inputResource.withCredentials)
  2692. },
  2693. timeout: inputResource.timeOut,
  2694. error: function(objAJAXRequest, strError){
  2695. console.log("Error: [netiCloudAuth: '"+uidBase+"'] code: '"+objAJAXRequest.status+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2696. return false;
  2697. },
  2698. beforeSend: function(req) {
  2699. req.setRequestHeader('Origin', 'https://www.icloud.com');
  2700. },
  2701. contentType: 'text/plain',
  2702. processData: false,
  2703. data: '{"apple_id":"'+inputResource.userAuth.userName+'","password":"'+inputResource.userAuth.userPassword+'","extended_login":false}',
  2704. complete: function(xml, textStatus)
  2705. {
  2706. // iCloud cookie not set (no photo access)
  2707. if(textStatus!='success')
  2708. return false;
  2709. }
  2710. });
  2711. }
  2712. */
  2713. /*
  2714. Permissions (from the DAViCal wiki):
  2715. all - aggregate of all permissions
  2716. read - grants basic read access to the principal or collection.
  2717. unlock - grants access to write content (i.e. update data) to the collection, or collections of the principal.
  2718. read-acl - grants access to read ACLs on the collection, or collections of the principal.
  2719. read-current-user-privilege-set - grants access to read the current user's privileges on the collection, or collections of the write-acl - grants access to writing ACLs on the collection, or collections of the principal.
  2720. write - aggregate of write-properties, write-content, bind & unbind
  2721. write-properties - Grants access to update properties of the principal or collection. In DAViCal, when granted to a user principal, this will only grant access to update properties of the principal's collections and not the user principal itself. When granted to a group or resource principal this will grant access to update the principal properties.
  2722. write-content - grants access to write content (i.e. update data) to the collection, or collections of the principal.
  2723. bind - grants access to creating resources in the collection, or in collections of the principal. Created resources may be new collections, although it is an error to create collections within calendar collections.
  2724. unbind - grants access to deleting resources (including collections) from the collection, or from collections of the principal.
  2725. */
  2726. function CardDAVnetLoadCollection(inputCollection, forceLoad, forceLoadNextContact, innerOperationData, recursiveIterator, collections, recursiveMode)
  2727. {
  2728. if(recursiveMode)
  2729. {
  2730. if(recursiveIterator>=collections.length)
  2731. {
  2732. if(!globalCardDAVInitLoad && isCardDAVLoaded)
  2733. loadNextApplication(false);
  2734. return false;
  2735. }
  2736. if((collections.length>0 && inputCollection.uid==undefined) || (!inputCollection.newlyAdded && !inputCollection.someChanged && !globalCardDAVInitLoad))
  2737. {
  2738. recursiveIterator++;
  2739. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoad, forceLoadNextContact, innerOperationData, recursiveIterator, collections, recursiveMode);
  2740. if(globalCardDAVInitLoad)
  2741. $('#ResourceCardDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2742. return false;
  2743. }
  2744. }
  2745. if(inputCollection.forceSyncPROPFIND!=undefined && inputCollection.forceSyncPROPFIND==true)
  2746. var requestText='<?xml version="1.0" encoding="utf-8"?><D:propfind xmlns:D="DAV:"><D:prop><D:getcontenttype/><D:getetag/></D:prop></D:propfind>';
  2747. else // if inputCollection.forceSyncPROPFIND is undefined or false
  2748. var requestText='<?xml version="1.0" encoding="utf-8"?><D:sync-collection xmlns:D="DAV:"><D:prop><D:getcontenttype/><D:getetag/></D:prop><D:sync-level>1</D:sync-level>'+(forceLoad==true || inputCollection.syncToken==undefined || inputCollection.syncToken=='' || inputCollection.newlyAdded ? '<D:sync-token/>' : '<D:sync-token>'+inputCollection.syncToken+'</D:sync-token>')+'</D:sync-collection>';
  2749. if(!inputCollection.makeLoaded)
  2750. {
  2751. if(globalSettingsSaving!='addressbook')
  2752. CardDAVUpdateMainLoader(inputCollection);
  2753. recursiveIterator++;
  2754. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoad, forceLoadNextContact, innerOperationData, recursiveIterator, collections, recursiveMode);
  2755. return false;
  2756. }
  2757. function ajaxComplete(data, textStatus, xml)
  2758. {
  2759. $('[data-id="'+inputCollection.uid+'"]').removeClass('er_error');
  2760. if($('#ResourceCardDAVList').find('.er_error').length==0 && isEachResourceLoaded())
  2761. $('#intCarddav').find('.int_error').css('display','none');
  2762. var vcardList=new Array();
  2763. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode(new RegExp('^(sync-)?response$')).each(
  2764. function(index, element)
  2765. {
  2766. var hrefVal=$(element).children().filterNsNode('href').text();
  2767. var etagVal=$(element).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('getetag').text();
  2768. var allowContent=false;
  2769. // checkContentType is undocumented but useful if somebody needs to disable it (wrong server response, etc.)
  2770. if(inputCollection.checkContentType!=false)
  2771. {
  2772. var contenttypeVal=$(element).children().filterNsNode('propstat').children().filterNsNode('prop').children().filterNsNode('getcontenttype').text();
  2773. if(contenttypeVal!=undefined)
  2774. {
  2775. contenttypeValArr=contenttypeVal.toLowerCase().replace(RegExp(' ','g'),'').split(';');
  2776. if(contenttypeValArr.indexOf('text/vcard')!=-1 || contenttypeValArr.indexOf('text/x-vcard')!=-1)
  2777. allowContent=true;
  2778. }
  2779. }
  2780. else
  2781. allowContent=true;
  2782. var result=$(element).find('*').filterNsNode('status').text(); // note for 404 there is no propstat!
  2783. var match=false;
  2784. if(hrefVal[hrefVal.length-1]!='/') /* Google CardDAV problem with resource URL if content type checking is disabled */
  2785. {
  2786. if(allowContent==true)
  2787. {
  2788. if(result.match(RegExp('200 OK$'))) // HTTP OK
  2789. {
  2790. vcardList[vcardList.length]={etag: etagVal, href: hrefVal};
  2791. match=true;
  2792. }
  2793. }
  2794. if(!match && result.match(RegExp('404 Not Found$'))) // HTTP Not Found
  2795. vcardList[vcardList.length]={deleted: true, etag: etagVal, href: hrefVal};
  2796. }
  2797. }
  2798. );
  2799. // store the syncToken
  2800. if(inputCollection.forceSyncPROPFIND==undefined || inputCollection.forceSyncPROPFIND==false)
  2801. inputCollection.syncToken=$(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('sync-token').text();
  2802. // we must call the netLoadAddressbook even if we get empty vcardList
  2803. netLoadAddressbook(inputCollection, vcardList, (inputCollection.forceSyncPROPFIND==undefined || inputCollection.forceSyncPROPFIND==false ? true : false), forceLoadNextContact, innerOperationData, forceLoad, recursiveIterator, collections, recursiveMode);
  2804. if(typeof globalParallelAjaxCallCardDAVEnabled!='undefined' && globalParallelAjaxCallCardDAVEnabled!=null && globalParallelAjaxCallCardDAVEnabled && recursiveMode && collections.length>0)
  2805. {
  2806. recursiveIterator++;
  2807. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoad, forceLoadNextContact, innerOperationData, recursiveIterator, collections, true);
  2808. }
  2809. }
  2810. // first try to process the cached data (if cached results are available in the "auth module" response)
  2811. var tmpCache;
  2812. if(globalXMLCache!=null && (tmpCache=globalXMLCache.children('carddavsynccollection[request_url="'+jqueryEscapeSelector(inputCollection.url+inputCollection.href)+'"]').remove()).length)
  2813. {
  2814. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  2815. console.log('DBG Cache OK: '+arguments.callee.name+' url: \''+inputCollection.url+inputCollection.href+'\': saved one request!');
  2816. ajaxComplete('', 'success', {responseXML: tmpCache});
  2817. }
  2818. else
  2819. {
  2820. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  2821. console.log('DBG Cache ERROR: '+arguments.callee.name+' url: \''+inputCollection.url+inputCollection.href+'\': spend one request!');
  2822. $.ajax({
  2823. type: (inputCollection.forceSyncPROPFIND!=undefined && inputCollection.forceSyncPROPFIND==true ? 'PROPFIND' : 'REPORT'),
  2824. url: inputCollection.url+inputCollection.href,
  2825. cache: false,
  2826. crossDomain: (typeof inputCollection.crossDomain=='undefined' ? true : inputCollection.crossDomain),
  2827. xhrFields: {
  2828. withCredentials: (typeof inputCollection.withCredentials=='undefined' ? false : inputCollection.withCredentials)
  2829. },
  2830. timeout: inputCollection.timeOut,
  2831. beforeSend: function(req) {
  2832. if(globalSettings.usejqueryauth.value!=true && inputCollection.userAuth.userName!='' && inputCollection.userAuth.userPassword!='')
  2833. req.setRequestHeader('Authorization', basicAuth(inputCollection.userAuth.userName,inputCollection.userAuth.userPassword));
  2834. req.setRequestHeader('X-client', globalXClientHeader);
  2835. req.setRequestHeader('Depth', '1');
  2836. /* XXX - System display:none changes */
  2837. if(isAvaible('Settings') && $('#SystemSettings').css('visibility')=='visible' && $('.resourceSettings_item_selected').attr('data-type')=='setting_group_password')
  2838. {
  2839. if(recursiveMode && collections.length>0)
  2840. {
  2841. recursiveIterator++;
  2842. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoad, forceLoadNextContact, innerOperationData, recursiveIterator, collections, recursiveMode);
  2843. }
  2844. return false;
  2845. }
  2846. },
  2847. username: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userName : null),
  2848. password: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userPassword : null),
  2849. contentType: 'text/xml; charset=utf-8',
  2850. processData: true,
  2851. data: requestText,
  2852. dataType: 'xml',
  2853. error: function(objAJAXRequest, strError){
  2854. // POROVNAT S TYM AKO JE TO V CALDAVZAP
  2855. $('#intCarddav').find('.int_error').css('display','block');
  2856. if((objAJAXRequest.status==400 /* bad request */ || objAJAXRequest.status==403 /* forbidden (for stupid servers) */ || objAJAXRequest.status==501 /* unimplemented */) && inputCollection.forceSyncPROPFIND!=true /* prevent recursion */)
  2857. {
  2858. collections[recursiveIterator].forceSyncPROPFIND=true;
  2859. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoad, forceLoadNextContact, innerOperationData, recursiveIterator, collections, recursiveMode);
  2860. return true;
  2861. }
  2862. else
  2863. {
  2864. globalAddressbookNumberCount--;
  2865. if(globalCardDAVInitLoad || globalSettingsSaving!='')
  2866. CardDAVUpdateMainLoader(inputCollection);
  2867. if(recursiveMode && collections.length>0)
  2868. {
  2869. recursiveIterator++;
  2870. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoad, forceLoadNextContact, innerOperationData, recursiveIterator, collections, recursiveMode);
  2871. }
  2872. $('#ResourceCardDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2873. $('[data-id="'+inputCollection.uid+'"]').addClass('er_error');
  2874. inputCollection.syncToken = inputCollection.oldSyncToken;
  2875. console.log("Error: [CardDAVnetLoadCollection: '"+(inputCollection.forceSyncPROPFIND!=undefined && inputCollection.forceSyncPROPFIND==true ? 'PROPFIND' : 'REPORT')+" "+inputCollection.url+inputCollection.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  2876. return false;
  2877. }
  2878. },
  2879. success: ajaxComplete
  2880. });
  2881. }
  2882. }
  2883. function netLoadAddressbook(inputCollection, vcardList, syncReportSupport, forceLoadNext, innerOperationData, forceLoadCollection, recursiveIterator, collections, recursiveMode)
  2884. {
  2885. var vcardChangedList=new Array();
  2886. var resultTimestamp=new Date().getTime();
  2887. if(syncReportSupport==true)
  2888. {
  2889. for(var i=0;i<vcardList.length;i++)
  2890. if(vcardList[i].deleted!=undefined && vcardList[i].deleted==true)
  2891. globalAddressbookList.removeContact(inputCollection.uid+vcardList[i].href.replace(RegExp('.*/',''),''),true);
  2892. else
  2893. vcardChangedList[vcardChangedList.length]=vcardList[i].href;
  2894. }
  2895. else // no sync-collection REPORT supported (we need to delete contacts by timestamp comparison)
  2896. {
  2897. for(var i=0;i<vcardList.length;i++)
  2898. {
  2899. var uid=inputCollection.uid+vcardList[i].href.replace(RegExp('.*/',''),'');
  2900. if(!globalAddressbookList.checkAndTouchIfExists(uid,vcardList[i].etag,resultTimestamp))
  2901. vcardChangedList[vcardChangedList.length]=vcardList[i].href;
  2902. }
  2903. globalAddressbookList.removeOldContacts(inputCollection.uid, resultTimestamp);
  2904. }
  2905. // not loaded vCards from the last multiget (if any)
  2906. if(inputCollection.pastUnloaded!=undefined && inputCollection.pastUnloaded.length>0)
  2907. vcardChangedList=vcardChangedList.concat(inputCollection.pastUnloaded).sort().unique();
  2908. // if nothing is changed on the server return
  2909. if(vcardChangedList.length==0)
  2910. {
  2911. inputCollection.newlyAdded = false;
  2912. inputCollection.someChanged = false;
  2913. inputCollection.oldSyncToken = inputCollection.syncToken;
  2914. if(forceLoadCollection)
  2915. $('#ResourceCardDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2916. if(innerOperationData!=null)
  2917. {
  2918. if(innerOperationData.call=='operationPerform')
  2919. operationPerform(innerOperationData.args.performOperation, innerOperationData.args.contactObj, innerOperationData.args.filterUID);
  2920. else if(innerOperationData.call=='operationPerformed')
  2921. operationPerformed(innerOperationData.args.mode, innerOperationData.args.contactObj, innerOperationData.args.loadContact);
  2922. }
  2923. CardDAVUpdateMainLoader(inputCollection);
  2924. if((typeof globalParallelAjaxCallCardDAVEnabled=='undefined' || globalParallelAjaxCallCardDAVEnabled==null || !globalParallelAjaxCallCardDAVEnabled) && recursiveMode && collections.length>0)
  2925. {
  2926. recursiveIterator++;
  2927. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoadCollection, false, null, recursiveIterator, collections, recursiveMode);
  2928. }
  2929. return true;
  2930. }
  2931. var multigetData='<?xml version="1.0" encoding="utf-8"?><R:addressbook-multiget xmlns:D="DAV:" xmlns:R="urn:ietf:params:xml:ns:carddav"><D:prop><D:getetag/><R:address-data/></D:prop><D:href>'+vcardChangedList.join('</D:href><D:href>')+'</D:href></R:addressbook-multiget>';
  2932. function ajaxComplete(data, textStatus, xml)
  2933. {
  2934. var isXMLEmpty=true;
  2935. inputCollection.newlyAdded = false;
  2936. inputCollection.someChanged = false;
  2937. inputCollection.oldSyncToken = inputCollection.syncToken;
  2938. $('[data-id="'+inputCollection.uid+'"]').removeClass('er_error');
  2939. if($('#ResourceCardDAVList').find('.er_error').length==0 && isEachResourceLoaded())
  2940. $('#intCarddav').find('.int_error').css('display','none');
  2941. inputCollection.pastUnloaded=[]; // all vCards loaded
  2942. $(xml.responseXML).children().filterNsNode('multistatus').children().filterNsNode('response').each(
  2943. function(index, element)
  2944. {
  2945. var tmpRef=$(element).children();
  2946. var tmpPropstatRef=tmpRef.filterNsNode('propstat').children();
  2947. var tmpPropstatPropRef=tmpPropstatRef.filterNsNode('prop').children();
  2948. if(tmpPropstatRef.filterNsNode('status').text().match(RegExp('200 OK$'))) // HTTP OK
  2949. {
  2950. isXMLEmpty=false;
  2951. var etag=tmpPropstatPropRef.filterNsNode('getetag').text();
  2952. var uid=inputCollection.uid+tmpRef.filterNsNode('href').text().replace(RegExp('.*/',''),'');
  2953. var vcard_raw=tmpPropstatPropRef.filterNsNode('address-data').text();
  2954. if(vcard_raw!='')
  2955. {
  2956. var result=basicRFCFixesAndCleanup(vcard_raw);
  2957. var normalized=false;
  2958. if(typeof globalCardDavPreNormalize!='undefined' && globalCardDavPreNormalize==true) /* pre-normalization is disabled by default */
  2959. {
  2960. result.vcard=normalizeVcard(additionalRFCFixes(result.vcard));
  2961. normalized=true;
  2962. }
  2963. }
  2964. else
  2965. return true; // continue for jQuery
  2966. // check the vCard validity here
  2967. // ...
  2968. // ...
  2969. globalAddressbookList.insertContact({timestamp: resultTimestamp, accountUID: inputCollection.accountUID, uid: uid, etag: etag, color: inputCollection.color, vcard: result.vcard, categories: result.categories, normalized: normalized}, (innerOperationData!=null && ((innerOperationData.call=='operationPerformed' && innerOperationData.args.mode=='DELETE_FROM_GROUP_LAST') || innerOperationData.args.forceReload==true)), !isCardDAVLoaded); // if inner operation is DELETE_FROM_GROUP_LAST we force reload the contact
  2970. }
  2971. }
  2972. );
  2973. CardDAVUpdateMainLoader(inputCollection);
  2974. // update the active search
  2975. if(globalQs!=null)
  2976. globalQs.cache();
  2977. if(typeof globalContactExtSyncEnd=='function')
  2978. globalContactExtSyncEnd();
  2979. // if no "concurrent" write in progress we need to update the group filter
  2980. if(globalRefAddContact.attr('data-url')==inputCollection.uid && inputCollection.filterUID!=undefined)
  2981. // XXX check this
  2982. // globalAddressbookList.applyABFilter(inputCollection.filterUID, forceLoadNext);
  2983. globalAddressbookList.applyABFilter(dataGetChecked('#ResourceCardDAVList'), forceLoadNext);
  2984. if(innerOperationData!=null)
  2985. {
  2986. if(innerOperationData.call=='operationPerform')
  2987. operationPerform(innerOperationData.args.performOperation, innerOperationData.args.contactObj, innerOperationData.args.filterUID);
  2988. else if(innerOperationData.call=='operationPerformed')
  2989. operationPerformed(innerOperationData.args.mode, innerOperationData.args.contactObj, innerOperationData.args.loadContact);
  2990. }
  2991. if(isXMLEmpty)
  2992. $('#ResourceCardDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  2993. if((typeof globalParallelAjaxCallCardDAVEnabled=='undefined' || globalParallelAjaxCallCardDAVEnabled==null || !globalParallelAjaxCallCardDAVEnabled) && recursiveMode && collections.length>0)
  2994. {
  2995. recursiveIterator++;
  2996. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoadCollection, false, null, recursiveIterator, collections, recursiveMode);
  2997. }
  2998. return true;
  2999. }
  3000. // first try to process the cached data (if cached results are available in the "auth module" response)
  3001. var tmpCache;
  3002. if(globalXMLCache!=null && (tmpCache=globalXMLCache.children('carddavaddressbookmultiget[request_url="'+jqueryEscapeSelector(inputCollection.url+inputCollection.href)+'"]').remove()).length)
  3003. {
  3004. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  3005. console.log('DBG Cache OK: '+arguments.callee.name+' url: \''+inputCollection.url+inputCollection.href+'\': saved one request!');
  3006. ajaxComplete('', 'success', {responseXML: tmpCache});
  3007. }
  3008. else
  3009. {
  3010. if(typeof globalDebug!='undefined' && globalDebug instanceof Array && globalDebug.indexOf('cache')!=-1)
  3011. console.log('DBG Cache ERROR: '+arguments.callee.name+' url: \''+inputCollection.url+inputCollection.href+'\': spend one request!');
  3012. $.ajax({
  3013. type: 'REPORT',
  3014. url: inputCollection.url+inputCollection.href,
  3015. cache: false,
  3016. crossDomain: (typeof inputCollection.crossDomain=='undefined' ? true : inputCollection.crossDomain),
  3017. xhrFields: {
  3018. withCredentials: (typeof inputCollection.withCredentials=='undefined' ? false : inputCollection.withCredentials)
  3019. },
  3020. timeout: inputCollection.timeOut,
  3021. beforeSend: function(req) {
  3022. if(globalSettings.usejqueryauth.value!=true && inputCollection.userAuth.userName!='' && inputCollection.userAuth.userPassword!='')
  3023. req.setRequestHeader('Authorization', basicAuth(inputCollection.userAuth.userName,inputCollection.userAuth.userPassword));
  3024. req.setRequestHeader('X-client', globalXClientHeader);
  3025. req.setRequestHeader('Depth', '0');
  3026. },
  3027. username: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userName : null),
  3028. password: (globalSettings.usejqueryauth.value==true ? inputCollection.userAuth.userPassword : null),
  3029. contentType: 'text/xml; charset=utf-8',
  3030. processData: true,
  3031. data: multigetData,
  3032. dataType: 'xml',
  3033. error: function(objAJAXRequest, strError){
  3034. // unable to load vCards, try to load them next time
  3035. inputCollection.pastUnloaded=vcardChangedList;
  3036. $('[data-id="'+inputCollection.uid+'"]').addClass('er_error');
  3037. $('#intCarddav').find('.int_error').css('display','block');
  3038. inputCollection.syncToken = inputCollection.oldSyncToken;
  3039. console.log("Error: [netLoadAddressbook: 'REPORT "+inputCollection.url+inputCollection.href+"'] code: '"+objAJAXRequest.status+"' status: '"+strError+"'"+(objAJAXRequest.status==0 ? ' - see https://www.inf-it.com/'+globalAppName.toLowerCase()+'/readme.txt (cross-domain setup)' : ''));
  3040. $('#ResourceCardDAVList [data-id="'+inputCollection.uid+'"]').removeClass('r_operate');
  3041. if(innerOperationData!=null && innerOperationData.call=='operationPerform')
  3042. {
  3043. show_editor_message('out','message_error',localization[globalInterfaceLanguage].errUnableSync,globalHideInfoMessageAfter);
  3044. // error icon
  3045. setTimeout(function(){
  3046. var resource=$('#ResourceCardDAVList').find('div[data-id="'+jqueryEscapeSelector(inputContactObj.uiObjects.resource)+'"]');
  3047. resource.addClass('r_error');
  3048. resource.removeClass('r_operate');
  3049. setTimeout(function(){
  3050. inputContactObj.uiObjects.contact.animate({opacity: 1}, 1000);
  3051. inputContactObj.uiObjects.contact.draggable('option', 'disabled', false);
  3052. resource.removeClass('r_error');
  3053. resource.droppable('option', 'disabled', false);
  3054. },globalHideInfoMessageAfter);
  3055. },globalHideInfoMessageAfter/10);
  3056. $('#ABContactOverlay').fadeOut(globalEditorFadeAnimation,function(){globalRefAddContact.prop('disabled',false);});
  3057. }
  3058. if(globalCardDAVInitLoad || globalSettingsSaving!='')
  3059. CardDAVUpdateMainLoader(inputCollection);
  3060. if((typeof globalParallelAjaxCallCardDAVEnabled=='undefined' || globalParallelAjaxCallCardDAVEnabled==null || !globalParallelAjaxCallCardDAVEnabled) && recursiveMode && collections.length>0)
  3061. {
  3062. recursiveIterator++;
  3063. CardDAVnetLoadCollection(collections[recursiveIterator], forceLoadCollection, false, null, recursiveIterator, collections, recursiveMode);
  3064. }
  3065. return false;
  3066. },
  3067. success: ajaxComplete
  3068. });
  3069. }
  3070. }