main.js 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  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. var globalAddressbookList=new AddressbookList();
  19. var globalResourceCardDAVList=new ResourceCardDAVList();
  20. var globalQs=null;
  21. var globalRefABList=null;
  22. var globalRefABListTable=null;
  23. var globalRefAbListTableHeader=null;
  24. var globalRefABListTableCols=null;
  25. var globalRefABListInnerTableCols=null;
  26. var globalRefAddContact=null;
  27. var globalRefVcardEditor=null; // editor reference stored after each editor cleanup
  28. var globalOrigCardDAVListTemplate=null; // template for clean resource list
  29. var globalOrigABListHeader=null; // template for clean addressbook header
  30. var globalOrigABListItem=null; // template for clean addressbook item
  31. var globalOrigVcardTemplate=null; // template for clean editor object
  32. var globalTranslCardDAVListTemplate=null; // template for translated resource list
  33. var globalTranslCardDAVListHeader=null; // template for translated resource header
  34. var globalTranslCardDAVListItem=null; // template for translated resource item
  35. var globalTranslVcardTemplate=null; // template for translated editor object
  36. var globalCardDAVInitLoad=true;
  37. var globalCardDAVResourceSync=false;
  38. var globalCardDAVCollectionSync=false;
  39. var isCardDAVLoaded=false;
  40. var isCardDAVAvaible=true;
  41. var globalDefaultAddressbookCollectionActiveAll=false;
  42. var globalDefaultAddrCollectionLoadAll=false;
  43. var globalAddressbookNumber=0;
  44. var globalAddressbookNumberCount=0;
  45. var globalABEditorCounter=new Object();
  46. var globalAddressElementOldData=new Object();
  47. var globalAddressbookCollectionsLoading=false;
  48. var globalDisableAnimationMessageHiding='';
  49. if(typeof globalContactPhotoScaleFactor==='undefined')
  50. var globalContactPhotoScaleFactor=1.5;
  51. var globalFixedContactDataColumnsCount = 1;
  52. var globalContactDataColumnDefs = {
  53. 'CATEGORIES': {
  54. 'property': 'cats',
  55. 'minWidth': 90
  56. },
  57. 'COMPANY': {
  58. 'property': 'company',
  59. 'minWidth': 135
  60. },
  61. 'DEPARTMENT': {
  62. 'property': 'department',
  63. 'minWidth': 90
  64. },
  65. 'LASTNAME': {
  66. 'property': 'lastname',
  67. 'minWidth': 90
  68. },
  69. 'FIRSTNAME': {
  70. 'property': 'firstname',
  71. 'minWidth': 45
  72. },
  73. 'MIDDLENAME': {
  74. 'property': 'middlename',
  75. 'minWidth': 45
  76. },
  77. 'PREFIX': {
  78. 'property': 'prefix',
  79. 'minWidth': 27
  80. },
  81. 'SUFFIX': {
  82. 'property': 'sufix',
  83. 'minWidth': 27
  84. },
  85. 'NICKNAME': {
  86. 'property': 'nickname',
  87. 'minWidth': 45
  88. },
  89. 'PHONETICLASTNAME': {
  90. 'property': 'phoneticLastName',
  91. 'minWidth': 90
  92. },
  93. 'PHONETICFIRSTNAME': {
  94. 'property': 'phoneticFirstName',
  95. 'minWidth': 45
  96. },
  97. 'BIRTHDAY': {
  98. 'property': 'birthday',
  99. 'minWidth': 90
  100. },
  101. 'JOBTITLE': {
  102. 'property': 'title',
  103. 'minWidth': 90
  104. },
  105. 'NOTETEXT': {
  106. 'property': 'note',
  107. 'minWidth': 180
  108. },
  109. 'ADDRESS': {
  110. 'property': 'address',
  111. 'filterProperities': {
  112. 'TYPE': 'type'
  113. },
  114. 'minWidth': 180
  115. },
  116. 'PHONE': {
  117. 'property': 'phone',
  118. 'filterProperities': {
  119. 'TYPE': 'type'
  120. },
  121. 'minWidth': 90
  122. },
  123. 'EMAIL': {
  124. 'property': 'email',
  125. 'filterProperities': {
  126. 'TYPE': 'type'
  127. },
  128. 'minWidth': 135
  129. },
  130. 'URL': {
  131. 'property': 'url',
  132. 'filterProperities': {
  133. 'TYPE': 'type'
  134. },
  135. 'minWidth': 135
  136. },
  137. 'DATES': {
  138. 'property': 'date',
  139. 'filterProperities': {
  140. 'TYPE': 'type'
  141. },
  142. 'minWidth': 90
  143. },
  144. 'RELATED': {
  145. 'property': 'related',
  146. 'filterProperities': {
  147. 'TYPE': 'type'
  148. },
  149. 'minWidth': 45
  150. },
  151. 'PROFILE': {
  152. 'property': 'social',
  153. 'filterProperities': {
  154. 'TYPE': 'type'
  155. },
  156. 'minWidth': 90
  157. },
  158. 'IM': {
  159. 'property': 'impp',
  160. 'filterProperities': {
  161. 'TYPE': 'type',
  162. 'SERVICE-TYPE': 'serviceType'
  163. },
  164. 'minWidth': 90
  165. }
  166. };
  167. globalContactDataColumnLabelVars = {
  168. 'Name': 'txtName',
  169. 'FirstName': 'pholderGiven',
  170. 'LastName': 'pholderFamily',
  171. 'MiddleName': 'pholderMiddle',
  172. 'NickName': 'pholderNickname',
  173. 'Prefix': 'pholderPrefix',
  174. 'Suffix': 'pholderSuffix',
  175. 'BirthDay': 'pholderBday',
  176. 'PhoneticLastName': 'pholderPhFamily',
  177. 'PhoneticFirstName': 'pholderPhGiven',
  178. 'JobTitle': 'pholderTitle',
  179. 'Company': 'pholderOrg',
  180. 'Department': 'pholderDepartment',
  181. 'Categories': 'txtCategories',
  182. 'NoteText': 'pholderNoteVal',
  183. 'Address': 'txtAddress',
  184. 'AddressWork': 'txtAddressWork',
  185. 'AddressHome': 'txtAddressHome',
  186. 'AddressOther': 'txtAddressOther',
  187. 'Phone': 'txtPhone',
  188. 'PhoneWork': 'txtPhoneWork',
  189. 'PhoneHome': 'txtPhoneHome',
  190. 'PhoneCell': 'txtPhoneCell',
  191. 'PhoneMain': 'txtPhoneMain',
  192. 'PhonePager': 'txtPhonePager',
  193. 'PhoneFax': 'txtPhoneFax',
  194. 'PhoneIphone': 'txtPhoneIphone',
  195. 'PhoneOther': 'txtPhoneOther',
  196. 'Email': 'txtEmail',
  197. 'EmailWork': 'txtEmailWork',
  198. 'EmailHome': 'txtEmailHome',
  199. 'EmailMobileme': 'txtEmailMobileme',
  200. 'EmailOther': 'txtEmailOther',
  201. 'URL': 'txtUrl',
  202. 'URLWork': 'txtUrlWork',
  203. 'URLHome': 'txtUrlHome',
  204. 'URLHomepage': 'txtUrlHomepage',
  205. 'URLOther': 'txtUrlOther',
  206. 'Dates': 'txtDates',
  207. 'DatesAnniversary': 'txtDatesAnniversary',
  208. 'DatesOther': 'txtDatesOther',
  209. 'Related': 'txtRelated',
  210. 'RelatedManager': 'txtRelatedManager',
  211. 'RelatedAssistant': 'txtRelatedAssistant',
  212. 'RelatedFather': 'txtRelatedFather',
  213. 'RelatedMother': 'txtRelatedMother',
  214. 'RelatedParent': 'txtRelatedParent',
  215. 'RelatedBrother': 'txtRelatedBrother',
  216. 'RelatedSister': 'txtRelatedSister',
  217. 'RelatedChild': 'txtRelatedChild',
  218. 'RelatedFriend': 'txtRelatedFriend',
  219. 'RelatedSpouse': 'txtRelatedSpouse',
  220. 'RelatedPartner': 'txtRelatedPartner',
  221. 'RelatedOther': 'txtRelatedOther',
  222. 'Profile': 'txtProfile',
  223. 'ProfileTwitter': 'txtProfileTwitter',
  224. 'ProfileFacebook': 'txtProfileFacebook',
  225. 'ProfileFlickr': 'txtProfileFlickr',
  226. 'ProfileLinkedin': 'txtProfileLinkedin',
  227. 'ProfileMyspace': 'txtProfileMyspace',
  228. 'ProfileSinaweibo': 'txtProfileSinaweibo',
  229. 'IM': 'txtIm',
  230. 'IMWork': 'txtImWork',
  231. 'IMHome': 'txtImHome',
  232. 'IMMobileme': 'txtImMobileme',
  233. 'IMOther': 'txtImOther',
  234. 'IMAim': 'txtImProtAim',
  235. 'IMIcq': 'txtImProtIcq',
  236. 'IMIrc': 'txtImProtIrc',
  237. 'IMJabber': 'txtImProtJabber',
  238. 'IMMsn': 'txtImProtMsn',
  239. 'IMYahoo': 'txtImProtYahoo',
  240. 'IMFacebook': 'txtImProtFacebook',
  241. 'IMGadugadu': 'txtImProtGadugadu',
  242. 'IMGoogletalk': 'txtImProtGoogletalk',
  243. 'IMQq': 'txtImProtQq',
  244. 'IMSkype': 'txtImProtSkype'
  245. };
  246. var globalSettings={
  247. version: {value: (typeof globalSettingsVersion!='undefined' && globalSettingsVersion!=null) ? globalSettingsVersion : 1, locked:false},
  248. resourcealphabetsorting: {value: (typeof globalResourceAlphabetSorting!='undefined' && globalResourceAlphabetSorting!=null) ? globalResourceAlphabetSorting : true, locked:false},
  249. usejqueryauth: {value: (typeof globalUseJqueryAuth!='undefined' && globalUseJqueryAuth!=null) ? globalUseJqueryAuth : false, locked:false},
  250. settingstype: {value: (typeof globalSettingsType!='undefined' && globalSettingsType!=null && globalSettingsType!='') ? globalSettingsType : 'principal-URL', locked:false},
  251. defaultactiveapp: {value: (typeof globalDefaultActiveApp!='undefined' && globalDefaultActiveApp!=null && globalDefaultActiveApp!='') ? globalDefaultActiveApp : null, locked:false},
  252. islastdefaultactiveapp: {value: false, locked:false},
  253. datepickerfirstdayofweek: {value: (typeof globalDatepickerFirstDayOfWeek!='undefined' && globalDatepickerFirstDayOfWeek!=null) ? globalDatepickerFirstDayOfWeek : 1, locked:false},
  254. syncresourcesinterval: {value: (typeof globalSyncResourcesInterval!='undefined' && globalSyncResourcesInterval!=null) ? globalSyncResourcesInterval :300000, locked:false},
  255. datepickerformat: {value: (typeof globalDatepickerFormat!='undefined' && globalDatepickerFormat!=null && globalDatepickerFormat!='') ? globalDatepickerFormat : localization[globalInterfaceLanguage]._default_datepicker_format_, locked:false},
  256. backgroundsync: {value: (typeof globalBackgroundSync!='undefined' && globalBackgroundSync!=null) ? globalBackgroundSync : true, locked:false},
  257. enablekbnavigation: {value: (typeof globalEnableKbNavigation!='undefined' && globalEnableKbNavigation!=null) ? globalEnableKbNavigation : true, locked:false},
  258. rewritetimezonecomponent: {value: (typeof globalRewriteTimezoneComponent!='undefined' && globalRewriteTimezoneComponent!=null) ? globalRewriteTimezoneComponent : true, locked:false},
  259. removeunknowntimezone: {value: (typeof globalRemoveUnknownTimezone!='undefined' && globalRemoveUnknownTimezone!=null) ? globalRemoveUnknownTimezone : false, locked:false},
  260. mozillasupport: {value: (typeof globalMozillaSupport!='undefined' && globalMozillaSupport!=null) ? globalMozillaSupport : false, locked:false},
  261. appleremindersmode: {value: (typeof globalAppleRemindersMode!='undefined' && globalAppleRemindersMode!=null) ? globalAppleRemindersMode : false, locked:false},
  262. titleformatmonth: {value: localization[globalInterfaceLanguage]._default_title_format_month_, locked:false},
  263. titleformatweek: {value: localization[globalInterfaceLanguage]._default_title_format_week_, locked:false},
  264. titleformatday: {value: localization[globalInterfaceLanguage]._default_title_format_day_, locked:false},
  265. titleformattable: {value: localization[globalInterfaceLanguage]._default_title_format_table_, locked:false},
  266. columnformatagenda: {value: localization[globalInterfaceLanguage]._default_column_format_agenda_, locked:false},
  267. activecalendarcollections: {value: (typeof globalActiveCalendarCollections!='undefined' && globalActiveCalendarCollections!=null) ? globalActiveCalendarCollections : new Array(), locked:false},
  268. activetodocollections: {value: (typeof globalActiveTodoCollections!='undefined' && globalActiveTodoCollections!=null) ? globalActiveTodoCollections : new Array(), locked:false},
  269. loadedcalendarcollections: {value: (typeof globalLoadedCalendarCollections!='undefined' && globalLoadedCalendarCollections!=null) ? globalLoadedCalendarCollections : new Array(), locked:false},
  270. loadedtodocollections: {value: (typeof globalLoadedTodoCollections!='undefined' && globalLoadedTodoCollections!=null) ? globalLoadedTodoCollections : new Array(), locked:false},
  271. todolistfilterselected: {value: (typeof globalTodoListFilterSelected!='undefined' && globalTodoListFilterSelected!=null && globalTodoListFilterSelected!='') ? globalTodoListFilterSelected : ['filterAction', 'filterProgress'], locked:false},
  272. activeview: {value: (typeof globalActiveView!='undefined' && globalActiveView!=null && globalActiveView!='') ? globalActiveView : 'multiWeek', locked:false},
  273. islastactiveview: {value: true, locked:false},
  274. calendarselected: {value: (typeof globalCalendarSelected!='undefined' && globalCalendarSelected!=null && globalCalendarSelected!='') ? globalCalendarSelected : '', locked:false},
  275. todocalendarselected: {value: (typeof globalTodoCalendarSelected!='undefined' && globalTodoCalendarSelected!=null && globalTodoCalendarSelected!='') ? globalTodoCalendarSelected : '', locked:false},
  276. timezone: {value: (typeof globalTimeZone!='undefined' && globalTimeZone!=null && globalTimeZone!='') ? globalTimeZone : 'local', locked:false},
  277. islasttimezone: {value: true, locked:false},
  278. openformmode: {value: (typeof globalOpenFormMode!='undefined' && globalOpenFormMode!=null && globalOpenFormMode!='') ? globalOpenFormMode : 'double', locked:false},
  279. calendarstartofbusiness: {value: (typeof globalCalendarStartOfBusiness!='undefined' && globalCalendarStartOfBusiness!=null) ? globalCalendarStartOfBusiness : 8, locked:false},
  280. calendarendofbusiness: {value: (typeof globalCalendarEndOfBusiness!='undefined' && globalCalendarEndOfBusiness!=null) ? globalCalendarEndOfBusiness : 17, locked:false},
  281. defaulteventduration: {value: (typeof globalDefaultEventDuration!='undefined' && globalDefaultEventDuration!=null && globalDefaultEventDuration>=0) ? globalDefaultEventDuration : null, locked:false},
  282. ampmformat: {value: (typeof globalAMPMFormat!='undefined' && globalAMPMFormat!=null) ? globalAMPMFormat : localization[globalInterfaceLanguage]._default_AMPM_format_, locked:false},
  283. timeformatagenda: {value: (typeof globalTimeFormatAgenda!='undefined' && globalTimeFormatAgenda!=null && globalTimeFormatAgenda!='') ? globalTimeFormatAgenda : null, locked:false},
  284. timeformatbasic: {value: (typeof globalTimeFormatBasic!='undefined' && globalTimeFormatBasic!=null && globalTimeFormatBasic!='') ? globalTimeFormatBasic : null, locked:false},
  285. displayhiddenevents: {value: (typeof globalDisplayHiddenEvents!='undefined' && globalDisplayHiddenEvents!=null) ? globalDisplayHiddenEvents : false, locked:false},
  286. timezonesupport: {value: (typeof globalTimeZoneSupport!='undefined' && globalTimeZoneSupport!=null) ? globalTimeZoneSupport : true, locked:false},
  287. timezonesenabled: {value: (typeof globalTimeZonesEnabled!='undefined' && globalTimeZonesEnabled!=null && globalTimeZonesEnabled!='') ? globalTimeZonesEnabled : [], locked:false},
  288. showhiddenalarms: {value: (typeof globalShowHiddenAlarms!='undefined' && globalShowHiddenAlarms!=null) ? globalShowHiddenAlarms : false, locked:false},
  289. ignorecompletedorcancelledalarms: {value: (typeof globalIgnoreCompletedOrCancelledAlarms!='undefined' && globalIgnoreCompletedOrCancelledAlarms!=null) ? globalIgnoreCompletedOrCancelledAlarms : true, locked:false},
  290. weekenddays: {value: (typeof globalWeekendDays!='undefined' && globalWeekendDays!=null && globalWeekendDays!='') ? globalWeekendDays : [0, 6], locked:false},
  291. eventstartpastlimit: {value: (typeof globalEventStartPastLimit!='undefined' && globalEventStartPastLimit!=null) ? globalEventStartPastLimit : 3, locked:false},
  292. todopastlimit: {value: (typeof globalTodoPastLimit!='undefined' && globalTodoPastLimit!=null) ? globalTodoPastLimit : 3, locked:false},
  293. eventstartfuturelimit: {value: (typeof globalEventStartFutureLimit!='undefined' && globalEventStartFutureLimit!=null) ? globalEventStartFutureLimit : 3, locked:false},
  294. compatibility: {value: (typeof globalCompatibility!='undefined' && globalCompatibility!=null && globalCompatibility!='') ? globalCompatibility : {anniversaryOutputFormat: ['apple']}, locked:false},
  295. contactstorefn: {value: (typeof globalContactStoreFN!='undefined' && globalContactStoreFN!=null && globalContactStoreFN!='') ? globalContactStoreFN : ['prefix',' last',' middle',' first',' suffix'], locked:false},
  296. urihandlertel: {value: (typeof globalUriHandlerTel!='undefined' && globalUriHandlerTel!=null && globalUriHandlerTel!='') ? globalUriHandlerTel : 'tel:', locked:false},
  297. urihandleremail: {value: (typeof globalUriHandlerEmail!='undefined' && globalUriHandlerEmail!=null && globalUriHandlerEmail!='') ? globalUriHandlerEmail : 'mailto:', locked:false},
  298. urihandlerurl: {value: (typeof globalUriHandlerUrl!='undefined' && globalUriHandlerUrl!=null && globalUriHandlerUrl!='') ? globalUriHandlerUrl : 'http://', locked:false},
  299. urihandlerprofile: {value: (typeof globalUriHandlerProfile!='undefined' && globalUriHandlerProfile!=null && globalUriHandlerProfile!='') ? globalUriHandlerProfile : {'twitter': 'http://twitter.com/%u', 'facebook': 'http://www.facebook.com/%u', 'flickr': 'http://www.flickr.com/photos/%u', 'linkedin': 'http://www.linkedin.com/in/%u', 'myspace': 'http://www.myspace.com/%u', 'sinaweibo': 'http://weibo.com/n/%u'}, locked:false},
  300. addresscountryequivalence: {value: (typeof globalAddressCountryEquivalence!='undefined' && globalAddressCountryEquivalence!=null && globalAddressCountryEquivalence!='') ? globalAddressCountryEquivalence : [{country: 'de', regex: '^\\W*Deutschland\\W*$'}, {country: 'sk', regex: '^\\W*Slovensko\\W*$'}], locked:false},
  301. addressbookselected: {value: (typeof globalAddressbookSelected!='undefined' && globalAddressbookSelected!=null && globalAddressbookSelected!='') ? globalAddressbookSelected : '', locked:false},
  302. collectiondisplay: {value: (typeof globalCollectionDisplay!='undefined' && globalCollectionDisplay!=null && globalCollectionDisplay!='') ? globalCollectionDisplay : (
  303. (typeof globalGroupContactsByCompanies!='undefined' && globalGroupContactsByCompanies) ?
  304. [{label: '{Name}', value: {company: ['{Company}', ' [{Department}]'], personal: ['{LastName}', ' {MiddleName}', ' {FirstName}']}}, {label: '{JobTitle}', value: ['{JobTitle}']}, {label: '{Email}', value: ['{Email[:0]}']}, {label: '{Phone} 1', value: ['{Phone[:0]}']}, {label: '{Phone} 2', value: ['{Phone[:1]}']}, {label: '{NoteText}', value: ['{NoteText}']}] :
  305. [{label: '{Name}', value: ['{LastName}', ' {MiddleName}', ' {FirstName}']}, {label: '{Company} [{Department}]', value: ['{Company}', ' [{Department}]']}, {label: '{JobTitle}', value: ['{JobTitle}']}, {label: '{Email}', value: ['{Email[:0]}']}, {label: '{Phone} 1', value: ['{Phone[:0]}']}, {label: '{Phone} 2', value: ['{Phone[:1]}']}, {label: '{NoteText}', value: ['{NoteText}']}]
  306. ), locked:false},
  307. collectionsort: {value: (typeof globalCollectionSort!='undefined' && globalCollectionSort!=null && globalCollectionSort!='') ? globalCollectionSort : '', locked:false},
  308. defaultaddresscountry: {value: (typeof globalDefaultAddressCountry!='undefined' && globalDefaultAddressCountry!=null && globalDefaultAddressCountry!='') ? globalDefaultAddressCountry :'us', locked:false},
  309. addresscountryfavorites: {value: (typeof globalAddressCountryFavorites!='undefined' && globalAddressCountryFavorites!=null && globalAddressCountryFavorites!='') ? globalAddressCountryFavorites :[], locked:false},
  310. activeaddressbookcollections: {value: (typeof globalActiveAddressbookCollections!='undefined' && globalActiveAddressbookCollections!=null) ? globalActiveAddressbookCollections : new Array(), locked:false},
  311. loadedaddressbookcollections: {value: (typeof globalLoadedAddressbookCollections!='undefined' && globalLoadedAddressbookCollections!=null) ? globalLoadedAddressbookCollections : new Array(), locked:false}
  312. };
  313. function resetSettings()
  314. {
  315. globalSettings={
  316. version: {value: (typeof globalSettingsVersion!='undefined' && globalSettingsVersion!=null) ? globalSettingsVersion : 1, locked:false},
  317. resourcealphabetsorting: {value: (typeof globalResourceAlphabetSorting!='undefined' && globalResourceAlphabetSorting!=null) ? globalResourceAlphabetSorting : true, locked:false},
  318. usejqueryauth: {value: (typeof globalUseJqueryAuth!='undefined' && globalUseJqueryAuth!=null) ? globalUseJqueryAuth : false, locked:false},
  319. settingstype: {value: (typeof globalSettingsType!='undefined' && globalSettingsType!=null && globalSettingsType!='') ? globalSettingsType : 'principal-URL', locked:false},
  320. defaultactiveapp: {value: (typeof globalDefaultActiveApp!='undefined' && globalDefaultActiveApp!=null && globalDefaultActiveApp!='') ? globalDefaultActiveApp : null, locked:false},
  321. islastdefaultactiveapp: {value: false, locked:false},
  322. datepickerfirstdayofweek: {value: (typeof globalDatepickerFirstDayOfWeek!='undefined' && globalDatepickerFirstDayOfWeek!=null) ? globalDatepickerFirstDayOfWeek : 1, locked:false},
  323. syncresourcesinterval: {value: (typeof globalSyncResourcesInterval!='undefined' && globalSyncResourcesInterval!=null) ? globalSyncResourcesInterval :300000, locked:false},
  324. datepickerformat: {value: (typeof globalDatepickerFormat!='undefined' && globalDatepickerFormat!=null && globalDatepickerFormat!='') ? globalDatepickerFormat : localization[globalInterfaceLanguage]._default_datepicker_format_, locked:false},
  325. backgroundsync: {value: (typeof globalBackgroundSync!='undefined' && globalBackgroundSync!=null) ? globalBackgroundSync : true, locked:false},
  326. enablekbnavigation: {value: (typeof globalEnableKbNavigation!='undefined' && globalEnableKbNavigation!=null) ? globalEnableKbNavigation : true, locked:false},
  327. rewritetimezonecomponent: {value: (typeof globalRewriteTimezoneComponent!='undefined' && globalRewriteTimezoneComponent!=null) ? globalRewriteTimezoneComponent : true, locked:false},
  328. removeunknowntimezone: {value: (typeof globalRemoveUnknownTimezone!='undefined' && globalRemoveUnknownTimezone!=null) ? globalRemoveUnknownTimezone : false, locked:false},
  329. mozillasupport: {value: (typeof globalMozillaSupport!='undefined' && globalMozillaSupport!=null) ? globalMozillaSupport : false, locked:false},
  330. appleremindersmode: {value: (typeof globalAppleRemindersMode!='undefined' && globalAppleRemindersMode!=null) ? globalAppleRemindersMode : false, locked:false},
  331. titleformatmonth: {value: localization[globalInterfaceLanguage]._default_title_format_month_, locked:false},
  332. titleformatweek: {value: localization[globalInterfaceLanguage]._default_title_format_week_, locked:false},
  333. titleformatday: {value: localization[globalInterfaceLanguage]._default_title_format_day_, locked:false},
  334. titleformattable: {value: localization[globalInterfaceLanguage]._default_title_format_table_, locked:false},
  335. columnformatagenda: {value: localization[globalInterfaceLanguage]._default_column_format_agenda_, locked:false},
  336. activecalendarcollections: {value: (typeof globalActiveCalendarCollections!='undefined' && globalActiveCalendarCollections!=null) ? globalActiveCalendarCollections : new Array(), locked:false},
  337. activetodocollections: {value: (typeof globalActiveTodoCollections!='undefined' && globalActiveTodoCollections!=null) ? globalActiveTodoCollections : new Array(), locked:false},
  338. loadedcalendarcollections: {value: (typeof globalLoadedCalendarCollections!='undefined' && globalLoadedCalendarCollections!=null) ? globalLoadedCalendarCollections : new Array(), locked:false},
  339. loadedtodocollections: {value: (typeof globalLoadedTodoCollections!='undefined' && globalLoadedTodoCollections!=null) ? globalLoadedTodoCollections : new Array(), locked:false},
  340. todolistfilterselected: {value: (typeof globalTodoListFilterSelected!='undefined' && globalTodoListFilterSelected!=null && globalTodoListFilterSelected!='') ? globalTodoListFilterSelected : ['filterAction', 'filterProgress'], locked:false},
  341. activeview: {value: (typeof globalActiveView!='undefined' && globalActiveView!=null && globalActiveView!='') ? globalActiveView : 'multiWeek', locked:false},
  342. islastactiveview: {value: true, lockedlocked:false},
  343. calendarselected: {value: (typeof globalCalendarSelected!='undefined' && globalCalendarSelected!=null && globalCalendarSelected!='') ? globalCalendarSelected : '', locked:false},
  344. todocalendarselected: {value: (typeof globalTodoCalendarSelected!='undefined' && globalTodoCalendarSelected!=null && globalTodoCalendarSelected!='') ? globalTodoCalendarSelected : '', locked:false},
  345. timezone: {value: (typeof globalTimeZone!='undefined' && globalTimeZone!=null && globalTimeZone!='') ? globalTimeZone : 'local', locked:false},
  346. islasttimezone: {value: true, locked:false},
  347. openformmode: {value: (typeof globalOpenFormMode!='undefined' && globalOpenFormMode!=null && globalOpenFormMode!='') ? globalOpenFormMode : 'double', locked:false},
  348. calendarstartofbusiness: {value: (typeof globalCalendarStartOfBusiness!='undefined' && globalCalendarStartOfBusiness!=null) ? globalCalendarStartOfBusiness : 8, locked:false},
  349. calendarendofbusiness: {value: (typeof globalCalendarEndOfBusiness!='undefined' && globalCalendarEndOfBusiness!=null) ? globalCalendarEndOfBusiness : 17, locked:false},
  350. defaulteventduration: {value: (typeof globalDefaultEventDuration!='undefined' && globalDefaultEventDuration!=null && globalDefaultEventDuration>=0) ? globalDefaultEventDuration : null, locked:false},
  351. ampmformat: {value: (typeof globalAMPMFormat!='undefined' && globalAMPMFormat!=null) ? globalAMPMFormat : localization[globalInterfaceLanguage]._default_AMPM_format_, locked:false},
  352. timeformatagenda: {value: (typeof globalTimeFormatAgenda!='undefined' && globalTimeFormatAgenda!=null && globalTimeFormatAgenda!='') ? globalTimeFormatAgenda : null, locked:false},
  353. timeformatbasic: {value: (typeof globalTimeFormatBasic!='undefined' && globalTimeFormatBasic!=null && globalTimeFormatBasic!='') ? globalTimeFormatBasic : null, locked:false},
  354. displayhiddenevents: {value: (typeof globalDisplayHiddenEvents!='undefined' && globalDisplayHiddenEvents!=null) ? globalDisplayHiddenEvents : false, locked:false},
  355. timezonesupport: {value: (typeof globalTimeZoneSupport!='undefined' && globalTimeZoneSupport!=null) ? globalTimeZoneSupport : true, locked:false},
  356. timezonesenabled: {value: (typeof globalTimeZonesEnabled!='undefined' && globalTimeZonesEnabled!=null && globalTimeZonesEnabled!='') ? globalTimeZonesEnabled : [], locked:false},
  357. showhiddenalarms: {value: (typeof globalShowHiddenAlarms!='undefined' && globalShowHiddenAlarms!=null) ? globalShowHiddenAlarms : false, locked:false},
  358. ignorecompletedorcancelledalarms: {value: (typeof globalIgnoreCompletedOrCancelledAlarms!='undefined' && globalIgnoreCompletedOrCancelledAlarms!=null) ? globalIgnoreCompletedOrCancelledAlarms : true, locked:false},
  359. weekenddays: {value: (typeof globalWeekendDays!='undefined' && globalWeekendDays!=null && globalWeekendDays!='') ? globalWeekendDays : [0, 6], locked:false},
  360. eventstartpastlimit: {value: (typeof globalEventStartPastLimit!='undefined' && globalEventStartPastLimit!=null) ? globalEventStartPastLimit : 3, locked:false},
  361. todopastlimit: {value: (typeof globalTodoPastLimit!='undefined' && globalTodoPastLimit!=null) ? globalTodoPastLimit : 3, locked:false},
  362. eventstartfuturelimit: {value: (typeof globalEventStartFutureLimit!='undefined' && globalEventStartFutureLimit!=null) ? globalEventStartFutureLimit : 3, locked:false},
  363. compatibility: {value: (typeof globalCompatibility!='undefined' && globalCompatibility!=null && globalCompatibility!='') ? globalCompatibility : {anniversaryOutputFormat: ['apple']}, locked:false},
  364. contactstorefn: {value: (typeof globalContactStoreFN!='undefined' && globalContactStoreFN!=null && globalContactStoreFN!='') ? globalContactStoreFN : ['prefix',' last',' middle',' first',' suffix'], locked:false},
  365. urihandlertel: {value: (typeof globalUriHandlerTel!='undefined' && globalUriHandlerTel!=null && globalUriHandlerTel!='') ? globalUriHandlerTel : 'tel:', locked:false},
  366. urihandleremail: {value: (typeof globalUriHandlerEmail!='undefined' && globalUriHandlerEmail!=null && globalUriHandlerEmail!='') ? globalUriHandlerEmail : 'mailto:', locked:false},
  367. urihandlerurl: {value: (typeof globalUriHandlerUrl!='undefined' && globalUriHandlerUrl!=null && globalUriHandlerUrl!='') ? globalUriHandlerUrl : 'http://', locked:false},
  368. urihandlerprofile: {value: (typeof globalUriHandlerProfile!='undefined' && globalUriHandlerProfile!=null && globalUriHandlerProfile!='') ? globalUriHandlerProfile : {'twitter': 'http://twitter.com/%u', 'facebook': 'http://www.facebook.com/%u', 'flickr': 'http://www.flickr.com/photos/%u', 'linkedin': 'http://www.linkedin.com/in/%u', 'myspace': 'http://www.myspace.com/%u', 'sinaweibo': 'http://weibo.com/n/%u'}, locked:false},
  369. addresscountryequivalence: {value: (typeof globalAddressCountryEquivalence!='undefined' && globalAddressCountryEquivalence!=null && globalAddressCountryEquivalence!='') ? globalAddressCountryEquivalence : [{country: 'de', regex: '^\\W*Deutschland\\W*$'}, {country: 'sk', regex: '^\\W*Slovensko\\W*$'}], locked:false},
  370. addressbookselected: {value: (typeof globalAddressbookSelected!='undefined' && globalAddressbookSelected!=null && globalAddressbookSelected!='') ? globalAddressbookSelected : '', locked:false},
  371. collectiondisplay: {value: (typeof globalCollectionDisplay!='undefined' && globalCollectionDisplay!=null && globalCollectionDisplay!='') ? globalCollectionDisplay : (
  372. (typeof globalGroupContactsByCompanies!='undefined' && globalGroupContactsByCompanies) ?
  373. [{label: '{Name}', value: {company: ['{Company}', ' [{Department}]'], personal: ['{LastName}', ' {MiddleName}', ' {FirstName}']}}, {label: '{JobTitle}', value: ['{JobTitle}']}, {label: '{Email}', value: ['{Email[:0]}']}, {label: '{Phone} 1', value: ['{Phone[:0]}']}, {label: '{Phone} 2', value: ['{Phone[:1]}']}, {label: '{NoteText}', value: ['{NoteText}']}] :
  374. [{label: '{Name}', value: ['{LastName}', ' {MiddleName}', ' {FirstName}']}, {label: '{Company} [{Department}]', value: ['{Company}', ' [{Department}]']}, {label: '{JobTitle}', value: ['{JobTitle}']}, {label: '{Email}', value: ['{Email[:0]}']}, {label: '{Phone} 1', value: ['{Phone[:0]}']}, {label: '{Phone} 2', value: ['{Phone[:1]}']}, {label: '{NoteText}', value: ['{NoteText}']}]
  375. ), locked:false},
  376. collectionsort: {value: (typeof globalCollectionSort!='undefined' && globalCollectionSort!=null && globalCollectionSort!='') ? globalCollectionSort : '', locked:false},
  377. defaultaddresscountry: {value: (typeof globalDefaultAddressCountry!='undefined' && globalDefaultAddressCountry!=null && globalDefaultAddressCountry!='') ? globalDefaultAddressCountry :'us', locked:false},
  378. addresscountryfavorites: {value: (typeof globalAddressCountryFavorites!='undefined' && globalAddressCountryFavorites!=null && globalAddressCountryFavorites!='') ? globalAddressCountryFavorites :[], locked:false},
  379. activeaddressbookcollections: {value: (typeof globalActiveAddressbookCollections!='undefined' && globalActiveAddressbookCollections!=null) ? globalActiveAddressbookCollections : new Array(), locked:false},
  380. loadedaddressbookcollections: {value: (typeof globalLoadedAddressbookCollections!='undefined' && globalLoadedAddressbookCollections!=null) ? globalLoadedAddressbookCollections : new Array(), locked:false}
  381. };
  382. }
  383. function transformToServer(inSettings)
  384. {
  385. var serverSettings={};
  386. for(var prop in inSettings)
  387. {
  388. serverSettings[prop]=inSettings[prop].value;
  389. }
  390. return serverSettings;
  391. }
  392. var globalWindowFocus=true;
  393. var globalLoginUsername='';
  394. var globalLoginPassword='';
  395. var isUserLogged=false;
  396. var isDelegationLoaded=false;
  397. var globalActiveApp='';
  398. var globalAvailableAppsArray=new Array();
  399. var globalEnableAppSwitch=true;
  400. var globalAppName='CardDavMATE';
  401. var globalVersion='0.13.1';
  402. var globalBuildNo=1442928605;
  403. var globalXMLCache=null;
  404. var globalVersionCheckURL=(location.protocol=='file:' ? 'http:' : location.protocol)+'//www.inf-it.com/versioncheck/'+globalAppName+'/?v='+globalVersion;
  405. var globalXClientHeader=globalAppName+' '+globalVersion+' (Inf-IT CardDAV Web Client)';
  406. var globalResourceNumberCount=0;
  407. var globalResourceNumber=0;
  408. var globalResourceIntervalID=null;
  409. var globalFirstLoadNextApp=false;
  410. var globalObjectLoading=false;
  411. var settingsLoaded=false;
  412. var globalKBNavigationPaddingRate=0.2;
  413. var globalParallelAjaxCallCardDAVEnabled=true;
  414. var globalParallelAjaxCallCalDAVEnabled=true;
  415. var globalCacheUpdateInterval=null;
  416. var isIntegrated=false;
  417. var SVG_select='<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0px" y="0px" width="19px" height="19px" viewBox="0 0 19 19" overflow="visible" enable-background="new 0 0 19 19" xml:space="preserve"><defs></defs><rect x="2" fill="#585858" width="17" height="19"/><polygon fill="#FFFFFF" points="14,7 10.5,13 7,7 "/><rect fill="#FFFFFF" width="2" height="19"/></svg>';
  418. var SVG_select_inv='<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0px" y="0px" width="19px" height="19px" viewBox="0 0 19 19" overflow="visible" enable-background="new 0 0 19 19" xml:space="preserve"><defs></defs><rect x="2" fill="#585858" width="17" height="19"/><polygon fill="#FFFFFF" points="14,13 10.5,7 7,13"/><rect fill="#FFFFFF" width="2" height="19"/></svg>';
  419. var SVG_select_login='<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0px" y="0px" width="19px" height="28px" viewBox="0 0 19 28" overflow="visible" enable-background="new 0 0 19 28" xml:space="preserve"><defs></defs><rect fill="#FFFFFF" width="19" height="28"/></svg>';
  420. var SVG_select_dis='<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0px" y="0px" width="22px" height="19px" viewBox="0 0 22 19" overflow="visible" enable-background="new 0 0 22 19" xml:space="preserve"><defs></defs><rect fill="#FFFFFF" width="22" height="19"/></svg>';
  421. var globalDefinedSettings = new Array();
  422. var globalLoadedPrincipals = new Array();
  423. var globalEnableAllResourceSync = true;
  424. if(typeof isSettingsAvaible == 'undefined')
  425. var globalPreviousSupportedSettings = ['activecalendarcollections','activetodocollections', 'activeaddressbookcollections','todolistfilterselected','activeview','defaultactiveapp','calendarselected', 'todocalendarselected','addressbookselected','timezone', 'loadedtodocollections', 'loadedcalendarcollections', 'loadedaddressbookcollections', 'version'];
  426. var globalSettingsSaving = '';
  427. var globalFirstHideLoader = true;
  428. var globalLoadedCollectionsNumber = 0;
  429. var globalLoadedCollectionsCount = 0;
  430. var ignoreServerSettings=false;
  431. var globalPreventLogoutSync=false;
  432. var globalEmailAddress='';
  433. var globalSettingsVersion=3;
  434. var globalSyncSettingsSave=false;
  435. // Timepicker hack (prevent IE to re-open the datepicker on date click + focus)
  436. var globalTmpTimePickerHackTime=new Object();
  437. function isAvaible(app)
  438. {
  439. return globalAvailableAppsArray.indexOf(app)!=-1
  440. }
  441. function loadAllResources()
  442. {
  443. if(globalResourceIntervalID==null)
  444. netFindResource(globalAccountSettings[0], 0, true, 0);
  445. }
  446. function getAccount(accountUID)
  447. {
  448. // find the original settings for the resource and user
  449. var tmp=accountUID.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)','i'));
  450. var resource_href=tmp[1]+tmp[3]+tmp[4];
  451. var resource_user=tmp[2];
  452. for(var i=0;i<globalAccountSettings.length;i++)
  453. if(globalAccountSettings[i].href==resource_href && globalAccountSettings[i].userAuth.userName==resource_user)
  454. resourceSettings=globalAccountSettings[i];
  455. return resourceSettings;
  456. }
  457. function checkForUnloadedResources()
  458. {
  459. var rex=new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@([^/]+)(.*/)', 'i');
  460. for(var i=globalLoadedPrincipals.length-1; i>=0;i--)
  461. {
  462. var resourceCounter = 0;
  463. if(isAvaible('CardDavMATE'))
  464. for(var j=0; j<globalResourceCardDAVList.collections.length;j++)
  465. if(globalResourceCardDAVList.collections[j].uid!=undefined&&globalResourceCardDAVList.collections[j].makeLoaded)
  466. {
  467. var tmp=globalResourceCardDAVList.collections[j].accountUID.match(rex);
  468. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  469. if(globalLoadedPrincipals[i]==resourceCalDAV_href)
  470. resourceCounter++;
  471. }
  472. if(isAvaible('CalDavZAP'))
  473. {
  474. for(var j=0; j<globalResourceCalDAVList.collections.length;j++)
  475. if(globalResourceCalDAVList.collections[j].uid!=undefined&&globalResourceCalDAVList.collections[j].makeLoaded)
  476. {
  477. var tmp=globalResourceCalDAVList.collections[j].accountUID.match(rex);
  478. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  479. if(globalLoadedPrincipals[i]==resourceCalDAV_href)
  480. resourceCounter++;
  481. }
  482. for(var j=0; j<globalResourceCalDAVList.TodoCollections.length;j++)
  483. if(globalResourceCalDAVList.TodoCollections[j].uid!=undefined&&globalResourceCalDAVList.TodoCollections[j].makeLoaded)
  484. {
  485. var tmp=globalResourceCalDAVList.TodoCollections[j].accountUID.match(rex);
  486. var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4];
  487. if(globalLoadedPrincipals[i]==resourceCalDAV_href)
  488. resourceCounter++;
  489. }
  490. }
  491. if(resourceCounter==0)
  492. globalLoadedPrincipals.splice(i,1);
  493. }
  494. }
  495. function reloadResources(dontSaveSettings, loadArray)
  496. {
  497. if((isAvaible('CardDavMATE')&&(globalCardDAVInitLoad||globalCardDAVResourceSync)) || (isAvaible('CalDavZAP')&&(globalCalDAVInitLoad||globalCalDAVResourceSync))
  498. || (isAvaible('Projects')&&!isProjectsLoaded) || (isAvaible('Settings')&&(!isSettingsLoaded || (globalSettingsSaving!=''&&!dontSaveSettings))) || (isAvaible('CalDavZAP')&&(globalLimitLoading!='' || globalLimitTodoLoading!='')))
  499. return false;
  500. if(globalWindowFocus==false)
  501. return false;
  502. globalCardDAVResourceSync=true;
  503. globalCalDAVResourceSync=true;
  504. if(isAvaible('CalDavZAP'))
  505. {
  506. globalCalDAVResourceSync = true;
  507. globalToday.setHours(0);
  508. globalToday.setMinutes(0);
  509. globalToday.setSeconds(0);
  510. globalToday.setMilliseconds(0);
  511. var currentToday=new Date();
  512. currentToday.setHours(0);
  513. currentToday.setMinutes(0);
  514. currentToday.setSeconds(0);
  515. currentToday.setMilliseconds(0);
  516. if(currentToday.getTime()!=globalToday.getTime())
  517. {
  518. if(isAvaible('CalDavZAP'))
  519. $('.date').datepicker('refresh');
  520. if(isAvaible('CardDavMATE'))
  521. $('#vCardEditor').find('input[data-type^="date_"]').datepicker('refresh');
  522. if(isAvaible('Projects'))
  523. $('.project_date').datepicker('refresh');
  524. $('#calendar').fullCalendar('updateToday');
  525. $('#calendar').fullCalendar('gotoDate', currentToday);
  526. $('#todoList').fullCalendar('gotoDate', currentToday);
  527. if(currentToday.getTime()>globalToday.getTime())
  528. {
  529. getNextMonths($('#calendar').fullCalendar('getView').end);
  530. getNextMonthsTodo();
  531. }
  532. else //support for timezone with backward time flow
  533. {
  534. getPrevMonths($('#calendar').fullCalendar('getView').start);
  535. getPrevMonthsTodo();
  536. }
  537. globalToday=currentToday;
  538. }
  539. }
  540. checkForUnloadedResources();
  541. if(!globalEnableAllResourceSync&&(typeof loadArray=='undefined' || loadArray==null))
  542. netFindResource(globalAccountSettings[0], 0, false, 0, globalLoadedPrincipals);
  543. else
  544. netFindResource(globalAccountSettings[0], 0, false, 0, loadArray);
  545. }
  546. function ifLoadCollections()
  547. {
  548. if((isAvaible('CardDavMATE') && (globalCardDAVInitLoad || globalCardDAVResourceSync)) || (isAvaible('CalDavZAP') && (globalCalDAVInitLoad || globalCalDAVResourceSync)))
  549. return false;
  550. var changeCounter = 0;
  551. if(isAvaible('CardDavMATE'))
  552. for(var i=0; i<globalResourceCardDAVList.collections.length;i++)
  553. if(globalResourceCardDAVList.collections[i].uid!=undefined && globalResourceCardDAVList.collections[i].someChanged)
  554. changeCounter++;
  555. if(isAvaible('CalDavZAP'))
  556. {
  557. for(var i=0; i<globalResourceCalDAVList.collections.length;i++)
  558. if(globalResourceCalDAVList.collections[i].uid!=undefined && globalResourceCalDAVList.collections[i].someChanged)
  559. changeCounter++;
  560. for(var i=0; i<globalResourceCalDAVList.TodoCollections.length;i++)
  561. if(globalResourceCalDAVList.TodoCollections[i].uid!=undefined && globalResourceCalDAVList.TodoCollections[i].someChanged)
  562. changeCounter++;
  563. }
  564. if(changeCounter>0 || globalSettingsSaving!='')
  565. loadNextApplication(false);
  566. }
  567. function bindColorPickerClick(newElement)
  568. {
  569. newElement.click(function(event){
  570. var collectionType=null;
  571. var resourceSelectedClass=null;
  572. var resourceItems=null;
  573. if(newElement.parent().hasClass('resourceCalDAV_item'))
  574. {
  575. if(globalEventCollectionsLoading)
  576. return false;
  577. collectionType='event';
  578. resourceSelectedClass='resourceCalDAV_item_selected';
  579. resourceItems=newElement.parent().siblings('.resourceCalDAV_item_selected');
  580. }
  581. else if(newElement.parent().hasClass('resourceCalDAVTODO_item'))
  582. {
  583. if(globalTodoCollectionsLoading)
  584. return false;
  585. collectionType='todo';
  586. resourceSelectedClass='resourceCalDAV_item_selected';
  587. resourceItems=newElement.parent().siblings('.resourceCalDAV_item_selected');
  588. }
  589. else if(newElement.hasClass('resourceCardDAVColor'))
  590. {
  591. if(globalAddressbookCollectionsLoading)
  592. return false;
  593. collectionType='addressbook';
  594. resourceSelectedClass='resourceCardDAV_selected';
  595. resourceItems=newElement.parent().parent().siblings().find('.resourceCardDAV_selected');
  596. }
  597. var showInput = event.shiftKey;
  598. var colorpicker=$(this).siblings('.colorPicker');
  599. if(!$(this).hasClass('hasColorpicker'))
  600. {
  601. $(this).addClass('hasColorpicker');
  602. colorpicker.spectrum({
  603. chooseText: localization[globalInterfaceLanguage].buttonSave,
  604. cancelText: localization[globalInterfaceLanguage].buttonCancel,
  605. color: newElement.css('background-color'),
  606. showInput: showInput,
  607. preferredFormat: 'hex6',
  608. move: function(color)
  609. {
  610. newElement.css('background', color);
  611. },
  612. hide: function(color)
  613. {
  614. if(newElement.css('background-color') != colorpicker.spectrum('get').toRgbString())
  615. newElement.css('background', colorpicker.spectrum('get').toRgbString());
  616. },
  617. change: function(color)
  618. {
  619. newElement.css('background', color);
  620. if(collectionType=='event')
  621. {
  622. var coll = globalResourceCalDAVList.getEventCollectionByUID($(this).parent().attr('data-id'));
  623. netSaveProperty(coll, (typeof globalCalendarColorPropertyXmlns!='undefined'&&globalCalendarColorPropertyXmlns!=null&&globalCalendarColorPropertyXmlns!='' ? globalCalendarColorPropertyXmlns : 'http://apple.com/ns/ical/'), 'calendar-color', color.toHexString())
  624. }
  625. else if(collectionType=='todo')
  626. {
  627. var coll = globalResourceCalDAVList.getTodoCollectionByUID($(this).parent().attr('data-id'));
  628. netSaveProperty(coll, (typeof globalCalendarColorPropertyXmlns!='undefined'&&globalCalendarColorPropertyXmlns!=null&&globalCalendarColorPropertyXmlns!='' ? globalCalendarColorPropertyXmlns : 'http://apple.com/ns/ical/'), 'calendar-color', color.toHexString())
  629. }
  630. else if(collectionType=='addressbook')
  631. {
  632. var coll = globalResourceCardDAVList.getCollectionByUID($(this).parent().attr('data-id'));
  633. netSaveProperty(coll, (typeof globalAddrColorPropertyXmlns!='undefined'&&globalAddrColorPropertyXmlns!=null&&globalAddrColorPropertyXmlns!='' ? globalAddrColorPropertyXmlns : 'http://inf-it.com/ns/ab/'), 'addressbook-color', color.toHexString())
  634. }
  635. }
  636. });
  637. }
  638. else if(showInput!=colorpicker.spectrum('option', 'showInput'))
  639. colorpicker.spectrum('option', 'showInput',showInput);
  640. var container = colorpicker.spectrum('container');
  641. if(container.is(':visible')) {
  642. colorpicker.spectrum('hide');
  643. }
  644. else {
  645. var offset=$(this).offset();
  646. colorpicker.spectrum('show');
  647. if(event.pageY<$(window).height()/2) {
  648. offset.top+=$(this).outerHeight();
  649. container.removeClass('sp-inverse');
  650. }
  651. else {
  652. offset.top-=container.outerHeight();
  653. container.addClass('sp-inverse');
  654. }
  655. container.offset(offset);
  656. }
  657. resourceItems.removeClass(resourceSelectedClass);
  658. newElement.parent().addClass(resourceSelectedClass);
  659. return false;
  660. });
  661. }
  662. function loadNextApplication(forceLoad)
  663. {
  664. if(!globalFirstLoadNextApp)
  665. {
  666. if(isAvaible('CardDavMATE'))
  667. setAddressbookNumber();
  668. if(isAvaible('CalDavZAP'))
  669. setCalendarNumber(true);
  670. globalFirstLoadNextApp=true;
  671. }
  672. if(isAvaible('CardDavMATE') && !globalCardDAVCollectionSync && globalResourceCardDAVList.collections.length>0)
  673. {
  674. globalCardDAVCollectionSync=true;
  675. CardDAVnetLoadCollection(globalResourceCardDAVList.collections[0], forceLoad, false, null, 0, globalResourceCardDAVList.collections,true);
  676. }
  677. else if(isAvaible('CalDavZAP') && !globalCalDAVCollectionSync && globalResourceCalDAVList.collections.length>0)
  678. {
  679. globalCalDAVCollectionSync=true;
  680. CalDAVnetLoadCollection(globalResourceCalDAVList.collections[0], forceLoad, true, 0, globalResourceCalDAVList.collections);
  681. }
  682. else if(isAvaible('Projects') && !globalProjectSync && !isProjectsLoaded && getLoggedUser()!=null)
  683. {
  684. $('#MainLoaderInner').html('Loading projects');
  685. globalProjectSync=true;
  686. if(typeof globalCRMSettings != 'undefined')
  687. netLoadXSLT(globalCRMSettings.XSLTHref);
  688. else
  689. {
  690. console.log("Error: globalCRMSettings is not defined");
  691. loadNextApplication(false);
  692. }
  693. }
  694. else if(isAvaible('Reports') && !globalReportsSync && !isReportsLoaded && getLoggedUser()!=null)
  695. {
  696. $('#MainLoaderInner').html('Loading Reports');
  697. globalReportsSync=true;
  698. if(typeof globalCRMSettings != 'undefined')
  699. netLoadReportList(globalCRMSettings);
  700. else
  701. {
  702. console.log("Error: globalCRMSettings is not defined");
  703. loadNextApplication(false);
  704. }
  705. }
  706. else if(isAvaible('Settings') && !globalSettingsSync && !isSettingsLoaded && getLoggedUser()!=null)
  707. {
  708. globalSettingsSync = true;
  709. if(!isSettingsLoaded)
  710. loadNextApplication(false);
  711. if($('#ResourceSettingsList').children('.resourceSettings_item').length)
  712. $('#ResourceSettingsList').children().eq(0).trigger('click');
  713. }
  714. else
  715. {
  716. if((isAvaible('CalDavZAP') && !isCalDAVLoaded) || (isAvaible('CardDavMATE') && !isCardDAVLoaded))
  717. $('#MainLoader').fadeOut(1200, function(){$('#MainLoader').css('left','50px');});
  718. if(isAvaible('CardDavMATE'))
  719. {
  720. globalCardDAVCollectionSync=false;
  721. if(!isCardDAVLoaded)
  722. isCardDAVLoaded=true;
  723. }
  724. if(isAvaible('CalDavZAP'))
  725. {
  726. globalCalDAVCollectionSync=false;
  727. if(!isCalDAVLoaded)
  728. isCalDAVLoaded=true;
  729. }
  730. if(isAvaible('Projects'))
  731. {
  732. globalProjectSync=false;
  733. isProjectsLoaded = true;
  734. }
  735. if(isAvaible('Reports'))
  736. {
  737. globalReportsSync=false;
  738. isReportsLoaded = true;
  739. }
  740. if(isAvaible('Settings'))
  741. {
  742. globalSettingsSync=false;
  743. isSettingsLoaded = true;
  744. }
  745. }
  746. }
  747. function checkForApplication(inputApp)
  748. {
  749. if(!globalEnableAppSwitch || globalObjectLoading)
  750. return false;
  751. globalEnableAppSwitch=false;
  752. globalActiveApp=inputApp;
  753. var inputID = 'System'+inputApp;
  754. $('.System').not('#'+inputID).each(function(){
  755. $(this).animate({opacity : 0}, 666, function(){
  756. /* XXX - System display:none changes
  757. if($(this).attr('id').indexOf('CalDav')==-1)
  758. $(this).css('display','none');
  759. else*/
  760. $(this).css('visibility','hidden');
  761. });
  762. });
  763. /* XXX - System display:none changes
  764. if(inputID.indexOf('CalDav')==-1)
  765. $('#'+inputID).css('display','block').animate({opacity : 1}, 666, function(){globalEnableAppSwitch=true;});
  766. else*/
  767. $('#'+inputID).css('visibility','visible').animate({opacity : 1}, 666, function(){globalEnableAppSwitch=true;});
  768. }
  769. function getLoggedUser()
  770. {
  771. for(var i=0; i<globalAccountSettings.length;i++)
  772. if(globalAccountSettings[i].href.indexOf(globalLoginUsername)!=-1)
  773. return globalAccountSettings[i];
  774. return globalAccountSettings[0];
  775. }
  776. function login()
  777. {
  778. $('#LoginLoader').fadeTo(1200, 1, function(){
  779. globalLoginUsername=$('#LoginPage').find('[data-type="system_username"]').val();
  780. globalLoginPassword=$('#LoginPage').find('[data-type="system_password"]').val();
  781. loadConfig();
  782. });
  783. }
  784. function logout(forceLogout)
  785. {
  786. if((typeof forceLogout=='undefined' || forceLogout==null ) && (
  787. (isAvaible('CardDavMATE') && (!isCardDAVLoaded || globalCardDAVResourceSync)) ||
  788. (isAvaible('CalDavZAP') && (!isCalDAVLoaded || globalCalDAVResourceSync)) ||
  789. (isAvaible('Projects') && !isProjectsLoaded) ||
  790. (isAvaible('Settings') && (!isSettingsLoaded || (globalSettingsSaving!='' && !dontSaveSettings))) ||
  791. (isAvaible('CalDavZAP') && (globalLimitLoading!='' || globalLimitTodoLoading!=''))
  792. ))
  793. {
  794. globalPreventLogoutSync=true;
  795. return false;
  796. }
  797. clearInterval(globalResourceIntervalID);
  798. if(globalFirstLoadNextApp)
  799. globalFirstLoadNextApp=false;
  800. settingsLoaded=false;
  801. ignoreServerSettings=false;
  802. //save settings
  803. checkBeforeClose(false);
  804. globalResourceIntervalID=null;
  805. globalLoginUsername='';
  806. globalLoginPassword='';
  807. globalXMLCache=null;
  808. globalResourceNumber=0;
  809. globalResourceNumberCount=0;
  810. globalLoadedPrincipals=new Array();
  811. globalEmailAddress='';
  812. globalPreventLogoutSync=false;
  813. globalSyncSettingsSave=false;
  814. $(document.documentElement).unbind();
  815. // reset page title
  816. var tmpMatch = document.title.match('^(.*) \\[.*\\]$');
  817. if(tmpMatch!=null)
  818. document.title = tmpMatch[1];
  819. $('#LoginPage').fadeTo(2000, 1, function(){
  820. if(typeof isCalDAVLoaded!='undefined' && isCalDAVLoaded)
  821. {
  822. logoutCalDAV();
  823. isCalDAVLoaded=false;
  824. }
  825. if(typeof isCardDAVLoaded!='undefined' && isCardDAVLoaded)
  826. {
  827. logoutCardDAV();
  828. isCardDAVLoaded=false;
  829. }
  830. if(typeof isProjectsLoaded!='undefined' && isProjectsLoaded)
  831. {
  832. logoutProjects();
  833. isProjectsLoaded = false;
  834. }
  835. if(typeof isReportsLoaded!='undefined' && isReportsLoaded)
  836. {
  837. logoutReports();
  838. isReportsLoaded = false;
  839. }
  840. if(typeof isSettingsLoaded!='undefined' && isSettingsLoaded)
  841. {
  842. logoutSettings();
  843. isSettingsLoaded = false;
  844. }
  845. for(var i=globalAccountSettings.length-1;i>=0;i--)
  846. if(globalAccountSettings[i].type=='network')
  847. globalAccountSettings.splice(i, 1);
  848. if(typeof globalDemoMode=='undefined')
  849. {
  850. $('[data-type="system_username"]').val('').change();
  851. $('[data-type="system_password"]').val('').change();
  852. }
  853. $('.integration_d').hide();
  854. isUserLogged=false;
  855. if(globalSettings.defaultactiveapp.value==null)
  856. {
  857. if(isAvaible('CalDavZAP'))
  858. globalActiveApp='CalDavZAP';
  859. else if(isAvaible('CardDavMATE'))
  860. globalActiveApp='CardDavMATE';
  861. }
  862. else
  863. globalActiveApp=globalSettings.defaultactiveapp.value;
  864. resetSettings();
  865. if(isAvaible('CardDavMATE'))
  866. mainCardDAV();
  867. if(isAvaible('CalDavZAP'))
  868. mainCalDAV();
  869. if(isAvaible('Settings'))
  870. mainSettings();
  871. if(isAvaible('Projects'))
  872. mainProjects();
  873. if(isAvaible('Reports'))
  874. mainReports();
  875. init();
  876. });
  877. }
  878. function init()
  879. {
  880. // browser check
  881. if(($.browser.msie && parseInt($.browser.version, 10)<9) || $.browser.opera)
  882. $('#login_message').css('display','').text(localization[globalInterfaceLanguage].unsupportedBrowser);
  883. if(typeof globalDemoMode!='undefined')
  884. {
  885. if(typeof globalDemoMode.userName!=undefined)
  886. $('[data-type="system_username"]').val(globalDemoMode.userName).change();
  887. if(typeof globalDemoMode.userPassword!=undefined)
  888. $('[data-type="system_password"]').val(globalDemoMode.userPassword).change();
  889. }
  890. loadConfig();
  891. }
  892. function run()
  893. {
  894. isUserLogged=true;
  895. window.onfocus=function(){globalWindowFocus=true;}
  896. window.onblur=function(){if(globalSettings.backgroundsync.value==false) globalWindowFocus=false;}
  897. $('#LoginPage').fadeOut(2000);
  898. if(typeof globalAccountSettings=='undefined')
  899. {
  900. console.log('Error: \'no account configured\': see config.js!');
  901. return false;
  902. }
  903. if(typeof globalNewVersionNotifyUsers=='undefined' || globalNewVersionNotifyUsers!=null)
  904. netVersionCheck();
  905. document.title+=' ['+globalAccountSettings[0].userAuth.userName+']';
  906. // Automatically detect crossDomain settings
  907. var detectedHref=location.protocol+'//'+location.hostname+(location.port ? ':'+location.port : '');
  908. for(var i=0;i<globalAccountSettings.length;i++)
  909. {
  910. if(globalAccountSettings[i].crossDomain==undefined || typeof globalAccountSettings[i].crossDomain!='boolean')
  911. {
  912. if(globalAccountSettings[i].href.indexOf(detectedHref)==0)
  913. globalAccountSettings[i].crossDomain=false;
  914. else
  915. globalAccountSettings[i].crossDomain=true;
  916. console.log("Info: [userAccount: '"+globalAccountSettings[i].href.replace('\/\/', '//'+globalAccountSettings[i].userAuth.userName+'@')+"']: crossDomain set to: '"+(globalAccountSettings[i].crossDomain==true ? 'true' : 'false')+"'");
  917. }
  918. }
  919. if(typeof globalAvailableAppsArray!='undefined' && globalAvailableAppsArray!=null && globalAvailableAppsArray.length>1) {
  920. // show integration banner
  921. $('.integration_d').css('display', 'block');
  922. // show app buttons for available apps only
  923. if(globalAvailableAppsArray.indexOf('CalDavZAP')!=-1)
  924. $('#intCaldav').attr('title',localization[globalInterfaceLanguage].txtCalendars).css('display', 'block').find('.int_error').attr('alt',localization[globalInterfaceLanguage].txtError);
  925. if(globalAvailableAppsArray.indexOf('CalDavTODO')!=-1)
  926. $('#intCaldavTodo').attr('title',localization[globalInterfaceLanguage].txtTodos).css('display', 'block').find('.int_error').attr('alt',localization[globalInterfaceLanguage].txtError);
  927. if(globalAvailableAppsArray.indexOf('CardDavMATE')!=-1)
  928. $('#intCarddav').attr('title',localization[globalInterfaceLanguage].txtContacts).css('display', 'block').find('.int_error').attr('alt',localization[globalInterfaceLanguage].txtError);
  929. if(globalAvailableAppsArray.indexOf('Projects')!=-1)
  930. $('#intProjects').attr('title',localization[globalInterfaceLanguage].txtProjects).css('display', 'block').find('.int_error').attr('alt',localization[globalInterfaceLanguage].txtError);
  931. if(globalAvailableAppsArray.indexOf('Reports')!=-1)
  932. $('#intReports').attr('title',localization[globalInterfaceLanguage].txtReports).css('display', 'block').find('.int_error').attr('alt',localization[globalInterfaceLanguage].txtError);
  933. if(globalAvailableAppsArray.indexOf('Settings')!=-1)
  934. $('#intSettings').attr('title',localization[globalInterfaceLanguage].txtSettings).css('display', 'block').find('.int_error').attr('alt',localization[globalInterfaceLanguage].txtError);
  935. // show the refresh button
  936. if(typeof globalEnableRefresh==='boolean' && globalEnableRefresh && (globalAvailableAppsArray.indexOf('CalDavZAP')!=-1 || globalAvailableAppsArray.indexOf('CalDavTODO')!=-1 || globalAvailableAppsArray.indexOf('CardDavMATE')!=-1)) {
  937. $('#intRefresh').attr('title',localization[globalInterfaceLanguage].txtRefresh).find('.int_error').attr('alt',localization[globalInterfaceLanguage].txtError);
  938. $('#intRefresh').prev().addBack().css('display', 'block');
  939. }
  940. }
  941. $('#cacheDialogText').text(localization[globalInterfaceLanguage].txtCacheText);
  942. $('#cacheDialogButton').attr('value',localization[globalInterfaceLanguage].txtCacheButton);
  943. }
  944. function loadConfig()
  945. {
  946. if(isUserLogged)// !!!!!! kedy moze toto nastat? nexapem ...
  947. return false;
  948. var configLoaded=true;
  949. // Automatically detect crossDomain settings
  950. var detectedHref=location.protocol+'//'+location.hostname+(location.port ? ':'+location.port : '');
  951. // check username and password against the server and create config from globalNetworkCheckSettings
  952. if(typeof globalNetworkCheckSettings!='undefined' && globalNetworkCheckSettings!=null)
  953. {
  954. if(globalLoginUsername=='' || globalLoginPassword=='')
  955. {
  956. $('#LoginPage').fadeTo(500, 1, function(){if(typeof globalDemoMode=='undefined') $('[data-type="system_username"]').focus()});
  957. $('#LoginLoader').fadeOut(1200);
  958. return false;
  959. }
  960. else
  961. {
  962. if(globalNetworkCheckSettings.crossDomain==undefined || typeof globalNetworkCheckSettings.crossDomain!='boolean')
  963. {
  964. if(globalNetworkCheckSettings.href.indexOf(detectedHref)==0)
  965. globalNetworkCheckSettings.crossDomain=false;
  966. else
  967. globalNetworkCheckSettings.crossDomain=true;
  968. console.log("Info: [globalNetworkCheckSettings: '"+globalNetworkCheckSettings.href+"']: crossDomain set to: '"+(globalNetworkCheckSettings.crossDomain==true ? 'true' : 'false')+"'");
  969. }
  970. // !!!! preco sa riesi s logout buttonom prave tu?
  971. // show the logout button
  972. if(typeof globalAvailableAppsArray!='undefined' && globalAvailableAppsArray!=null && globalAvailableAppsArray.length>1) {
  973. $('#intLogout').prev().addBack().css('display', 'block');
  974. $('#intLogout').attr('title',localization[globalInterfaceLanguage].altLogout);
  975. }
  976. else {
  977. $('#Logout').css('display', 'block');
  978. }
  979. netCheckAndCreateConfiguration(globalNetworkCheckSettings);
  980. return true;
  981. }
  982. }
  983. // load the configuration XML(s) from the network
  984. if(typeof globalNetworkAccountSettings!='undefined' && globalNetworkAccountSettings!=null)
  985. {
  986. if(globalLoginUsername=='' || globalLoginPassword=='')
  987. {
  988. $('#LoginPage').fadeTo(500, 1, function(){if(typeof globalDemoMode=='undefined') $('[data-type="system_username"]').focus()});
  989. $('#LoginLoader').fadeOut(1200);
  990. return false;
  991. }
  992. else
  993. {
  994. if(globalNetworkAccountSettings.crossDomain==undefined || typeof globalNetworkAccountSettings.crossDomain!='boolean')
  995. {
  996. if(globalNetworkAccountSettings.href.indexOf(detectedHref)==0)
  997. globalNetworkAccountSettings.crossDomain=false;
  998. else
  999. globalNetworkAccountSettings.crossDomain=true;
  1000. console.log("Info: [globalNetworkAccountSettings: '"+globalNetworkAccountSettings.href+"']: crossDomain set to: '"+(globalNetworkAccountSettings.crossDomain==true ? 'true' : 'false')+"'");
  1001. }
  1002. // !!!! preco sa riesi s logout buttonom prave tu?
  1003. // show the logout button
  1004. if(typeof globalAvailableAppsArray!='undefined' && globalAvailableAppsArray!=null && globalAvailableAppsArray.length>1) {
  1005. $('#intLogout').prev().addBack().css('display', 'block');
  1006. $('#intLogout').attr('title',localization[globalInterfaceLanguage].altLogout);
  1007. }
  1008. else {
  1009. $('#Logout').css('display', 'block');
  1010. }
  1011. netLoadConfiguration(globalNetworkAccountSettings);
  1012. return true;
  1013. }
  1014. }
  1015. if((typeof globalNetworkAccountSettings=='undefined' || globalNetworkAccountSettings==null) && (typeof globalNetworkCheckSettings=='undefined' || globalNetworkCheckSettings==null) && (typeof globalAccountSettings!='undefined' && globalAccountSettings!=null) && globalAccountSettings.length>0)
  1016. {
  1017. var delegCount=0, delegIndex=0;
  1018. if(!isDelegationLoaded)
  1019. {
  1020. for(var i=0; i<globalAccountSettings.length; i++)
  1021. if((typeof globalAccountSettings[i].delegation=='boolean' && globalAccountSettings[i].delegation) || (globalAccountSettings[i].delegation instanceof Array && globalAccountSettings[i].delegation.length>0))
  1022. delegIndex=i;
  1023. for(var i=0; i<globalAccountSettings.length; i++)
  1024. if((typeof globalAccountSettings[i].delegation=='boolean' && globalAccountSettings[i].delegation) || (globalAccountSettings[i].delegation instanceof Array && globalAccountSettings[i].delegation.length>0))
  1025. {
  1026. delegCount++;
  1027. DAVresourceDelegation(globalAccountSettings[i], i, delegIndex);
  1028. }
  1029. if(delegCount>0)
  1030. isDelegationLoaded = true;
  1031. }
  1032. if(delegCount==0 && !isDelegationLoaded)
  1033. {
  1034. // start the client
  1035. if(isAvaible('CardDavMATE'))
  1036. runCardDAV();
  1037. if(isAvaible('CalDavZAP'))
  1038. runCalDAV();
  1039. if(isAvaible('Projects'))
  1040. runProjects();
  1041. if(isAvaible('Settings'))
  1042. runSettings();
  1043. globalResourceNumber=globalAccountSettings.length;
  1044. loadAllResources();
  1045. }
  1046. }
  1047. }
  1048. function globalMain()
  1049. {
  1050. for(var prop in globalSettings)
  1051. globalDefinedSettings.push(prop);
  1052. if(typeof globalEnabledApps=='undefined' || globalEnabledApps==null)
  1053. {
  1054. if(typeof isCalDAVAvaible!='undefined' && isCalDAVAvaible!=null && isCalDAVAvaible)
  1055. {
  1056. globalAvailableAppsArray[globalAvailableAppsArray.length]='CalDavZAP';
  1057. globalAvailableAppsArray[globalAvailableAppsArray.length]='CalDavTODO';
  1058. }
  1059. if(typeof isCardDAVAvaible!='undefined' && isCardDAVAvaible!=null && isCardDAVAvaible)
  1060. globalAvailableAppsArray[globalAvailableAppsArray.length]='CardDavMATE';
  1061. if(typeof isSettingsAvaible!='undefined' && isSettingsAvaible!=null && isSettingsAvaible)
  1062. globalAvailableAppsArray[globalAvailableAppsArray.length]='Settings';
  1063. if(typeof isProjectsAvaible!='undefined' && isProjectsAvaible!=null && isProjectsAvaible)
  1064. globalAvailableAppsArray[globalAvailableAppsArray.length]='Projects';
  1065. if(typeof isReportsAvaible!='undefined' && isReportsAvaible!=null && isReportsAvaible)
  1066. globalAvailableAppsArray[globalAvailableAppsArray.length]='Reports';
  1067. }
  1068. else
  1069. {
  1070. if(typeof isCalDAVAvaible!='undefined' && isCalDAVAvaible!=null && isCalDAVAvaible && (globalEnabledApps.indexOf('CalDavZAP')!=-1 || globalEnabledApps.indexOf('CalDavTODO')!=-1 ))
  1071. {
  1072. globalAvailableAppsArray[globalAvailableAppsArray.length]='CalDavZAP';
  1073. globalAvailableAppsArray[globalAvailableAppsArray.length]='CalDavTODO';
  1074. }
  1075. if(typeof isCardDAVAvaible!='undefined' && isCardDAVAvaible!=null && isCardDAVAvaible && globalEnabledApps.indexOf('CardDavMATE')!=-1)
  1076. globalAvailableAppsArray[globalAvailableAppsArray.length]='CardDavMATE';
  1077. if(typeof isSettingsAvaible!='undefined' && isSettingsAvaible!=null && isSettingsAvaible && globalEnabledApps.indexOf('Settings')!=-1)
  1078. globalAvailableAppsArray[globalAvailableAppsArray.length]='Settings';
  1079. if(typeof isProjectsAvaible!='undefined' && isProjectsAvaible!=null && isProjectsAvaible && globalEnabledApps.indexOf('Projects')!=-1)
  1080. globalAvailableAppsArray[globalAvailableAppsArray.length]='Projects';
  1081. if(typeof isReportsAvaible!='undefined' && isReportsAvaible!=null && isReportsAvaible)
  1082. globalAvailableAppsArray[globalAvailableAppsArray.length]='Reports';
  1083. }
  1084. if(globalAvailableAppsArray.length>1)
  1085. isIntegrated=true;
  1086. if(globalSettings.defaultactiveapp.value==null)
  1087. {
  1088. if(isAvaible('CardDavMATE'))
  1089. globalActiveApp='CardDavMATE';
  1090. else if(isAvaible('CalDavZAP'))
  1091. globalActiveApp='CalDavZAP';
  1092. }
  1093. else
  1094. globalActiveApp=globalSettings.defaultactiveapp.value;
  1095. if(isAvaible('CardDavMATE'))
  1096. {
  1097. // Modify available inputs before making additional changes to vCard form
  1098. if(typeof globalDisabledContactAttributes!='undefined' && globalDisabledContactAttributes instanceof Array)
  1099. for(var i=0;i<globalDisabledContactAttributes.length;i++)
  1100. $('#vCardTemplate').find('[data-attr-name="'+jqueryEscapeSelector(globalDisabledContactAttributes[i])+'"]').remove();
  1101. // hook for vCard template extension
  1102. if(typeof(globalContactsExtInitMain)=='function')
  1103. globalContactsExtInitMain($('#vCardTemplate'));
  1104. }
  1105. /*************************** BAD HACKS SECTION ***************************/
  1106. // here we fix the cross OS/cross broser problems (unfixable in pure CSS)
  1107. if($.browser.webkit && !!window.chrome) /* Chrome */
  1108. {
  1109. if(navigator.platform.toLowerCase().indexOf('win')==0) /* Windows version */
  1110. {
  1111. $('#LoginPage, #vCardTemplate, #event_details_template, #todo_details_template, #EditorBoxSettings').find('input').css('text-indent', '2px');
  1112. $('#LoginPage, #vCardTemplate, #event_details_template, #todo_details_template, #EditorBoxSettings').find('select').css({'padding-left': '0px', 'padding-right': '13px'});
  1113. }
  1114. else /* non-Windows version */
  1115. $('#LoginPage, #vCardTemplate, #event_details_template, #todo_details_template, #EditorBoxSettings').find('input').css('text-indent', '1px');
  1116. }
  1117. else if($.browser.safari)
  1118. {
  1119. $('#LoginPage, #vCardTemplate, #event_details_template, #todo_details_template, #EditorBoxSettings').find('textarea').addClass('safari_hack');
  1120. $('#LoginPage, #vCardTemplate, #event_details_template, #todo_details_template, #EditorBoxSettings').find('input').addClass('safari_hack');
  1121. }
  1122. else if($.browser.msie) /* IE */
  1123. {
  1124. if(parseInt($.browser.version, 10)==10) /* IE 10 (because there are no more conditional comments) */
  1125. {
  1126. $('select').css({'padding-top': '1px', 'padding-left': '0px', 'padding-right': '0px'});
  1127. $('textarea').css('padding-top', '3px');
  1128. $('input[type=button]').css('padding-top', '2px');
  1129. }
  1130. // ADD SVG to login screen
  1131. var newSVG=$(SVG_select_login).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-19px', 'vertical-align': 'top', 'background-color': '#ffffff'}); // background-color = stupid IE9 bug
  1132. $('#Login').find('select[data-type="language"]').after($($('<div>').append($(newSVG).clone()).html()));
  1133. }
  1134. else if($.browser.mozilla)
  1135. {
  1136. // ADD SVG to login screen
  1137. var newSVG=$(SVG_select_login).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-19px', 'vertical-align': 'top', 'background-color': '#ffffff'}); // background-color = stupid IE9 bug
  1138. $('#Login').find('select[data-type="language"]').after($($('<div>').append($(newSVG).clone()).html()));
  1139. }
  1140. /*************************** END OF BAD HACKS SECTION ***************************/
  1141. /* language selector */
  1142. var lang_num=0;
  1143. var language_option=$('#Login').find('[data-type="language"]').find('option');
  1144. $('#Login').find('[data-type="language"]').html('');
  1145. if(typeof globalInterfaceCustomLanguages!='undefined' && globalInterfaceCustomLanguages.length!=undefined && globalInterfaceCustomLanguages.length>0)
  1146. {
  1147. for(var i=0; i<globalInterfaceCustomLanguages.length; i++)
  1148. if(localization[globalInterfaceCustomLanguages[i]]!=undefined)
  1149. {
  1150. var tmp=language_option;
  1151. tmp.attr('data-type',globalInterfaceCustomLanguages[i]);
  1152. tmp.text(localization[globalInterfaceCustomLanguages[i]]['_name_']);
  1153. $('#Login').find('[data-type="language"]').append(tmp.clone());
  1154. lang_num++;
  1155. }
  1156. }
  1157. if(lang_num==0) // no language option, use the default (all languages from localization.js)
  1158. for(var loc in localization)
  1159. {
  1160. var tmp=language_option;
  1161. tmp.attr('data-type',loc);
  1162. tmp.text(localization[loc]['_name_']); // translation
  1163. $('#Login').find('[data-type="language"]').append(tmp.clone());
  1164. }
  1165. // select the globalInterfaceLanguage in the interface
  1166. $('[data-type="language"]').find('[data-type='+globalInterfaceLanguage+']').prop('selected',true);
  1167. // set login screen logo
  1168. if(isAvaible('CalDavZAP') && !isAvaible('CardDavMATE'))
  1169. {
  1170. $('[data-size="login_logo"]').find('img').attr('src', "caldavzap/images/cdz_logo.svg");
  1171. $('#LoginPage').find('.footer').text('CalDavZAP - the open source CalDAV web client');
  1172. }
  1173. else if(isAvaible('CardDavMATE') && !isAvaible('CalDavZAP'))
  1174. {
  1175. $('[data-size="login_logo"]').find('img').attr('src', "images/cdm_logo.svg");
  1176. $('#LoginPage').find('.footer').text('CardDavMATE - the open source CardDAV web client');
  1177. }
  1178. else
  1179. {
  1180. $('#Login').css('margin-top', '41px');
  1181. $('[data-size="login_logo"]').find('img').attr('src', "images/infcloud_logo.svg");
  1182. $('#LoginPage').find('.footer').text('InfCloud - the open source CalDAV/CardDAV web client');
  1183. }
  1184. $('#LoginPage').find('.footer').attr('title', globalVersion);
  1185. var server_info_tag = $('<div>Server: </div>')
  1186. server_info_tag.append($('<a>', {href: globalNetworkCheckSettings.href}).append(globalNetworkCheckSettings.href))
  1187. $('#LoginPage').find('.footer').append(server_info_tag);
  1188. if(isAvaible('CardDavMATE'))
  1189. globalMainCardDAV();
  1190. if(isAvaible('CalDavZAP'))
  1191. globalMainCalDAV();
  1192. if(isAvaible('Projects'))
  1193. globalMainProjects();
  1194. if(isAvaible('Reports'))
  1195. globalMainReports();
  1196. if(isAvaible('Settings'))
  1197. globalMainSettings();
  1198. if(isAvaible('CardDavMATE'))
  1199. mainCardDAV();
  1200. if(isAvaible('CalDavZAP'))
  1201. mainCalDAV();
  1202. if(isAvaible('Projects'))
  1203. mainProjects();
  1204. if(isAvaible('Reports'))
  1205. mainReports();
  1206. if(isAvaible('Settings'))
  1207. mainSettings();
  1208. init();
  1209. }
  1210. function saveSettings(isFormSave)
  1211. {
  1212. if(globalSettings.islastdefaultactiveapp.value)
  1213. globalSettings.defaultactiveapp.value=globalActiveApp;
  1214. globalSettings.version.value=globalSettingsVersion;
  1215. var rex = new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)');
  1216. if(isAvaible('CalDavZAP'))
  1217. {
  1218. globalSettings.activecalendarcollections.value.splice(0, globalSettings.activecalendarcollections.value.length);
  1219. globalSettings.activetodocollections.value.splice(0, globalSettings.activetodocollections.value.length);
  1220. globalSettings.todolistfilterselected.value.splice(0, globalSettings.todolistfilterselected.value.length);
  1221. for(var i=0;i<globalVisibleCalDAVCollections.length;i++)
  1222. {
  1223. var uidParts=globalVisibleCalDAVCollections[i].match(rex)
  1224. globalSettings.activecalendarcollections.value.splice(globalSettings.activecalendarcollections.value.length , 0, uidParts[1]+uidParts[3]);
  1225. }
  1226. for(var i=0;i<globalVisibleCalDAVTODOCollections.length;i++)
  1227. {
  1228. var uidParts=globalVisibleCalDAVTODOCollections[i].match(rex);
  1229. globalSettings.activetodocollections.value.splice(globalSettings.activetodocollections.value.length , 0, uidParts[1]+uidParts[3]);
  1230. }
  1231. if(globalSettings.islastactiveview.value)
  1232. {
  1233. var view= $('#calendar').fullCalendar('getView');
  1234. globalSettings.activeview.value=view.name;
  1235. }
  1236. if(globalSettings.islasttimezone.value)
  1237. globalSettings.timezone.value=globalSessionTimeZone;
  1238. var uidSelected=$('#ResourceCalDAVList').find('.resourceCalDAV_item_selected').attr('data-id');
  1239. if(uidSelected!=undefined && uidSelected!='')
  1240. {
  1241. var par=uidSelected.split('/');
  1242. globalSettings.calendarselected.value=par[par.length-3]+'/'+par[par.length-2]+'/';
  1243. }
  1244. uidSelected=$('#ResourceCalDAVTODOList').find('.resourceCalDAV_item_selected').attr('data-id');
  1245. if(uidSelected!=undefined && uidSelected!='')
  1246. {
  1247. var par=uidSelected.split('/');
  1248. globalSettings.todocalendarselected.value=par[par.length-3]+'/'+par[par.length-2]+'/';
  1249. }
  1250. var filterArray = $('.fc-filter-option-selected');
  1251. for(var i=0; i<filterArray.length; i++)
  1252. globalSettings.todolistfilterselected.value.splice(globalSettings.todolistfilterselected.value.length,0,$($('.fc-filter-option-selected')[i]).attr('data-type'));
  1253. }
  1254. if(isAvaible('CardDavMATE'))
  1255. {
  1256. globalSettings.activeaddressbookcollections.value.splice(0, globalSettings.activeaddressbookcollections.value.length);
  1257. var visAddrs = dataGetChecked('#ResourceCardDAVList');
  1258. for(var i=0;i<visAddrs.length;i++)
  1259. {
  1260. if(visAddrs[i]!='undefined')
  1261. {
  1262. var uidPart=visAddrs[i].match(RegExp('^(https?://)(.*)', 'i'))[1];
  1263. var uidPart2= visAddrs[i].match(RegExp('^(https?://)(.*)', 'i'))[2].split('@')[2];
  1264. globalSettings.activeaddressbookcollections.value.splice(globalSettings.activeaddressbookcollections.value.length , 0, uidPart+uidPart2);
  1265. }
  1266. }
  1267. if($('#ResourceCardDAVList').find('.group.resourceCardDAV_selected').length>0)
  1268. var uidASelected=$('#ResourceCardDAVList').find('.group.resourceCardDAV_selected').attr('data-id');
  1269. else if($('#ResourceCardDAVList').find('.resourceCardDAV_selected').length>0)
  1270. var uidASelected=$('#ResourceCardDAVList').find('.resourceCardDAV_selected').attr('data-id');
  1271. else
  1272. var uidASelected='';
  1273. if(uidASelected!=undefined && uidASelected!='')
  1274. globalSettings.addressbookselected.value=uidASelected;
  1275. }
  1276. if(isAvaible('Settings') && isFormSave)
  1277. return applyFormSettings();
  1278. else
  1279. return globalSettings;
  1280. }
  1281. function loadXMLSetings(settingsXML)
  1282. {
  1283. $(settingsXML).children().each(
  1284. function(ind,elm)
  1285. {
  1286. var type = $(elm).attr('type');
  1287. var locked = typeof $(elm).attr('locked')!='undefined'&&$(elm).attr('locked')!=null&&$(elm).attr('locked')=='true' ? true : false;
  1288. if(typeof globalSettings[$(elm).prop('tagName').toLowerCase()] == 'undefined')
  1289. return true;
  1290. if(locked)
  1291. globalSettings[$(elm).prop('tagName').toLowerCase()].locked=true;
  1292. if($(elm).children().length>0)
  1293. {
  1294. globalSettings[$(elm).prop('tagName').toLowerCase()].value = new Array();
  1295. $(elm).children().each(function(pind,pelm)
  1296. {
  1297. if($(elm).prop('tagName').toLowerCase() == 'urihandlerprofile')
  1298. {
  1299. globalSettings[$(elm).prop('tagName').toLowerCase()].value = {};
  1300. globalSettings[$(elm).prop('tagName').toLowerCase()].value[$(pelm).text().toLowerCase()] = $(pelm).attr('url');
  1301. }
  1302. else if($(elm).prop('tagName').toLowerCase() == 'addresscountryequivalence')
  1303. {
  1304. var eqObject = {};
  1305. eqObject['country'] = $(pelm).attr('name');
  1306. eqObject['regex'] = $(pelm).attr('regex');
  1307. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(eqObject);
  1308. }
  1309. else if($(elm).prop('tagName').toLowerCase() == 'compatibility')
  1310. {
  1311. globalSettings[$(elm).prop('tagName').toLowerCase()].value = {};
  1312. globalSettings[$(elm).prop('tagName').toLowerCase()].value[$(pelm).attr('name')] = new Array();
  1313. $(pelm).children().each(function(rind,relm)
  1314. {
  1315. globalSettings[$(elm).prop('tagName').toLowerCase()].value[$(pelm).attr('name')].push($(relm).text());
  1316. });
  1317. }
  1318. else if($(pelm).text()!='')
  1319. {
  1320. switch(type)
  1321. {
  1322. case 'integer':
  1323. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(parseInt($(pelm).text(),10));
  1324. break;
  1325. case 'string':
  1326. if($(pelm).text()!='null')
  1327. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push($(pelm).text());
  1328. else
  1329. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(null);
  1330. break;
  1331. case 'boolean':
  1332. if($(pelm).text() == 'true')
  1333. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(true);
  1334. else
  1335. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(false);
  1336. break;
  1337. default:
  1338. break;
  1339. }
  1340. }
  1341. });
  1342. }
  1343. else if($(elm).text()!='')
  1344. {
  1345. switch(type)
  1346. {
  1347. case 'integer':
  1348. globalSettings[$(elm).prop('tagName').toLowerCase()].value = parseInt($(elm).text(),10);
  1349. break;
  1350. case 'string':
  1351. if($(elm).text()!='null')
  1352. globalSettings[$(elm).prop('tagName').toLowerCase()].value = $(elm).text();
  1353. else
  1354. globalSettings[$(elm).prop('tagName').toLowerCase()].value = null;
  1355. break;
  1356. case 'boolean':
  1357. if($(elm).text() == 'true')
  1358. globalSettings[$(elm).prop('tagName').toLowerCase()].value = true;
  1359. else if($(elm).text() == 'false')
  1360. globalSettings[$(elm).prop('tagName').toLowerCase()].value = false;
  1361. break;
  1362. default:
  1363. break;
  1364. }
  1365. }
  1366. });
  1367. }
  1368. function applyServerSettings(inputSettings)
  1369. {
  1370. if(typeof inputSettings.activecalendarcollections == 'undefined' || inputSettings.activecalendarcollections==null)
  1371. inputSettings.activecalendarcollections = new Array();
  1372. if(typeof inputSettings.activetodocollections == 'undefined' || inputSettings.activetodocollections==null)
  1373. inputSettings.activetodocollections = new Array();
  1374. if(typeof inputSettings.loadedcalendarcollections == 'undefined' || inputSettings.loadedcalendarcollections==null)
  1375. {
  1376. inputSettings.loadedcalendarcollections = new Array();
  1377. if(isAvaible('CalDavZAP'))
  1378. $('#showUnloadedCalendars').css('display','none');
  1379. }
  1380. if(typeof inputSettings.loadedtodocollections == 'undefined' || inputSettings.loadedtodocollections==null)
  1381. {
  1382. inputSettings.loadedtodocollections = new Array();
  1383. if(isAvaible('CalDavZAP'))
  1384. $('#showUnloadedCalendarsTODO').css('display','none');
  1385. }
  1386. if(typeof inputSettings.activeaddressbookcollections == 'undefined' || inputSettings.activeaddressbookcollections==null)
  1387. inputSettings.activeaddressbookcollections = new Array();
  1388. if(typeof inputSettings.loadedaddressbookcollections == 'undefined' || inputSettings.loadedaddressbookcollections==null)
  1389. {
  1390. inputSettings.loadedaddressbookcollections = new Array();
  1391. if(isAvaible('CardDavMATE'))
  1392. $('#showUnloadedAddressbooks').css('display','none');
  1393. }
  1394. transformSettings(inputSettings);
  1395. for(var prop in inputSettings)
  1396. {
  1397. if(globalDefinedSettings.indexOf(prop)==-1 || (typeof globalPreviousSupportedSettings !='undefined' && globalPreviousSupportedSettings.indexOf(prop)==-1))
  1398. {
  1399. if(globalDefinedSettings.indexOf(prop)==-1)
  1400. console.log('Warning: Unsupported property: \''+prop+'\' (you can safely ignore this message)');
  1401. continue;
  1402. }
  1403. if(typeof globalSettings[prop] !='undefined' && !globalSettings[prop].locked)
  1404. globalSettings[prop].value=inputSettings[prop];
  1405. }
  1406. }
  1407. function transformSettings(settings) {
  1408. if(!settings.version) {
  1409. settings.version = 1;
  1410. }
  1411. while(settings.version<globalSettingsVersion) {
  1412. console.log('Warning: Detected outdated server settings (version ' + settings.version++ +') - transforming to version ' + settings.version);
  1413. switch(settings.version) {
  1414. case 2:
  1415. if(typeof globalActiveCalendarCollections!='undefined' && globalActiveCalendarCollections!=null)
  1416. settings.activecalendarcollections=globalActiveCalendarCollections.slice();
  1417. else
  1418. settings.activecalendarcollections.splice(0, settings.activecalendarcollections.length);
  1419. if(typeof globalActiveTodoCollections!='undefined' && globalActiveTodoCollections!=null)
  1420. settings.activetodocollections=globalActiveTodoCollections.slice();
  1421. else
  1422. settings.activetodocollections.splice(0, settings.activetodocollections.length);
  1423. if(typeof globalLoadedCalendarCollections!='undefined' && globalLoadedCalendarCollections!=null)
  1424. settings.loadedcalendarcollections=globalLoadedCalendarCollections.slice();
  1425. else
  1426. settings.loadedcalendarcollections.splice(0, settings.loadedcalendarcollections.length);
  1427. if(typeof globalLoadedTodoCollections!='undefined' && globalLoadedTodoCollections!=null)
  1428. settings.loadedtodocollections=globalLoadedTodoCollections.slice();
  1429. else
  1430. settings.loadedtodocollections.splice(0, settings.loadedtodocollections.length);
  1431. if(typeof globalActiveAddressbookCollections!='undefined' && globalActiveAddressbookCollections!=null)
  1432. settings.activeaddressbookcollections=globalActiveAddressbookCollections.slice();
  1433. else
  1434. settings.activeaddressbookcollections.splice(0, settings.activeaddressbookcollections.length);
  1435. if(typeof globalLoadedAddressbookCollections!='undefined' && globalLoadedAddressbookCollections!=null)
  1436. settings.loadedaddressbookcollections=globalLoadedAddressbookCollections.slice();
  1437. else
  1438. settings.loadedaddressbookcollections.splice(0, settings.loadedaddressbookcollections.length);
  1439. if(typeof globalContactStoreFN!='undefined' && globalContactStoreFN!=null)
  1440. settings.contactstorefn=globalContactStoreFN.slice();
  1441. else
  1442. settings.contactstorefn=['prefix', ' last', ' middle', ' first', ' suffix'];
  1443. break;
  1444. case 3:
  1445. settings.collectiondisplay=(typeof globalCollectionDisplay!='undefined' && globalCollectionDisplay!=null && globalCollectionDisplay!='') ? globalCollectionDisplay : (
  1446. (typeof globalGroupContactsByCompanies!='undefined' && globalGroupContactsByCompanies) ?
  1447. [{label: '{Name}', value: {company: ['{Company}', ' [{Department}]'], personal: ['{LastName}', ' {MiddleName}', ' {FirstName}']}}, {label: '{JobTitle}', value: ['{JobTitle}']}, {label: '{Email}', value: ['{Email[:0]}']}, {label: '{Phone} 1', value: ['{Phone[:0]}']}, {label: '{Phone} 2', value: ['{Phone[:1]}']}, {label: '{NoteText}', value: ['{NoteText}']}] :
  1448. [{label: '{Name}', value: ['{LastName}', ' {MiddleName}', ' {FirstName}']}, {label: '{Company} [{Department}]', value: ['{Company}', ' [{Department}]']}, {label: '{JobTitle}', value: ['{JobTitle}']}, {label: '{Email}', value: ['{Email[:0]}']}, {label: '{Phone} 1', value: ['{Phone[:0]}']}, {label: '{Phone} 2', value: ['{Phone[:1]}']}, {label: '{NoteText}', value: ['{NoteText}']}]
  1449. );
  1450. settings.collectionsort=(typeof globalCollectionSort!='undefined' && globalCollectionSort!=null && globalCollectionSort!='') ? globalCollectionSort : '';
  1451. break;
  1452. default:
  1453. break;
  1454. }
  1455. }
  1456. }
  1457. function loadSettings(strobj, fromServer, syncMode)
  1458. {
  1459. if(settingsLoaded && !syncMode)
  1460. return false;
  1461. try
  1462. {
  1463. objNew = jQuery.parseJSON(strobj);
  1464. if(typeof objNew=='object')
  1465. {
  1466. if(!syncMode && typeof globalSettingsXML!='undefined' && globalSettingsXML!=null && globalSettingsXML!='')
  1467. loadXMLSetings($(globalSettingsXML));
  1468. if(fromServer)
  1469. applyServerSettings(objNew);
  1470. // $.extend(globalSettings,objNew);
  1471. }
  1472. }
  1473. catch(err)
  1474. {
  1475. console.log('load settings - JSON parsing error: '+err);
  1476. delete globalSettings.version.value;
  1477. loadSettings(JSON.stringify(globalSettings), false, false);
  1478. return false;
  1479. }
  1480. if(syncMode)
  1481. return false;
  1482. if(isAvaible('CalDavZAP'))
  1483. {
  1484. for(var i=0;i<globalSettings.timezonesenabled.value.length;i++)
  1485. if(timeZonesEnabled.indexOf(globalSettings.timezonesenabled.value[i])==-1)
  1486. timeZonesEnabled.push(globalSettings.timezonesenabled.value[i]);
  1487. if(globalSettings.timezonesupport.value)
  1488. {
  1489. globalSessionTimeZone=globalSettings.timezone.value;
  1490. if(globalSessionTimeZone != null && timeZonesEnabled.indexOf(globalSessionTimeZone)==-1)
  1491. timeZonesEnabled.push(globalSessionTimeZone);
  1492. }
  1493. else
  1494. {
  1495. globalSessionTimeZone = 'local';
  1496. timeZonesEnabled.push('local');
  1497. }
  1498. initTimepicker(globalSettings.ampmformat.value);
  1499. if(globalSettings.timeformatagenda.value==null)
  1500. {
  1501. if(globalSettings.ampmformat.value)
  1502. globalSettings.timeformatagenda.value='h:mm TT{ - h:mm TT}';
  1503. else
  1504. globalSettings.timeformatagenda.value='H:mm{ - H:mm}';
  1505. }
  1506. if(globalSettings.timeformatbasic.value==null)
  1507. {
  1508. if(globalSettings.ampmformat.value)
  1509. globalSettings.timeformatbasic.value = 'h:mmT{-h:mmT}';
  1510. else
  1511. globalSettings.timeformatbasic.value = 'H:mm{-H:mm}';
  1512. }
  1513. if(globalSettings.appleremindersmode.value)
  1514. {
  1515. if(globalSettings.todolistfilterselected.value.indexOf('filterAction')==-1 && globalSettings.todolistfilterselected.value.indexOf('filterCompleted')==-1)
  1516. {
  1517. if(globalSettings.todolistfilterselected.value.indexOf('filterProgress')!=-1)
  1518. globalSettings.todolistfilterselected.value[globalSettings.todolistfilterselected.value.indexOf('filterProgress')] = 'filterAction';
  1519. if(globalSettings.todolistfilterselected.value.indexOf('filterCanceled')!=-1)
  1520. globalSettings.todolistfilterselected.value[globalSettings.todolistfilterselected.value.indexOf('filterCanceled')] = 'filterAction';
  1521. }
  1522. }
  1523. if(globalSettings.eventstartfuturelimit.value == null)
  1524. {
  1525. var now=new Date();
  1526. globalToLoadedLimit = new Date(now.getFullYear(), now.getMonth()+12, 1, 0, 0, 0);
  1527. globalToLoadedLimit.setMilliseconds(0);
  1528. globalBeginFuture = new Date(globalToLoadedLimit.getTime());
  1529. globalBeginFuture.setDate(globalBeginFuture.getDate()+14);
  1530. globalToLoadedLimitTodo = new Date(now.getFullYear(), now.getMonth()+12, 1, 0, 0, 0);
  1531. globalToLoadedLimitTodo.setMilliseconds(0);
  1532. }
  1533. if(globalSettings.enablekbnavigation.value!==false)
  1534. initKbTodoNavigation();
  1535. initFullCalendar();
  1536. initTodoList();
  1537. $('#SystemCalDavZAP .fc-header-title').css('width', $('#main_h_placeholder').width()-$('#SystemCalDavZAP .fc-header-left').outerWidth()-$('#SystemCalDavZAP .fc-header-right').outerWidth());
  1538. $('#ResourceCalDAVList, #ResourceCalDAVTODOList').css('bottom',(globalSettings.timezonesupport.value ? 20 : 0));
  1539. $('#alertBox').css('left', ($(window).width()/2)-($('#alertBox').width()/2));
  1540. }
  1541. if(isAvaible('CardDavMATE'))
  1542. {
  1543. // set ABListTableLayout
  1544. globalRefAbListTableHeader = $('#ABListTable').find('.ablist_table_header');
  1545. var colgroups = $('#ABListTable').find('colgroup');
  1546. for(var i=0; i<getDataColumnCount(); i++) {
  1547. globalRefAbListTableHeader.append('<th>');
  1548. colgroups.append('<col>');
  1549. }
  1550. globalRefAbListTableHeader.children().slice(globalFixedContactDataColumnsCount).each(function(ind) {
  1551. $(this).text(getDataColumnLabelAtIndex(ind));
  1552. });
  1553. globalRefABListTableCols=$('#ABListTable').find('colgroup').first().children();
  1554. globalRefABListInnerTableCols=$('#ABListTableInner').find('colgroup').children();
  1555. $('#ABListTable').find('.ablist_table_container').children().attr('colspan', getDataColumnCount()+globalFixedContactDataColumnsCount);
  1556. globalRefABListTable.children('.ablist_header').children().attr('colspan', getDataColumnCount()+globalFixedContactDataColumnsCount);
  1557. if(!globalOrigABListHeader) {
  1558. globalOrigABListHeader=globalRefABListTable.children('.ablist_header').remove();
  1559. }
  1560. if(!globalOrigABListItem) {
  1561. globalOrigABListItem=globalRefABListTable.children('.ablist_item').remove();
  1562. }
  1563. if(globalSettings.enablekbnavigation.value!==false)
  1564. initKbAddrNavigation();
  1565. applyAddrSettings(globalTranslVcardTemplate);
  1566. applyAddrSettings($('#vCardEditor'));
  1567. }
  1568. if(isAvaible('Projects'))
  1569. if(globalSettings.enablekbnavigation.value!==false)
  1570. initKbProjectNavigation();
  1571. settingsLoaded=true;
  1572. if(!isAvaible(globalSettings.defaultactiveapp.value))
  1573. globalActiveApp = globalAvailableAppsArray[0];
  1574. else
  1575. globalActiveApp = globalSettings.defaultactiveapp.value;
  1576. }
  1577. function checkForLoadedCollections(inputSettings)
  1578. {
  1579. var val='', triggerSync=true;
  1580. globalLoadedCollectionsNumber=0;
  1581. globalLoadedCollectionsCount=0;
  1582. if(globalSettingsSaving=='event')
  1583. {
  1584. hideUnloadedCollections('event');
  1585. val = inputSettings.loadedcalendarcollections.value;
  1586. if(val.length>0)
  1587. globalLoadedCollectionsNumber+=$(val).not(globalSettings.loadedcalendarcollections.value).length;
  1588. else
  1589. globalLoadedCollectionsNumber++;
  1590. if($(globalSettings.loadedcalendarcollections.value).not(val).length>0)
  1591. {
  1592. if(globalLoadedCollectionsNumber==0)
  1593. {
  1594. triggerSync=false;
  1595. globalFirstHideLoader=false;
  1596. }
  1597. var unloadArray = $(globalSettings.loadedcalendarcollections.value).not(val);
  1598. unloadCalDAVCollection(unloadArray.toArray(),true);
  1599. }
  1600. if(triggerSync)
  1601. addLoadCalDAVCollection(val, true);
  1602. globalSettings.loadedcalendarcollections.value = val;
  1603. }
  1604. else if(globalSettingsSaving=='todo')
  1605. {
  1606. hideUnloadedCollections('todo');
  1607. val = inputSettings.loadedtodocollections.value;
  1608. if(val.length>0)
  1609. globalLoadedCollectionsNumber+=$(val).not(globalSettings.loadedtodocollections.value).length;
  1610. else
  1611. globalLoadedCollectionsNumber++;
  1612. if($(globalSettings.loadedtodocollections.value).not(val).length>0)
  1613. {
  1614. if(globalLoadedCollectionsNumber==0)
  1615. {
  1616. triggerSync=false;
  1617. globalFirstHideLoader=false;
  1618. }
  1619. var unloadArray = $(globalSettings.loadedtodocollections.value).not(val);
  1620. unloadCalDAVCollection(unloadArray.toArray(),false);
  1621. }
  1622. if(triggerSync)
  1623. addLoadCalDAVCollection(val, false);
  1624. globalSettings.loadedtodocollections.value = val;
  1625. }
  1626. else if(globalSettingsSaving=='addressbook')
  1627. {
  1628. hideUnloadedCardDAVCollections();
  1629. val = inputSettings.loadedaddressbookcollections.value;
  1630. if(val.length>0)
  1631. globalLoadedCollectionsNumber+=$(val).not(globalSettings.loadedaddressbookcollections.value).length;
  1632. else
  1633. globalLoadedCollectionsNumber++;
  1634. if($(globalSettings.loadedaddressbookcollections.value).not(val).length>0)
  1635. {
  1636. if(globalLoadedCollectionsNumber==0)
  1637. {
  1638. triggerSync=false;
  1639. globalFirstHideLoader=false;
  1640. }
  1641. var unloadArray = $(globalSettings.loadedaddressbookcollections.value).not(val);
  1642. unloadCardDAVCollection(unloadArray.toArray());
  1643. }
  1644. if(triggerSync)
  1645. addLoadCardDAVCollection(val)
  1646. globalSettings.loadedaddressbookcollections.value = val;
  1647. }
  1648. if(triggerSync)
  1649. ifLoadCollections();
  1650. }
  1651. function checkBeforeClose(isFormSave)
  1652. {
  1653. if((isAvaible('CalDavZAP') && globalCalDAVInitLoad) || (isAvaible('CardDavMATE') && globalCardDAVInitLoad))
  1654. return false;
  1655. var old_settings=JSON.stringify(globalSettings);
  1656. var settings=saveSettings(isFormSave);
  1657. var new_settings = JSON.stringify(settings);
  1658. if(old_settings == new_settings)
  1659. return false;
  1660. for(var i=0;i<globalAccountSettings.length;i++)
  1661. if(globalAccountSettings[i].href.indexOf(globalLoginUsername)!=-1 && globalAccountSettings[i].settingsAccount)
  1662. {
  1663. netSaveSettings(globalAccountSettings[i], settings, isFormSave,false);
  1664. break;
  1665. }
  1666. }
  1667. function isEachResourceLoaded()
  1668. {
  1669. var loaded = true;
  1670. for(var i=0; i< globalAccountSettings.length; i++)
  1671. if(typeof globalAccountSettings[i].errorLoaded!='undefined' && globalAccountSettings[i].errorLoaded!=null && globalAccountSettings[i].errorLoaded===true)
  1672. loaded=false;
  1673. return loaded;
  1674. }
  1675. window.onload=globalMain;
  1676. window.onkeydown=function(event)
  1677. {
  1678. switch(event.which) {
  1679. case 13:
  1680. if(!isUserLogged)
  1681. $('#Login').find('[data-type="system_login"]').trigger('click');
  1682. break;
  1683. case 27:
  1684. if(globalActiveApp=='CalDavZAP' && $('#CAEvent').is(':visible') && $('#EventDisabler').is(':hidden'))
  1685. $('#closeButton').trigger('click');
  1686. if(globalActiveApp=='Projects' && $('#ProjectEventForm').is(':visible') && $('#ProjectsDisabler').is(':hidden'))
  1687. $('#cancelActivity').trigger('click');
  1688. if($('.sp-container').is(':visible'))
  1689. $('html').trigger('click');
  1690. break;
  1691. default:
  1692. break;
  1693. }
  1694. };
  1695. // called only once (after tha page is loaded)
  1696. function globalMainCardDAV()
  1697. {
  1698. $(window).resize(function(evt){
  1699. if(evt.target!=window)
  1700. return;
  1701. var columnLengths = [];
  1702. for(var i=0; i<getDataColumnCount(); i++) {
  1703. columnLengths.push([]);
  1704. }
  1705. globalRefABListTable.children('.ablist_item:visible').each(function() {
  1706. $(this).children().slice(globalFixedContactDataColumnsCount).each(function(ind) {
  1707. columnLengths[ind].push($(this).text().length);
  1708. });
  1709. });
  1710. setDataColumnsWidth(columnLengths);
  1711. $('.ablist_table_wrapper').css('max-height', $('#ABList').innerHeight() - $('.ablist_table_header').outerHeight() - 1);
  1712. checkContactFormScrollBar();
  1713. });
  1714. // set the initial height to get vertical scrollbars working (used also in $(window).resize(...))
  1715. $('.ablist_table_wrapper').css('max-height', $('#ABList').innerHeight() - $('.ablist_table_header').outerHeight() - 1);
  1716. // toggle CardDAV resources
  1717. $('#ResourceCardDAVToggle').click(function(){
  1718. var transSpeedResource=70;
  1719. var isResourceVisible=$('#ResourceCardDAVList').width()>1;
  1720. var col1=isResourceVisible? 0:224;
  1721. var col2=isResourceVisible? 0:225;
  1722. if(isIntegrated)
  1723. {
  1724. col2+=50;
  1725. }
  1726. $('.resourcesCardDAV_d, #ResourceCardDAVList, #ResourceCardDAVListOverlay').animate({width: col1}, transSpeedResource);
  1727. $('.collection_d, #SearchBox, #ABList, #ABListOverlay, #AddressbookOverlay').animate({left: col2}, transSpeedResource);
  1728. });
  1729. globalRefABList=$('#ABList');
  1730. globalRefABListTable=$('#ABListTableInner').find('tbody');
  1731. globalRefAddContact=$('#AddContact');
  1732. // these are restored after each logout
  1733. globalOrigCardDAVListTemplate=$('#ResourceCardDAVListTemplate').clone();
  1734. // clone + cleanup the editor (autocomplete bug in some browsers) + store the reference in globalOrigVcardTemplate
  1735. var tmp=$('#vCardTemplate').clone();
  1736. tmp.find('input[type="text"]').val('');
  1737. tmp.find('textarea').text('');
  1738. globalOrigVcardTemplate=tmp;
  1739. }
  1740. // called after the page is loaded and after each logout
  1741. function mainCardDAV()
  1742. {
  1743. globalCardDAVInitLoad=true;
  1744. // localize templates
  1745. // + store translated templates (globalTranl*)
  1746. // + initialize placeholder plugin
  1747. localizeCardDAV();
  1748. // cleanup the search field
  1749. $('[data-type="search"]').val('');
  1750. // Switch back to global Init (check for supported browser, demo login & password autofill
  1751. // then performs loadConfig() /netCheckAndCreateConfiguration() or netLoadConfiguration() or loadAllResources()/
  1752. // init();
  1753. }
  1754. // POZOR! login vola priamo loadConfig() ... nie je tym nahodou predxadzajuca funkcia zbytocna? ... overit!
  1755. // called from loadConfig() and netCheckAndCreateConfiguration() and netLoadConfiguration() and DAVresourceDelegation()
  1756. function runCardDAV()
  1757. {
  1758. if(!isUserLogged)
  1759. run();
  1760. // $('#SystemCardDavMATE').animate({opacity : 1},200,function(){
  1761. // /* XXX - System display:none changes
  1762. // $('#SystemCardDavMATE').css('display','block'); */
  1763. // $('#SystemCardDavMATE').css('visibility','visible');
  1764. // });
  1765. $('#MainLoader').css('left','0px');
  1766. $('#MainLoader').fadeIn(200);
  1767. initSearchCardDav();
  1768. }
  1769. function logoutCardDAV()
  1770. {
  1771. globalAddressbookList.reset();
  1772. globalResourceCardDAVList.reset();
  1773. globalAddressbookNumber=0;
  1774. globalAddressbookNumberCount=0;
  1775. globalCardDAVCollectionSync=false;
  1776. globalDefaultAddressbookCollectionActiveAll=false;
  1777. globalDefaultAddrCollectionLoadAll=false;
  1778. globalDisableAnimationMessageHiding='';
  1779. // reset ABList
  1780. globalRefABListTable.empty();
  1781. // remove ABList table gutter
  1782. $('.ablist_table_gutter').remove();
  1783. // clear old ABList table column widths
  1784. globalRefABListTableCols.width('');
  1785. globalRefABListInnerTableCols.width('');
  1786. // reset ABList table layout
  1787. globalRefAbListTableHeader.children().slice(globalFixedContactDataColumnsCount).remove();
  1788. globalRefABListTableCols.slice(globalFixedContactDataColumnsCount).remove();
  1789. globalRefABListInnerTableCols.slice(globalFixedContactDataColumnsCount).remove();
  1790. globalRefAbListTableHeader=null;
  1791. globalRefABListTableCols=null;
  1792. globalRefABListInnerTableCols=null;
  1793. // hide update notification
  1794. $('#SystemCardDavMATE').find('div.update_d').hide();
  1795. // if the editor is in "edit" state during the logout,
  1796. // we need to remove all overlays (for next login)
  1797. $('#ResourceCardDAVListOverlay, #ABListOverlay').fadeOut(2000);
  1798. $('#SystemCardDavMATE').animate({opacity : 0},200,function(){
  1799. /* XXX - System display:none changes
  1800. $('#SystemCardDavMATE').css('display','none');*/
  1801. $('#SystemCardDavMATE').css('visibility', 'hidden');
  1802. $('#ABContactColor').css('background-color', '');
  1803. if($('#ResourceCardDAVList').width()<1)
  1804. $('#ResourceCardDAVToggle').trigger('click');
  1805. });
  1806. }
  1807. function setAddressbookNumber()
  1808. {
  1809. for(var i=0; i<globalResourceCardDAVList.collections.length;i++)
  1810. if(globalResourceCardDAVList.collections[i].uid!=undefined && globalResourceCardDAVList.collections[i].makeLoaded)
  1811. globalAddressbookNumber++;
  1812. }