main.js 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993
  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. if(isAvaible('CardDavMATE'))
  1186. globalMainCardDAV();
  1187. if(isAvaible('CalDavZAP'))
  1188. globalMainCalDAV();
  1189. if(isAvaible('Projects'))
  1190. globalMainProjects();
  1191. if(isAvaible('Reports'))
  1192. globalMainReports();
  1193. if(isAvaible('Settings'))
  1194. globalMainSettings();
  1195. if(isAvaible('CardDavMATE'))
  1196. mainCardDAV();
  1197. if(isAvaible('CalDavZAP'))
  1198. mainCalDAV();
  1199. if(isAvaible('Projects'))
  1200. mainProjects();
  1201. if(isAvaible('Reports'))
  1202. mainReports();
  1203. if(isAvaible('Settings'))
  1204. mainSettings();
  1205. init();
  1206. }
  1207. function saveSettings(isFormSave)
  1208. {
  1209. if(globalSettings.islastdefaultactiveapp.value)
  1210. globalSettings.defaultactiveapp.value=globalActiveApp;
  1211. globalSettings.version.value=globalSettingsVersion;
  1212. var rex = new RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)');
  1213. if(isAvaible('CalDavZAP'))
  1214. {
  1215. globalSettings.activecalendarcollections.value.splice(0, globalSettings.activecalendarcollections.value.length);
  1216. globalSettings.activetodocollections.value.splice(0, globalSettings.activetodocollections.value.length);
  1217. globalSettings.todolistfilterselected.value.splice(0, globalSettings.todolistfilterselected.value.length);
  1218. for(var i=0;i<globalVisibleCalDAVCollections.length;i++)
  1219. {
  1220. var uidParts=globalVisibleCalDAVCollections[i].match(rex)
  1221. globalSettings.activecalendarcollections.value.splice(globalSettings.activecalendarcollections.value.length , 0, uidParts[1]+uidParts[3]);
  1222. }
  1223. for(var i=0;i<globalVisibleCalDAVTODOCollections.length;i++)
  1224. {
  1225. var uidParts=globalVisibleCalDAVTODOCollections[i].match(rex);
  1226. globalSettings.activetodocollections.value.splice(globalSettings.activetodocollections.value.length , 0, uidParts[1]+uidParts[3]);
  1227. }
  1228. if(globalSettings.islastactiveview.value)
  1229. {
  1230. var view= $('#calendar').fullCalendar('getView');
  1231. globalSettings.activeview.value=view.name;
  1232. }
  1233. if(globalSettings.islasttimezone.value)
  1234. globalSettings.timezone.value=globalSessionTimeZone;
  1235. var uidSelected=$('#ResourceCalDAVList').find('.resourceCalDAV_item_selected').attr('data-id');
  1236. if(uidSelected!=undefined && uidSelected!='')
  1237. {
  1238. var par=uidSelected.split('/');
  1239. globalSettings.calendarselected.value=par[par.length-3]+'/'+par[par.length-2]+'/';
  1240. }
  1241. uidSelected=$('#ResourceCalDAVTODOList').find('.resourceCalDAV_item_selected').attr('data-id');
  1242. if(uidSelected!=undefined && uidSelected!='')
  1243. {
  1244. var par=uidSelected.split('/');
  1245. globalSettings.todocalendarselected.value=par[par.length-3]+'/'+par[par.length-2]+'/';
  1246. }
  1247. var filterArray = $('.fc-filter-option-selected');
  1248. for(var i=0; i<filterArray.length; i++)
  1249. globalSettings.todolistfilterselected.value.splice(globalSettings.todolistfilterselected.value.length,0,$($('.fc-filter-option-selected')[i]).attr('data-type'));
  1250. }
  1251. if(isAvaible('CardDavMATE'))
  1252. {
  1253. globalSettings.activeaddressbookcollections.value.splice(0, globalSettings.activeaddressbookcollections.value.length);
  1254. var visAddrs = dataGetChecked('#ResourceCardDAVList');
  1255. for(var i=0;i<visAddrs.length;i++)
  1256. {
  1257. if(visAddrs[i]!='undefined')
  1258. {
  1259. var uidPart=visAddrs[i].match(RegExp('^(https?://)(.*)', 'i'))[1];
  1260. var uidPart2= visAddrs[i].match(RegExp('^(https?://)(.*)', 'i'))[2].split('@')[2];
  1261. globalSettings.activeaddressbookcollections.value.splice(globalSettings.activeaddressbookcollections.value.length , 0, uidPart+uidPart2);
  1262. }
  1263. }
  1264. if($('#ResourceCardDAVList').find('.group.resourceCardDAV_selected').length>0)
  1265. var uidASelected=$('#ResourceCardDAVList').find('.group.resourceCardDAV_selected').attr('data-id');
  1266. else if($('#ResourceCardDAVList').find('.resourceCardDAV_selected').length>0)
  1267. var uidASelected=$('#ResourceCardDAVList').find('.resourceCardDAV_selected').attr('data-id');
  1268. else
  1269. var uidASelected='';
  1270. if(uidASelected!=undefined && uidASelected!='')
  1271. globalSettings.addressbookselected.value=uidASelected;
  1272. }
  1273. if(isAvaible('Settings') && isFormSave)
  1274. return applyFormSettings();
  1275. else
  1276. return globalSettings;
  1277. }
  1278. function loadXMLSetings(settingsXML)
  1279. {
  1280. $(settingsXML).children().each(
  1281. function(ind,elm)
  1282. {
  1283. var type = $(elm).attr('type');
  1284. var locked = typeof $(elm).attr('locked')!='undefined'&&$(elm).attr('locked')!=null&&$(elm).attr('locked')=='true' ? true : false;
  1285. if(typeof globalSettings[$(elm).prop('tagName').toLowerCase()] == 'undefined')
  1286. return true;
  1287. if(locked)
  1288. globalSettings[$(elm).prop('tagName').toLowerCase()].locked=true;
  1289. if($(elm).children().length>0)
  1290. {
  1291. globalSettings[$(elm).prop('tagName').toLowerCase()].value = new Array();
  1292. $(elm).children().each(function(pind,pelm)
  1293. {
  1294. if($(elm).prop('tagName').toLowerCase() == 'urihandlerprofile')
  1295. {
  1296. globalSettings[$(elm).prop('tagName').toLowerCase()].value = {};
  1297. globalSettings[$(elm).prop('tagName').toLowerCase()].value[$(pelm).text().toLowerCase()] = $(pelm).attr('url');
  1298. }
  1299. else if($(elm).prop('tagName').toLowerCase() == 'addresscountryequivalence')
  1300. {
  1301. var eqObject = {};
  1302. eqObject['country'] = $(pelm).attr('name');
  1303. eqObject['regex'] = $(pelm).attr('regex');
  1304. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(eqObject);
  1305. }
  1306. else if($(elm).prop('tagName').toLowerCase() == 'compatibility')
  1307. {
  1308. globalSettings[$(elm).prop('tagName').toLowerCase()].value = {};
  1309. globalSettings[$(elm).prop('tagName').toLowerCase()].value[$(pelm).attr('name')] = new Array();
  1310. $(pelm).children().each(function(rind,relm)
  1311. {
  1312. globalSettings[$(elm).prop('tagName').toLowerCase()].value[$(pelm).attr('name')].push($(relm).text());
  1313. });
  1314. }
  1315. else if($(pelm).text()!='')
  1316. {
  1317. switch(type)
  1318. {
  1319. case 'integer':
  1320. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(parseInt($(pelm).text(),10));
  1321. break;
  1322. case 'string':
  1323. if($(pelm).text()!='null')
  1324. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push($(pelm).text());
  1325. else
  1326. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(null);
  1327. break;
  1328. case 'boolean':
  1329. if($(pelm).text() == 'true')
  1330. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(true);
  1331. else
  1332. globalSettings[$(elm).prop('tagName').toLowerCase()].value.push(false);
  1333. break;
  1334. default:
  1335. break;
  1336. }
  1337. }
  1338. });
  1339. }
  1340. else if($(elm).text()!='')
  1341. {
  1342. switch(type)
  1343. {
  1344. case 'integer':
  1345. globalSettings[$(elm).prop('tagName').toLowerCase()].value = parseInt($(elm).text(),10);
  1346. break;
  1347. case 'string':
  1348. if($(elm).text()!='null')
  1349. globalSettings[$(elm).prop('tagName').toLowerCase()].value = $(elm).text();
  1350. else
  1351. globalSettings[$(elm).prop('tagName').toLowerCase()].value = null;
  1352. break;
  1353. case 'boolean':
  1354. if($(elm).text() == 'true')
  1355. globalSettings[$(elm).prop('tagName').toLowerCase()].value = true;
  1356. else if($(elm).text() == 'false')
  1357. globalSettings[$(elm).prop('tagName').toLowerCase()].value = false;
  1358. break;
  1359. default:
  1360. break;
  1361. }
  1362. }
  1363. });
  1364. }
  1365. function applyServerSettings(inputSettings)
  1366. {
  1367. if(typeof inputSettings.activecalendarcollections == 'undefined' || inputSettings.activecalendarcollections==null)
  1368. inputSettings.activecalendarcollections = new Array();
  1369. if(typeof inputSettings.activetodocollections == 'undefined' || inputSettings.activetodocollections==null)
  1370. inputSettings.activetodocollections = new Array();
  1371. if(typeof inputSettings.loadedcalendarcollections == 'undefined' || inputSettings.loadedcalendarcollections==null)
  1372. {
  1373. inputSettings.loadedcalendarcollections = new Array();
  1374. if(isAvaible('CalDavZAP'))
  1375. $('#showUnloadedCalendars').css('display','none');
  1376. }
  1377. if(typeof inputSettings.loadedtodocollections == 'undefined' || inputSettings.loadedtodocollections==null)
  1378. {
  1379. inputSettings.loadedtodocollections = new Array();
  1380. if(isAvaible('CalDavZAP'))
  1381. $('#showUnloadedCalendarsTODO').css('display','none');
  1382. }
  1383. if(typeof inputSettings.activeaddressbookcollections == 'undefined' || inputSettings.activeaddressbookcollections==null)
  1384. inputSettings.activeaddressbookcollections = new Array();
  1385. if(typeof inputSettings.loadedaddressbookcollections == 'undefined' || inputSettings.loadedaddressbookcollections==null)
  1386. {
  1387. inputSettings.loadedaddressbookcollections = new Array();
  1388. if(isAvaible('CardDavMATE'))
  1389. $('#showUnloadedAddressbooks').css('display','none');
  1390. }
  1391. transformSettings(inputSettings);
  1392. for(var prop in inputSettings)
  1393. {
  1394. if(globalDefinedSettings.indexOf(prop)==-1 || (typeof globalPreviousSupportedSettings !='undefined' && globalPreviousSupportedSettings.indexOf(prop)==-1))
  1395. {
  1396. if(globalDefinedSettings.indexOf(prop)==-1)
  1397. console.log('Warning: Unsupported property: \''+prop+'\' (you can safely ignore this message)');
  1398. continue;
  1399. }
  1400. if(typeof globalSettings[prop] !='undefined' && !globalSettings[prop].locked)
  1401. globalSettings[prop].value=inputSettings[prop];
  1402. }
  1403. }
  1404. function transformSettings(settings) {
  1405. if(!settings.version) {
  1406. settings.version = 1;
  1407. }
  1408. while(settings.version<globalSettingsVersion) {
  1409. console.log('Warning: Detected outdated server settings (version ' + settings.version++ +') - transforming to version ' + settings.version);
  1410. switch(settings.version) {
  1411. case 2:
  1412. if(typeof globalActiveCalendarCollections!='undefined' && globalActiveCalendarCollections!=null)
  1413. settings.activecalendarcollections=globalActiveCalendarCollections.slice();
  1414. else
  1415. settings.activecalendarcollections.splice(0, settings.activecalendarcollections.length);
  1416. if(typeof globalActiveTodoCollections!='undefined' && globalActiveTodoCollections!=null)
  1417. settings.activetodocollections=globalActiveTodoCollections.slice();
  1418. else
  1419. settings.activetodocollections.splice(0, settings.activetodocollections.length);
  1420. if(typeof globalLoadedCalendarCollections!='undefined' && globalLoadedCalendarCollections!=null)
  1421. settings.loadedcalendarcollections=globalLoadedCalendarCollections.slice();
  1422. else
  1423. settings.loadedcalendarcollections.splice(0, settings.loadedcalendarcollections.length);
  1424. if(typeof globalLoadedTodoCollections!='undefined' && globalLoadedTodoCollections!=null)
  1425. settings.loadedtodocollections=globalLoadedTodoCollections.slice();
  1426. else
  1427. settings.loadedtodocollections.splice(0, settings.loadedtodocollections.length);
  1428. if(typeof globalActiveAddressbookCollections!='undefined' && globalActiveAddressbookCollections!=null)
  1429. settings.activeaddressbookcollections=globalActiveAddressbookCollections.slice();
  1430. else
  1431. settings.activeaddressbookcollections.splice(0, settings.activeaddressbookcollections.length);
  1432. if(typeof globalLoadedAddressbookCollections!='undefined' && globalLoadedAddressbookCollections!=null)
  1433. settings.loadedaddressbookcollections=globalLoadedAddressbookCollections.slice();
  1434. else
  1435. settings.loadedaddressbookcollections.splice(0, settings.loadedaddressbookcollections.length);
  1436. if(typeof globalContactStoreFN!='undefined' && globalContactStoreFN!=null)
  1437. settings.contactstorefn=globalContactStoreFN.slice();
  1438. else
  1439. settings.contactstorefn=['prefix', ' last', ' middle', ' first', ' suffix'];
  1440. break;
  1441. case 3:
  1442. settings.collectiondisplay=(typeof globalCollectionDisplay!='undefined' && globalCollectionDisplay!=null && globalCollectionDisplay!='') ? globalCollectionDisplay : (
  1443. (typeof globalGroupContactsByCompanies!='undefined' && globalGroupContactsByCompanies) ?
  1444. [{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}']}] :
  1445. [{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}']}]
  1446. );
  1447. settings.collectionsort=(typeof globalCollectionSort!='undefined' && globalCollectionSort!=null && globalCollectionSort!='') ? globalCollectionSort : '';
  1448. break;
  1449. default:
  1450. break;
  1451. }
  1452. }
  1453. }
  1454. function loadSettings(strobj, fromServer, syncMode)
  1455. {
  1456. if(settingsLoaded && !syncMode)
  1457. return false;
  1458. try
  1459. {
  1460. objNew = jQuery.parseJSON(strobj);
  1461. if(typeof objNew=='object')
  1462. {
  1463. if(!syncMode && typeof globalSettingsXML!='undefined' && globalSettingsXML!=null && globalSettingsXML!='')
  1464. loadXMLSetings($(globalSettingsXML));
  1465. if(fromServer)
  1466. applyServerSettings(objNew);
  1467. // $.extend(globalSettings,objNew);
  1468. }
  1469. }
  1470. catch(err)
  1471. {
  1472. console.log('load settings - JSON parsing error: '+err);
  1473. delete globalSettings.version.value;
  1474. loadSettings(JSON.stringify(globalSettings), false, false);
  1475. return false;
  1476. }
  1477. if(syncMode)
  1478. return false;
  1479. if(isAvaible('CalDavZAP'))
  1480. {
  1481. for(var i=0;i<globalSettings.timezonesenabled.value.length;i++)
  1482. if(timeZonesEnabled.indexOf(globalSettings.timezonesenabled.value[i])==-1)
  1483. timeZonesEnabled.push(globalSettings.timezonesenabled.value[i]);
  1484. if(globalSettings.timezonesupport.value)
  1485. {
  1486. globalSessionTimeZone=globalSettings.timezone.value;
  1487. if(globalSessionTimeZone != null && timeZonesEnabled.indexOf(globalSessionTimeZone)==-1)
  1488. timeZonesEnabled.push(globalSessionTimeZone);
  1489. }
  1490. else
  1491. {
  1492. globalSessionTimeZone = 'local';
  1493. timeZonesEnabled.push('local');
  1494. }
  1495. initTimepicker(globalSettings.ampmformat.value);
  1496. if(globalSettings.timeformatagenda.value==null)
  1497. {
  1498. if(globalSettings.ampmformat.value)
  1499. globalSettings.timeformatagenda.value='h:mm TT{ - h:mm TT}';
  1500. else
  1501. globalSettings.timeformatagenda.value='H:mm{ - H:mm}';
  1502. }
  1503. if(globalSettings.timeformatbasic.value==null)
  1504. {
  1505. if(globalSettings.ampmformat.value)
  1506. globalSettings.timeformatbasic.value = 'h:mmT{-h:mmT}';
  1507. else
  1508. globalSettings.timeformatbasic.value = 'H:mm{-H:mm}';
  1509. }
  1510. if(globalSettings.appleremindersmode.value)
  1511. {
  1512. if(globalSettings.todolistfilterselected.value.indexOf('filterAction')==-1 && globalSettings.todolistfilterselected.value.indexOf('filterCompleted')==-1)
  1513. {
  1514. if(globalSettings.todolistfilterselected.value.indexOf('filterProgress')!=-1)
  1515. globalSettings.todolistfilterselected.value[globalSettings.todolistfilterselected.value.indexOf('filterProgress')] = 'filterAction';
  1516. if(globalSettings.todolistfilterselected.value.indexOf('filterCanceled')!=-1)
  1517. globalSettings.todolistfilterselected.value[globalSettings.todolistfilterselected.value.indexOf('filterCanceled')] = 'filterAction';
  1518. }
  1519. }
  1520. if(globalSettings.eventstartfuturelimit.value == null)
  1521. {
  1522. var now=new Date();
  1523. globalToLoadedLimit = new Date(now.getFullYear(), now.getMonth()+12, 1, 0, 0, 0);
  1524. globalToLoadedLimit.setMilliseconds(0);
  1525. globalBeginFuture = new Date(globalToLoadedLimit.getTime());
  1526. globalBeginFuture.setDate(globalBeginFuture.getDate()+14);
  1527. globalToLoadedLimitTodo = new Date(now.getFullYear(), now.getMonth()+12, 1, 0, 0, 0);
  1528. globalToLoadedLimitTodo.setMilliseconds(0);
  1529. }
  1530. if(globalSettings.enablekbnavigation.value!==false)
  1531. initKbTodoNavigation();
  1532. initFullCalendar();
  1533. initTodoList();
  1534. $('#SystemCalDavZAP .fc-header-title').css('width', $('#main_h_placeholder').width()-$('#SystemCalDavZAP .fc-header-left').outerWidth()-$('#SystemCalDavZAP .fc-header-right').outerWidth());
  1535. $('#ResourceCalDAVList, #ResourceCalDAVTODOList').css('bottom',(globalSettings.timezonesupport.value ? 20 : 0));
  1536. $('#alertBox').css('left', ($(window).width()/2)-($('#alertBox').width()/2));
  1537. }
  1538. if(isAvaible('CardDavMATE'))
  1539. {
  1540. // set ABListTableLayout
  1541. globalRefAbListTableHeader = $('#ABListTable').find('.ablist_table_header');
  1542. var colgroups = $('#ABListTable').find('colgroup');
  1543. for(var i=0; i<getDataColumnCount(); i++) {
  1544. globalRefAbListTableHeader.append('<th>');
  1545. colgroups.append('<col>');
  1546. }
  1547. globalRefAbListTableHeader.children().slice(globalFixedContactDataColumnsCount).each(function(ind) {
  1548. $(this).text(getDataColumnLabelAtIndex(ind));
  1549. });
  1550. globalRefABListTableCols=$('#ABListTable').find('colgroup').first().children();
  1551. globalRefABListInnerTableCols=$('#ABListTableInner').find('colgroup').children();
  1552. $('#ABListTable').find('.ablist_table_container').children().attr('colspan', getDataColumnCount()+globalFixedContactDataColumnsCount);
  1553. globalRefABListTable.children('.ablist_header').children().attr('colspan', getDataColumnCount()+globalFixedContactDataColumnsCount);
  1554. if(!globalOrigABListHeader) {
  1555. globalOrigABListHeader=globalRefABListTable.children('.ablist_header').remove();
  1556. }
  1557. if(!globalOrigABListItem) {
  1558. globalOrigABListItem=globalRefABListTable.children('.ablist_item').remove();
  1559. }
  1560. if(globalSettings.enablekbnavigation.value!==false)
  1561. initKbAddrNavigation();
  1562. applyAddrSettings(globalTranslVcardTemplate);
  1563. applyAddrSettings($('#vCardEditor'));
  1564. }
  1565. if(isAvaible('Projects'))
  1566. if(globalSettings.enablekbnavigation.value!==false)
  1567. initKbProjectNavigation();
  1568. settingsLoaded=true;
  1569. if(!isAvaible(globalSettings.defaultactiveapp.value))
  1570. globalActiveApp = globalAvailableAppsArray[0];
  1571. else
  1572. globalActiveApp = globalSettings.defaultactiveapp.value;
  1573. }
  1574. function checkForLoadedCollections(inputSettings)
  1575. {
  1576. var val='', triggerSync=true;
  1577. globalLoadedCollectionsNumber=0;
  1578. globalLoadedCollectionsCount=0;
  1579. if(globalSettingsSaving=='event')
  1580. {
  1581. hideUnloadedCollections('event');
  1582. val = inputSettings.loadedcalendarcollections.value;
  1583. if(val.length>0)
  1584. globalLoadedCollectionsNumber+=$(val).not(globalSettings.loadedcalendarcollections.value).length;
  1585. else
  1586. globalLoadedCollectionsNumber++;
  1587. if($(globalSettings.loadedcalendarcollections.value).not(val).length>0)
  1588. {
  1589. if(globalLoadedCollectionsNumber==0)
  1590. {
  1591. triggerSync=false;
  1592. globalFirstHideLoader=false;
  1593. }
  1594. var unloadArray = $(globalSettings.loadedcalendarcollections.value).not(val);
  1595. unloadCalDAVCollection(unloadArray.toArray(),true);
  1596. }
  1597. if(triggerSync)
  1598. addLoadCalDAVCollection(val, true);
  1599. globalSettings.loadedcalendarcollections.value = val;
  1600. }
  1601. else if(globalSettingsSaving=='todo')
  1602. {
  1603. hideUnloadedCollections('todo');
  1604. val = inputSettings.loadedtodocollections.value;
  1605. if(val.length>0)
  1606. globalLoadedCollectionsNumber+=$(val).not(globalSettings.loadedtodocollections.value).length;
  1607. else
  1608. globalLoadedCollectionsNumber++;
  1609. if($(globalSettings.loadedtodocollections.value).not(val).length>0)
  1610. {
  1611. if(globalLoadedCollectionsNumber==0)
  1612. {
  1613. triggerSync=false;
  1614. globalFirstHideLoader=false;
  1615. }
  1616. var unloadArray = $(globalSettings.loadedtodocollections.value).not(val);
  1617. unloadCalDAVCollection(unloadArray.toArray(),false);
  1618. }
  1619. if(triggerSync)
  1620. addLoadCalDAVCollection(val, false);
  1621. globalSettings.loadedtodocollections.value = val;
  1622. }
  1623. else if(globalSettingsSaving=='addressbook')
  1624. {
  1625. hideUnloadedCardDAVCollections();
  1626. val = inputSettings.loadedaddressbookcollections.value;
  1627. if(val.length>0)
  1628. globalLoadedCollectionsNumber+=$(val).not(globalSettings.loadedaddressbookcollections.value).length;
  1629. else
  1630. globalLoadedCollectionsNumber++;
  1631. if($(globalSettings.loadedaddressbookcollections.value).not(val).length>0)
  1632. {
  1633. if(globalLoadedCollectionsNumber==0)
  1634. {
  1635. triggerSync=false;
  1636. globalFirstHideLoader=false;
  1637. }
  1638. var unloadArray = $(globalSettings.loadedaddressbookcollections.value).not(val);
  1639. unloadCardDAVCollection(unloadArray.toArray());
  1640. }
  1641. if(triggerSync)
  1642. addLoadCardDAVCollection(val)
  1643. globalSettings.loadedaddressbookcollections.value = val;
  1644. }
  1645. if(triggerSync)
  1646. ifLoadCollections();
  1647. }
  1648. function checkBeforeClose(isFormSave)
  1649. {
  1650. if((isAvaible('CalDavZAP') && globalCalDAVInitLoad) || (isAvaible('CardDavMATE') && globalCardDAVInitLoad))
  1651. return false;
  1652. var old_settings=JSON.stringify(globalSettings);
  1653. var settings=saveSettings(isFormSave);
  1654. var new_settings = JSON.stringify(settings);
  1655. if(old_settings == new_settings)
  1656. return false;
  1657. for(var i=0;i<globalAccountSettings.length;i++)
  1658. if(globalAccountSettings[i].href.indexOf(globalLoginUsername)!=-1 && globalAccountSettings[i].settingsAccount)
  1659. {
  1660. netSaveSettings(globalAccountSettings[i], settings, isFormSave,false);
  1661. break;
  1662. }
  1663. }
  1664. function isEachResourceLoaded()
  1665. {
  1666. var loaded = true;
  1667. for(var i=0; i< globalAccountSettings.length; i++)
  1668. if(typeof globalAccountSettings[i].errorLoaded!='undefined' && globalAccountSettings[i].errorLoaded!=null && globalAccountSettings[i].errorLoaded===true)
  1669. loaded=false;
  1670. return loaded;
  1671. }
  1672. window.onload=globalMain;
  1673. window.onkeydown=function(event)
  1674. {
  1675. switch(event.which) {
  1676. case 13:
  1677. if(!isUserLogged)
  1678. $('#Login').find('[data-type="system_login"]').trigger('click');
  1679. break;
  1680. case 27:
  1681. if(globalActiveApp=='CalDavZAP' && $('#CAEvent').is(':visible') && $('#EventDisabler').is(':hidden'))
  1682. $('#closeButton').trigger('click');
  1683. if(globalActiveApp=='Projects' && $('#ProjectEventForm').is(':visible') && $('#ProjectsDisabler').is(':hidden'))
  1684. $('#cancelActivity').trigger('click');
  1685. if($('.sp-container').is(':visible'))
  1686. $('html').trigger('click');
  1687. break;
  1688. default:
  1689. break;
  1690. }
  1691. };
  1692. // called only once (after tha page is loaded)
  1693. function globalMainCardDAV()
  1694. {
  1695. $(window).resize(function(evt){
  1696. if(evt.target!=window)
  1697. return;
  1698. var columnLengths = [];
  1699. for(var i=0; i<getDataColumnCount(); i++) {
  1700. columnLengths.push([]);
  1701. }
  1702. globalRefABListTable.children('.ablist_item:visible').each(function() {
  1703. $(this).children().slice(globalFixedContactDataColumnsCount).each(function(ind) {
  1704. columnLengths[ind].push($(this).text().length);
  1705. });
  1706. });
  1707. setDataColumnsWidth(columnLengths);
  1708. $('.ablist_table_wrapper').css('max-height', $('#ABList').innerHeight() - $('.ablist_table_header').outerHeight() - 1);
  1709. checkContactFormScrollBar();
  1710. });
  1711. // set the initial height to get vertical scrollbars working (used also in $(window).resize(...))
  1712. $('.ablist_table_wrapper').css('max-height', $('#ABList').innerHeight() - $('.ablist_table_header').outerHeight() - 1);
  1713. // toggle CardDAV resources
  1714. $('#ResourceCardDAVToggle').click(function(){
  1715. var transSpeedResource=70;
  1716. var isResourceVisible=$('#ResourceCardDAVList').width()>1;
  1717. var col1=isResourceVisible? 0:224;
  1718. var col2=isResourceVisible? 0:225;
  1719. if(isIntegrated)
  1720. {
  1721. col2+=50;
  1722. }
  1723. $('.resourcesCardDAV_d, #ResourceCardDAVList, #ResourceCardDAVListOverlay').animate({width: col1}, transSpeedResource);
  1724. $('.collection_d, #SearchBox, #ABList, #ABListOverlay, #AddressbookOverlay').animate({left: col2}, transSpeedResource);
  1725. });
  1726. globalRefABList=$('#ABList');
  1727. globalRefABListTable=$('#ABListTableInner').find('tbody');
  1728. globalRefAddContact=$('#AddContact');
  1729. // these are restored after each logout
  1730. globalOrigCardDAVListTemplate=$('#ResourceCardDAVListTemplate').clone();
  1731. // clone + cleanup the editor (autocomplete bug in some browsers) + store the reference in globalOrigVcardTemplate
  1732. var tmp=$('#vCardTemplate').clone();
  1733. tmp.find('input[type="text"]').val('');
  1734. tmp.find('textarea').text('');
  1735. globalOrigVcardTemplate=tmp;
  1736. }
  1737. // called after the page is loaded and after each logout
  1738. function mainCardDAV()
  1739. {
  1740. globalCardDAVInitLoad=true;
  1741. // localize templates
  1742. // + store translated templates (globalTranl*)
  1743. // + initialize placeholder plugin
  1744. localizeCardDAV();
  1745. // cleanup the search field
  1746. $('[data-type="search"]').val('');
  1747. // Switch back to global Init (check for supported browser, demo login & password autofill
  1748. // then performs loadConfig() /netCheckAndCreateConfiguration() or netLoadConfiguration() or loadAllResources()/
  1749. // init();
  1750. }
  1751. // POZOR! login vola priamo loadConfig() ... nie je tym nahodou predxadzajuca funkcia zbytocna? ... overit!
  1752. // called from loadConfig() and netCheckAndCreateConfiguration() and netLoadConfiguration() and DAVresourceDelegation()
  1753. function runCardDAV()
  1754. {
  1755. if(!isUserLogged)
  1756. run();
  1757. // $('#SystemCardDavMATE').animate({opacity : 1},200,function(){
  1758. // /* XXX - System display:none changes
  1759. // $('#SystemCardDavMATE').css('display','block'); */
  1760. // $('#SystemCardDavMATE').css('visibility','visible');
  1761. // });
  1762. $('#MainLoader').css('left','0px');
  1763. $('#MainLoader').fadeIn(200);
  1764. initSearchCardDav();
  1765. }
  1766. function logoutCardDAV()
  1767. {
  1768. globalAddressbookList.reset();
  1769. globalResourceCardDAVList.reset();
  1770. globalAddressbookNumber=0;
  1771. globalAddressbookNumberCount=0;
  1772. globalCardDAVCollectionSync=false;
  1773. globalDefaultAddressbookCollectionActiveAll=false;
  1774. globalDefaultAddrCollectionLoadAll=false;
  1775. globalDisableAnimationMessageHiding='';
  1776. // reset ABList
  1777. globalRefABListTable.empty();
  1778. // remove ABList table gutter
  1779. $('.ablist_table_gutter').remove();
  1780. // clear old ABList table column widths
  1781. globalRefABListTableCols.width('');
  1782. globalRefABListInnerTableCols.width('');
  1783. // reset ABList table layout
  1784. globalRefAbListTableHeader.children().slice(globalFixedContactDataColumnsCount).remove();
  1785. globalRefABListTableCols.slice(globalFixedContactDataColumnsCount).remove();
  1786. globalRefABListInnerTableCols.slice(globalFixedContactDataColumnsCount).remove();
  1787. globalRefAbListTableHeader=null;
  1788. globalRefABListTableCols=null;
  1789. globalRefABListInnerTableCols=null;
  1790. // hide update notification
  1791. $('#SystemCardDavMATE').find('div.update_d').hide();
  1792. // if the editor is in "edit" state during the logout,
  1793. // we need to remove all overlays (for next login)
  1794. $('#ResourceCardDAVListOverlay, #ABListOverlay').fadeOut(2000);
  1795. $('#SystemCardDavMATE').animate({opacity : 0},200,function(){
  1796. /* XXX - System display:none changes
  1797. $('#SystemCardDavMATE').css('display','none');*/
  1798. $('#SystemCardDavMATE').css('visibility', 'hidden');
  1799. $('#ABContactColor').css('background-color', '');
  1800. if($('#ResourceCardDAVList').width()<1)
  1801. $('#ResourceCardDAVToggle').trigger('click');
  1802. });
  1803. }
  1804. function setAddressbookNumber()
  1805. {
  1806. for(var i=0; i<globalResourceCardDAVList.collections.length;i++)
  1807. if(globalResourceCardDAVList.collections[i].uid!=undefined && globalResourceCardDAVList.collections[i].makeLoaded)
  1808. globalAddressbookNumber++;
  1809. }