Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

1122 wiersze
57 KiB

  1. /**
  2. * (c) by aheadware.com
  3. */
  4. var app = app || {};
  5. app.state = app.state || {};
  6. app.state.Home = function()
  7. {
  8. var state = app.core.StateManager.createState( 'home', { filter: null } );
  9. state.createPager = function( allAppointments, currentPage )
  10. {
  11. var pageSize = 250,
  12. cPage = currentPage || 1;
  13. return {
  14. pageElements : allAppointments.slice( ((cPage-1) * pageSize), (cPage * pageSize )),
  15. totalElements : allAppointments.length,
  16. pageSize : pageSize,
  17. currentPage : cPage,
  18. totalPages : Math.ceil( allAppointments.length / pageSize )
  19. };
  20. };
  21. state.getMemberByGroupAndProfileId = function( groupId, profileId )
  22. {
  23. let self = this,
  24. profile = null;
  25. if ( false === self.teamMembers.hasOwnProperty( groupId ) )
  26. {
  27. return profile;
  28. }
  29. for( let pi = 0; pi < self.teamMembers[ groupId ].length; pi++ )
  30. {
  31. if ( self.teamMembers[ groupId ][ pi ].getId() == profileId )
  32. {
  33. profile = self.teamMembers[ groupId][ pi ];
  34. break;
  35. }
  36. }
  37. return profile;
  38. };
  39. state.getMembersForAppointment = function( app, status )
  40. {
  41. let self = this,
  42. profileIds = [],
  43. appMembers = [],
  44. members = self.teamMembers.hasOwnProperty( app.getTeamId() ) ? self.teamMembers[ app.getTeamId() ] : [];
  45. switch( status )
  46. {
  47. case 'accepted':
  48. profileIds = app.getProfileIdsAccepted();
  49. break;
  50. case 'waiting':
  51. profileIds = app.getProfileIdsWaiting();
  52. break;
  53. case 'declined':
  54. profileIds = app.getProfileIdsDeclined();
  55. break;
  56. }
  57. for ( let pi = 0; pi < profileIds.length; pi++ )
  58. {
  59. for ( let mi = 0; mi < members.length; mi++ )
  60. {
  61. if ( profileIds[ pi ] == members[ mi ].getId() )
  62. {
  63. //list += members[ mi ].getName();
  64. appMembers.push( members[ mi ] );
  65. }
  66. }
  67. }
  68. return appMembers;
  69. };
  70. state.onSetAttendanceStatusResult = function( res )
  71. {
  72. if ( false === res.hasOwnProperty( 'err' ) )
  73. {
  74. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  75. renderAppointmentItem( new app.model.Appointment( res.appointment, res.attendee_data ) );
  76. }
  77. else
  78. {
  79. if ( res.err == 'max_reached' )
  80. {
  81. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().hide();
  82. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().show();
  83. app.core.View.confirm(
  84. _lc( 'MAX_REACHED_DO_YOU_WANT_ON_BE_ADDED_TO_THE_WAITLIST' ),
  85. function() {
  86. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  87. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  88. app.core.Rpc.call(
  89. 'Appointment',
  90. 'setAttendanceStatus',
  91. {
  92. appointmentId : appId,
  93. status : 'waiting'
  94. },
  95. function( res )
  96. {
  97. var newAppointment = new app.model.Appointment( res.appointment, res.attendee_data );
  98. app.core.View.toastWarning(
  99. _lc(
  100. 'SUCCESSFULLY_ADDED_TO_WAITING_LIST',
  101. [
  102. newAppointment.getWaitingPositionForProfileId( app.model.SessionUser.getUserProfile().getId() )
  103. ]
  104. )
  105. );
  106. renderAppointmentItem( newAppointment );
  107. }
  108. );
  109. },
  110. _lc( 'BTN_OK' ),
  111. );
  112. }
  113. else if ( "deadline_over" === res.err )
  114. {
  115. app.core.View.toastError( _lc( 'DEADLINE_IS_OVER' ) );
  116. renderAppointmentItem( getAppointment( appId ) );
  117. }
  118. else
  119. {
  120. app.core.View.toastError( _lc( 'GENERAL_SERVER_ERROR' ) );
  121. renderAppointmentItem( getAppointment( appId ) );
  122. }
  123. }
  124. };
  125. state.callSetAttendanceStatus = function( appId, status, profileChildId = null )
  126. {
  127. app.core.Rpc.call(
  128. 'Appointment',
  129. 'setAttendanceStatus',
  130. {
  131. appointmentId : appId,
  132. status : status,
  133. profileChildId : profileChildId
  134. },
  135. function( res )
  136. {
  137. if ( false === res.hasOwnProperty( 'err' ) )
  138. {
  139. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  140. renderAppointmentItem( new app.model.Appointment( res.appointment, res.attendee_data ) );
  141. }
  142. else
  143. {
  144. if ( res.err == 'max_reached' )
  145. {
  146. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().hide();
  147. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().show();
  148. app.core.View.confirm(
  149. _lc( 'MAX_REACHED_DO_YOU_WANT_ON_BE_ADDED_TO_THE_WAITLIST' ),
  150. function() {
  151. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  152. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  153. app.core.Rpc.call(
  154. 'Appointment',
  155. 'setAttendanceStatus',
  156. {
  157. appointmentId : appId,
  158. status : 'waiting'
  159. },
  160. function( res )
  161. {
  162. var newAppointment = new app.model.Appointment( res.appointment, res.attendee_data );
  163. app.core.View.toastWarning(
  164. _lc(
  165. 'SUCCESSFULLY_ADDED_TO_WAITING_LIST',
  166. [
  167. newAppointment.getWaitingPositionForProfileId( app.model.SessionUser.getUserProfile().getId() )
  168. ]
  169. )
  170. );
  171. renderAppointmentItem( newAppointment );
  172. }
  173. );
  174. },
  175. _lc( 'BTN_OK' ),
  176. );
  177. }
  178. else if ( "deadline_over" === res.err )
  179. {
  180. app.core.View.toastError( _lc( 'DEADLINE_IS_OVER' ) );
  181. renderAppointmentItem( getAppointment( appId ) );
  182. }
  183. else
  184. {
  185. app.core.View.toastError( _lc( 'GENERAL_SERVER_ERROR' ) );
  186. renderAppointmentItem( getAppointment( appId ) );
  187. }
  188. }
  189. },
  190. function( res )
  191. {
  192. renderAppointmentItem( getAppointment( appId ) );
  193. }
  194. );
  195. };
  196. state.onEnter = function( p )
  197. {
  198. var $content = app.core.View.getContent(),
  199. appointments = [],
  200. allowedCategoryIds = [],
  201. gcgIds,
  202. userGroups = [],
  203. self = this,
  204. filter = this.getStateSetting( 'filter' ),
  205. isBackButton = app.core.StateManager.isPreviousState(),
  206. scrollY = +this.getStateSetting( 'scrollY' ),
  207. groupsTermsNotAccepted = [],
  208. groupsNotActiveString = "";
  209. // For paging
  210. self.currentPage = 1;
  211. self.appointments = appointments;
  212. self.teamMembers = {};
  213. app.gui.PageLoader.show();
  214. app.core.Rpc.call(
  215. 'Profile',
  216. 'get',
  217. {
  218. includeTeamMembers : true
  219. },
  220. function( res )
  221. {
  222. app.model.SessionUser.updateUserData( res.profile, res.profile_teams );
  223. userGroups = app.model.SessionUser.getGroups();
  224. for ( var ui = 0; ui < userGroups.length; ui++ )
  225. {
  226. let group = userGroups[ ui ];
  227. let groupData = app.model.SessionUser.getUserProfile().getGroupData(group.getId());
  228. if (group.getTermsConditionsActive() && groupData.terms_accepted !== 1) {
  229. groupsTermsNotAccepted.push(group);
  230. }
  231. if (groupData.status !== 'active') {
  232. groupsNotActiveString += groupsNotActiveString === "" ? group.getName() : (" ," + group.getName());
  233. }
  234. gcgIds = userGroups[ ui ].getCourseCategories();
  235. for ( var gci = 0; gci < gcgIds.length; gci++ )
  236. {
  237. allowedCategoryIds.push( gcgIds[ gci ].id );
  238. }
  239. }
  240. if ( !filter || !filter.hasOwnProperty( 'version' ) )
  241. {
  242. filter = {
  243. version : app.core.App.getVersion(),
  244. previous : false,
  245. appointmentCategoryIds : allowedCategoryIds,
  246. disallowedCategoryIds : [],
  247. isModified : false
  248. };
  249. }
  250. else
  251. {
  252. filter.appointmentCategoryIds = $( allowedCategoryIds ).not( filter.disallowedCategoryIds ).get();
  253. }
  254. // Set value of isModified
  255. if ( filter.previous || filter.disallowedCategoryIds.length )
  256. {
  257. filter.isModified = true;
  258. }
  259. else
  260. {
  261. filter.isModified = false;
  262. }
  263. function callSetAttendanceStatus( appId, status, profileChildId = null)
  264. {
  265. app.core.Rpc.call(
  266. 'Appointment',
  267. 'setAttendanceStatus',
  268. {
  269. appointmentId : appId,
  270. status : status,
  271. profileChildId : profileChildId
  272. },
  273. function( res )
  274. {
  275. if ( false === res.hasOwnProperty( 'err' ) )
  276. {
  277. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  278. renderAppointmentItem( new app.model.Appointment( res.appointment, res.attendee_data ) );
  279. let profileContainer = profileChildId !== null ?
  280. $('[data-row-child-profile-id="' + profileChildId + '"]') :
  281. $('[data-row-parent="true"]');
  282. if (status === 'accepted') {
  283. profileContainer.find("section").hide();
  284. profileContainer.find('[data-type="section-rsvp-icon-accepted"]').show();
  285. } else {
  286. profileContainer.find("section").hide();
  287. profileContainer.find('[data-type="section-rsvp-icon-unchecked"]').show();
  288. }
  289. }
  290. else
  291. {
  292. if ( res.err == 'max_reached' )
  293. {
  294. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first();
  295. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().hide();
  296. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().show();
  297. app.core.View.confirm(
  298. _lc( 'MAX_REACHED_DO_YOU_WANT_ON_BE_ADDED_TO_THE_WAITLIST' ),
  299. function() {
  300. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  301. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  302. app.core.Rpc.call(
  303. 'Appointment',
  304. 'setAttendanceStatus',
  305. {
  306. appointmentId : appId,
  307. status : 'waiting',
  308. profileChildId : profileChildId
  309. },
  310. function( res )
  311. {
  312. var newAppointment = new app.model.Appointment( res.appointment, res.attendee_data );
  313. app.core.View.toastWarning(
  314. _lc(
  315. 'SUCCESSFULLY_ADDED_TO_WAITING_LIST',
  316. [
  317. newAppointment.getWaitingPositionForProfileId( app.model.SessionUser.getUserProfile().getId() )
  318. ]
  319. )
  320. );
  321. let profileContainer = profileChildId !== null ?
  322. $('[data-row-child-profile-id="' + profileChildId + '"]') :
  323. $('[data-row-parent="true"]');
  324. profileContainer.find("section").hide();
  325. profileContainer.find('[data-type="section-rsvp-icon-waiting"]').show();
  326. // if (status === 'accepted') {
  327. // profileContainer.find("section").hide();
  328. // profileContainer.find('[data-type="section-rsvp-icon-accepted"]').show();
  329. // } else {
  330. // profileContainer.find("section").hide();
  331. // profileContainer.find('[data-type="section-rsvp-icon-unchecked"]').show();
  332. // }
  333. renderAppointmentItem( newAppointment );
  334. }
  335. );
  336. },
  337. _lc( 'BTN_OK' ),
  338. );
  339. }
  340. else if ( "deadline_over" === res.err )
  341. {
  342. app.core.View.toastError( _lc( 'DEADLINE_IS_OVER' ) );
  343. renderAppointmentItem( getAppointment( appId ) );
  344. }
  345. else if ( "deadline_reject_over" === res.err )
  346. {
  347. app.core.View.toastError( 'Die Absagefrist ist verstrichen. Bitte nehme direkten Kontakt auf.' );
  348. renderAppointmentItem( getAppointment( appId ) );
  349. }
  350. else
  351. {
  352. app.core.View.toastError( _lc( 'GENERAL_SERVER_ERROR' ) );
  353. renderAppointmentItem( getAppointment( appId ) );
  354. }
  355. }
  356. },
  357. function( res )
  358. {
  359. renderAppointmentItem( getAppointment( appId ) );
  360. }
  361. );
  362. };
  363. function renderAppointmentItem( appointment )
  364. {
  365. updateAppointment( appointment );
  366. $content.find( '[data-type="appointment-item-container"][data-appointment-id="' + appointment.getId() + '"]' ).first().html(
  367. app.core.View.getTemplate( 'home-appointment-item', { a : appointment } )
  368. );
  369. }
  370. /**
  371. *
  372. * @param appointmentId
  373. * @returns {*}
  374. */
  375. function getAppointment( appointmentId )
  376. {
  377. var app = null;
  378. for ( var ai = 0; ai < appointments.length; ai++ )
  379. {
  380. if ( appointments[ ai ].getId() == appointmentId )
  381. {
  382. app = appointments[ ai ];
  383. break;
  384. }
  385. }
  386. return app;
  387. }
  388. /**
  389. *
  390. * @param appointment
  391. */
  392. function updateAppointment( appointment )
  393. {
  394. for ( var ai = 0; ai < appointments.length; ai++ )
  395. {
  396. if ( appointments[ ai ].getId() == appointment.getId() )
  397. {
  398. appointments[ ai ] = appointment;
  399. break;
  400. }
  401. }
  402. }
  403. // Note
  404. // This needs to be called once at the beginning to trigger correct handlers and body classes
  405. app.core.View.setContent( 'Loading...' );
  406. for ( let teamId in res.profile_team_members )
  407. {
  408. self.teamMembers[ teamId ] = [];
  409. for ( let tmi = 0; tmi < res.profile_team_members[ teamId ].length; tmi++ )
  410. {
  411. self.teamMembers[ teamId ].push( new app.model.Profile( res.profile_team_members[ teamId ][ tmi ] ) );
  412. }
  413. }
  414. app.core.Rpc.call(
  415. 'Appointment',
  416. 'getList',
  417. {
  418. filter: filter
  419. },
  420. function( res )
  421. {
  422. appointments = [];
  423. for ( var ai = 0 ; ai < res.appointments.length; ai++ )
  424. {
  425. appointments.push(
  426. new app.model.Appointment(
  427. res.appointments[ ai ],
  428. res[ 'attendees_' + res.appointments[ ai ].id ]
  429. )
  430. );
  431. }
  432. self.appointments = appointments;
  433. $content = app.core.View.getContent();
  434. $content.html(
  435. app.core.View.getTemplate(
  436. 'home',
  437. {
  438. appointments: appointments,
  439. filter : filter,
  440. groupsNotActiveString: groupsNotActiveString,
  441. }
  442. )
  443. );
  444. // Animate scroll to top
  445. $("html, body").animate({ scrollTop: 0 });
  446. $content.on('input', '[data-id="appointment-search-filter"]', function(e)
  447. {
  448. var searchTerm = $(this).val().toLowerCase();
  449. // Filter elements
  450. $('[data-type="appointment-item-container"]').each(function() {
  451. var $div = $(this);
  452. let appCat = $div.find('.appointment-category').text().toLowerCase();
  453. let appSub = $div.find('.appointment-subject').text().toLowerCase();
  454. let appDate = $div.find('.appointment-datetime').text().toLowerCase();
  455. if (appCat.includes(searchTerm) ||
  456. appSub.includes(searchTerm) ||
  457. appDate.includes(searchTerm) ||
  458. searchTerm === '') {
  459. $div.show();
  460. } else {
  461. $div.hide();
  462. }
  463. });
  464. });
  465. $content.on( 'click', '[data-type="appointment-short-info"]', function( e )
  466. {
  467. var $eTarget = $( e.target );
  468. if ( $eTarget.attr( 'data-type') === 'appointment-rsvp-container' ||
  469. $eTarget.parents( '[data-type="appointment-rsvp-container"]' ).length )
  470. {
  471. return true;
  472. }
  473. var appId = $(this).attr( 'data-appointment-id' );
  474. $content.find( '[data-type="appointment-detail-container"][data-appointment-id="' + appId + '"]' ).first().collapse( 'toggle' );
  475. });
  476. // start: News item action
  477. $content.on( 'click', '[data-type="news-item"]', function( e )
  478. {
  479. var newsId = $(this).attr( 'data-news-id' );
  480. $(this).find( '[data-type="news-collapse-icon"]' ).first().toggleClass( 'news-collapse-icon-rotate-down' );
  481. $content.find( '[data-type="news-item-detail-container"][data-news-id="' + newsId + '"]' ).first().collapse( 'toggle' );
  482. });
  483. // stop: News item action
  484. $content.on( 'click', '[data-type="btn-filter"]', function()
  485. {
  486. var p = {
  487. title : _lc( 'HEADER_APPOINTMENT_FILTER' ),
  488. body : app.core.View.getTemplate( 'home-modal-appointment-filter', { filter: filter, groups: app.model.SessionUser.getGroups() } ),
  489. onShow : function()
  490. {
  491. var $modal = app.core.View.getModalContent();
  492. },
  493. onConfirm : function()
  494. {
  495. var $modal = app.core.View.getModalContent(),
  496. newDisallowed = [];
  497. if ( $modal.find( '[data-id="filter-include-previous"]' ).first().is( ':checked') )
  498. {
  499. filter.previous = true;
  500. }
  501. else
  502. {
  503. filter.previous = false;
  504. }
  505. $modal.find( 'input[data-type="appointment-category"]:not(:checked )' ).each( function()
  506. {
  507. newDisallowed.push( $(this).val() );
  508. });
  509. filter.disallowedCategoryIds = newDisallowed;
  510. self.setStateSetting( 'filter', filter );
  511. app.core.Controller.reload();
  512. app.core.View.closeModal();
  513. }
  514. };
  515. app.core.View.showModal( p );
  516. });
  517. $content.on( 'click', '[data-type="rsvp-button-recall"]', function()
  518. {
  519. var $btn = $(this),
  520. appId = $btn.attr('data-appointment-id'),
  521. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first(),
  522. appointment = getAppointment(appId),
  523. profileStatus = appointment.getAttendeeStatusForProfileId( app.model.SessionUser.getUserProfile().getId() );
  524. if ( "accepted" !== profileStatus && "waiting" !== profileStatus )
  525. {
  526. return false;
  527. }
  528. app.core.View.confirm(
  529. _lc( 'REALLY_RECALL_ATTENDEE_STATUS' ),
  530. function()
  531. {
  532. $rsvpContainer.find( '[data-type="section-rsvp-icon-accepted"]' ).first().hide();
  533. $rsvpContainer.find( '[data-type="section-rsvp-icon-waiting"]' ).first().hide();
  534. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  535. app.core.Rpc.call(
  536. 'Appointment',
  537. 'setAttendanceStatus',
  538. {
  539. appointmentId : appId,
  540. status : "declined"
  541. },
  542. function( res )
  543. {
  544. if ( false === res.hasOwnProperty( 'err' ) )
  545. {
  546. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  547. renderAppointmentItem( new app.model.Appointment( res.appointment, res.attendee_data ) );
  548. }
  549. else if ( "deadline_over" === res.err )
  550. {
  551. app.core.View.toastError( _lc( 'DEADLINE_IS_OVER' ) );
  552. renderAppointmentItem( getAppointment( appId ) );
  553. }
  554. else if ( "deadline_reject_over" === res.err )
  555. {
  556. app.core.View.toastError( _lc( 'DEADLINE_REJECT_IS_OVER' ) );
  557. renderAppointmentItem( getAppointment( appId ) );
  558. }
  559. else if ( "appointment_is_cancelled" === res.err )
  560. {
  561. app.core.View.toastError( _lc( 'APPOINTMENT_IS_ALREADY_CANCELLED' ) );
  562. renderAppointmentItem( getAppointment( appId ) );
  563. }
  564. else if ( "appointment_not_accessible" === res.err )
  565. {
  566. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  567. setTimeout( function()
  568. {
  569. app.core.Controller.reload();
  570. }, 250 );
  571. }
  572. else
  573. {
  574. app.core.View.toastError( _lc( 'GENERAL_SERVER_ERROR' ) );
  575. renderAppointmentItem( getAppointment( appId ) );
  576. }
  577. }
  578. );
  579. }
  580. );
  581. });
  582. $content.on( 'click', '[data-type="rsvp-button-accept-multiple"], [data-type="rsvp-button-recall-multiple"]', function()
  583. {
  584. var $btn = $(this),
  585. appId = $btn.attr('data-appointment-id'),
  586. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first(),
  587. appointment = getAppointment(appId),
  588. profileStatus = appointment.getAttendeeStatusForProfileId( app.model.SessionUser.getUserProfile().getId() );
  589. $rsvpContainer.find( '[data-type="section-rsvp-icon-accepted"]' ).first().hide();
  590. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  591. $rsvpContainer.find( '[data-type="section-rsvp-icon-waiting"]' ).first().hide();
  592. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  593. app.core.View.showModal(
  594. {
  595. 'title' : appointment.getSubject() + ', am ' + appointment.getMomentStart().format( 'DD.MM.' ) + ' um ' + appointment.getMomentStart().format( 'HH:mm' ) + 'Uhr',
  596. 'body' : app.core.View.getTemplate( 'home-modal-appointment-subprofile', { a : appointment, currentProfile: app.model.SessionUser.getUserProfile() } ),
  597. 'cancelButtonText' : null,
  598. 'okButtonText' : 'Schließen',
  599. 'onShow' : function()
  600. {
  601. const $modalRoot = app.core.View.getModalContent();
  602. $modalRoot.on( 'click', '[data-type="rsvp-button-accept"]', function()
  603. {
  604. callSetAttendanceStatus( appId, "accepted", $(this).attr( 'data-child-profile-id' ) );
  605. //app.core.View.closeModal();
  606. //renderAppointmentItem( appointment );
  607. });
  608. $modalRoot.on( 'click', '[data-type="rsvp-button-recall"]', function()
  609. {
  610. callSetAttendanceStatus( appId, "declined", $(this).attr( 'data-child-profile-id' ) );
  611. //app.core.View.closeModal();
  612. //renderAppointmentItem( appointment );
  613. });
  614. },
  615. 'onHide' : function()
  616. {
  617. const $modalRoot = app.core.View.getModalContent();
  618. $modalRoot.off( 'click', '[data-type="rsvp-button-accept"]' );
  619. renderAppointmentItem( getAppointment(appId) );
  620. },
  621. 'onConfirm' : function()
  622. {
  623. app.core.View.closeModal();
  624. }
  625. }
  626. );
  627. });
  628. $content.on( 'click', '[data-type="rsvp-button-accept"]', function()
  629. {
  630. var $btn = $(this),
  631. appId = $btn.attr('data-appointment-id'),
  632. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first(),
  633. appointment = getAppointment(appId),
  634. profileStatus = appointment.getAttendeeStatusForProfileId( app.model.SessionUser.getUserProfile().getId() );
  635. if ( "accepted" === profileStatus )
  636. {
  637. return false;
  638. }
  639. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  640. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  641. callSetAttendanceStatus( appId, 'accepted', null );
  642. });
  643. $content.on( 'click', '[data-type="btn-appointment-edit"]', function()
  644. {
  645. var appToEdit = getAppointment( $(this).attr( 'data-appointment-id' ) );
  646. if ( appToEdit.isSerial() )
  647. {
  648. app.core.View.showModal({
  649. title : _lc( 'EDIT_SERIAL_APPOINTMENT' ),
  650. body : app.core.View.getTemplate( 'appointment-edit-modal-serial', { a : appToEdit } ),
  651. showOnlyCloseButton : true,
  652. onShow : function()
  653. {
  654. var $m = app.core.View.getModalContent();
  655. $m.find( '[data-id="btn-edit-single-appointment"]' ).first().click( function()
  656. {
  657. app.core.View.closeModal();
  658. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) )
  659. }
  660. );
  661. $m.find( '[data-id="btn-edit-serial-appointment"]' ).first().click( function()
  662. {
  663. app.core.View.closeModal();
  664. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) + '/serial' )
  665. }
  666. );
  667. }
  668. });
  669. }
  670. else
  671. {
  672. app.core.Controller.redirect( '#/appointment/edit/' + appToEdit.getId() );
  673. }
  674. }
  675. );
  676. $content.on( 'click', '[data-type="btn-appointment-edit-attendee"]', function()
  677. {
  678. var appToEdit = getAppointment( $(this).attr( 'data-appointment-id' ) );
  679. if ( appToEdit.isSerial() )
  680. {
  681. app.core.View.showModal({
  682. title : _lc( 'EDIT_SERIAL_APPOINTMENT' ),
  683. body : app.core.View.getTemplate( 'appointment-edit-modal-serial', { a : appToEdit } ),
  684. showOnlyCloseButton : true,
  685. onShow : function()
  686. {
  687. var $m = app.core.View.getModalContent();
  688. $m.find( '[data-id="btn-edit-single-appointment"]' ).first().click( function()
  689. {
  690. app.core.View.closeModal();
  691. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) + '/attendee' );
  692. }
  693. );
  694. $m.find( '[data-id="btn-edit-serial-appointment"]' ).first().click( function()
  695. {
  696. app.core.View.closeModal();
  697. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) + '/attendee/serial' );
  698. }
  699. );
  700. }
  701. });
  702. }
  703. else
  704. {
  705. app.core.Controller.redirect( '#/appointment/edit/' + appToEdit.getId() + '/attendee' );
  706. }
  707. });
  708. $content.on( 'click', '[data-type="btn-appoint-cancel"]', function()
  709. {
  710. var appointmentId = $(this).attr( 'data-appointment-id' );
  711. app.core.View.confirm(
  712. _lc( 'DO_YOU_REALLY_WANT_TO_CANCEL_APPOINTMENT' ),
  713. function()
  714. {
  715. app.core.Rpc.call(
  716. 'Appointment',
  717. 'cancel',
  718. {
  719. appointmentId : appointmentId
  720. },
  721. function( res )
  722. {
  723. app.core.View.toastSuccess( _lc( 'CANCEL_APPOINTMENT_SUCCESS' ) );
  724. app.core.Controller.reload();
  725. }
  726. );
  727. },
  728. _lc( 'BTN_CONFIRM_CANCEL_APPOINTMENT' )
  729. );
  730. });
  731. $content.on( 'click', '[data-type="btn-appoint-delete"]', function()
  732. {
  733. var appointmentId = $(this).attr( 'data-appointment-id' );
  734. var appToDelete = getAppointment( appointmentId );
  735. if ( appToDelete.isDraft() && appToDelete.isSerial() )
  736. {
  737. app.core.View.showModal({
  738. title : _lc( 'DELETE_SERIAL_APPOINTMENT' ),
  739. body : app.core.View.getTemplate( 'appointment-delete-modal-serial', { a : appToDelete } ),
  740. showOnlyCloseButton : true,
  741. onShow : function()
  742. {
  743. var $m = app.core.View.getModalContent();
  744. $m.find( '[data-id="btn-delete-single-appointment"]' ).first().click( function()
  745. {
  746. app.gui.PageLoader.show();
  747. app.core.View.closeModal();
  748. app.core.Rpc.call(
  749. 'Appointment',
  750. 'delete',
  751. {
  752. appointmentId : appToDelete.getId(),
  753. serialDeletion : false
  754. },
  755. function( res )
  756. {
  757. app.core.View.toastSuccess( _lc( 'DELETE_APPOINTMENT_SUCCESS' ) );
  758. setTimeout( function()
  759. {
  760. app.core.Controller.reload();
  761. }, 250 );
  762. }
  763. );
  764. }
  765. );
  766. $m.find( '[data-id="btn-delete-serial-appointment"]' ).first().click( function()
  767. {
  768. app.gui.PageLoader.show();
  769. app.core.View.closeModal();
  770. app.core.Rpc.call(
  771. 'Appointment',
  772. 'delete',
  773. {
  774. appointmentId : appToDelete.getId(),
  775. serialDeletion : true
  776. },
  777. function( res )
  778. {
  779. app.core.View.toastSuccess( _lc( 'DELETE_APPOINTMENT_SUCCESS' ) );
  780. setTimeout( function()
  781. {
  782. app.core.Controller.reload();
  783. }, 250 );
  784. }
  785. );
  786. }
  787. );
  788. }
  789. });
  790. }
  791. else
  792. {
  793. var warnTxt = '';
  794. if ( true === appToDelete.hasContractAttendances() )
  795. {
  796. warnTxt = '<br /><br /><div class="alert alert-danger"><strong>Achtung:</strong> ';
  797. warnTxt += 'Dieser Termin wurde mit mindestens einem Mitglieder-Vertrag verrechnet. ';
  798. warnTxt += 'Diese Zuweisung ginge bei verloren.';
  799. warnTxt += '</div>';
  800. }
  801. app.core.View.confirm(
  802. _lc( 'DO_YOU_REALLY_WANT_TO_DELETE_APPOINTMENT' ) + warnTxt,
  803. function()
  804. {
  805. app.gui.PageLoader.show();
  806. app.core.Rpc.call(
  807. 'Appointment',
  808. 'delete',
  809. {
  810. appointmentId : appToDelete.getId()
  811. },
  812. function( res )
  813. {
  814. app.core.View.toastSuccess( _lc( 'DELETE_APPOINTMENT_SUCCESS' ) );
  815. setTimeout( function()
  816. {
  817. app.core.Controller.reload();
  818. }, 250 );
  819. }
  820. );
  821. },
  822. _lc( 'BTN_CONFIRM_DELETE_APPOINTMENT' )
  823. );
  824. }
  825. });
  826. $content.on( 'click', '[data-type="btn-appoint-publish"]', function()
  827. {
  828. var appointmentId = $(this).attr('data-appointment-id'),
  829. appToPublish = getAppointment( appointmentId );
  830. if ( appToPublish.isDraft() && appToPublish.isSerial() )
  831. {
  832. app.core.View.showModal({
  833. title : _lc( 'PUBLISH_SERIAL_APPOINTMENT' ),
  834. body : app.core.View.getTemplate( 'appointment-publish-modal-serial', { a : appToPublish } ),
  835. showOnlyCloseButton : true,
  836. onShow : function()
  837. {
  838. var $m = app.core.View.getModalContent();
  839. $m.find( '[data-id="btn-publish-single-appointment"]' ).first().click( function()
  840. {
  841. app.gui.PageLoader.show();
  842. app.core.View.closeModal();
  843. app.core.Rpc.call(
  844. 'Appointment',
  845. 'publish',
  846. {
  847. appointmentId : appToPublish.getId(),
  848. serialPublishing : false
  849. },
  850. function( res )
  851. {
  852. app.core.View.toastSuccess( _lc( 'APPOINTMENT_SUCCESSFULLY_PUBLISHED' ) );
  853. setTimeout( function()
  854. {
  855. app.core.Controller.reload();
  856. }, 250 );
  857. }
  858. );
  859. }
  860. );
  861. $m.find( '[data-id="btn-publish-serial-appointment"]' ).first().click( function()
  862. {
  863. app.gui.PageLoader.show();
  864. app.core.View.closeModal();
  865. app.core.Rpc.call(
  866. 'Appointment',
  867. 'publish',
  868. {
  869. appointmentId : appToPublish.getId(),
  870. serialPublishing : true
  871. },
  872. function( res )
  873. {
  874. app.core.View.toastSuccess( _lc( 'APPOINTMENT_SUCCESSFULLY_PUBLISHED' ) );
  875. setTimeout( function()
  876. {
  877. app.core.Controller.reload();
  878. }, 250 );
  879. }
  880. );
  881. }
  882. );
  883. }
  884. });
  885. }
  886. else
  887. {
  888. app.core.View.confirm(
  889. _lc('DO_YOU_REALLY_WANT_TO_PUBLISH_APPOINTMENT'),
  890. function () {
  891. app.gui.PageLoader.show();
  892. app.core.Rpc.call(
  893. 'Appointment',
  894. 'publish',
  895. {
  896. appointmentId : appToPublish.getId()
  897. },
  898. function( res )
  899. {
  900. app.core.View.toastSuccess( _lc( 'APPOINTMENT_SUCCESSFULLY_PUBLISHED' ) );
  901. setTimeout( function()
  902. {
  903. app.core.Controller.reload();
  904. }, 250 );
  905. }
  906. );
  907. }
  908. );
  909. }
  910. });
  911. /*
  912. if ( flag === "new-group-created" )
  913. {
  914. setTimeout( function()
  915. {
  916. app.core.View.showModal({
  917. title : _lc( 'WELCOME_TO_PROBUDDY' ),
  918. body : app.core.View.getTemplate( 'home-modal-welcome-trainer' ),
  919. showOnlyCloseButton : true,
  920. cancelButtonText : _lc( 'CLOSE' )
  921. });
  922. }, 500 );
  923. }
  924. else if ( flag === "new-member" )
  925. {
  926. setTimeout( function()
  927. {
  928. app.core.View.showModal({
  929. title: _lc('WELCOME_TO_PROBUDDY'),
  930. body: app.core.View.getTemplate('home-modal-welcome-member'),
  931. showOnlyCloseButton: true,
  932. cancelButtonText: _lc('CLOSE')
  933. });
  934. }, 500 );
  935. }
  936. */
  937. if ( true === isBackButton )
  938. {
  939. setTimeout( function()
  940. {
  941. window.scrollTo( 0, scrollY);
  942. }, 500 );
  943. }
  944. app.gui.PageLoader.hide();
  945. }
  946. );
  947. let profile = app.model.SessionUser.getUserProfile();
  948. let groupId = null;
  949. let groupName = null;
  950. let status = null;
  951. let showPopup = false;
  952. let deleteStorageValues = true;
  953. let storageGroupIds = JSON.parse(sessionStorage.getItem("g_ids_popup_shown"));
  954. if (storageGroupIds === null) {
  955. storageGroupIds = [];
  956. }
  957. for (let i = 0; i < userGroups.length; i++) {
  958. groupId = userGroups[i].getId();
  959. status = profile.getGroupData(groupId).status;
  960. if (status === 'not_approved') {
  961. deleteStorageValues = false;
  962. if (!storageGroupIds.includes(groupId)) {
  963. groupName = userGroups[i].getName();
  964. showPopup = true;
  965. storageGroupIds.push(groupId);
  966. window.sessionStorage.setItem("g_ids_popup_shown", JSON.stringify(storageGroupIds));
  967. break;
  968. }
  969. }
  970. }
  971. if (deleteStorageValues) {
  972. sessionStorage.removeItem("g_ids_popup_shown");
  973. }
  974. if (showPopup) {
  975. app.core.View.showModal({
  976. title: _lc('HOME_MODAL_NOT_ACTIVATED_TITLE'),
  977. body: app.core.View.getTemplate('home-modal-not-activated', { groupName: groupName }),
  978. hideButtons: true,
  979. hideCloseBtn: true,
  980. cancelButtonText: _lc('HOME_MODAL_NOT_ACTIVATED_BUTTON')
  981. });
  982. $("body").on( 'click', '[data-id="not-activated"]', function(e)
  983. {
  984. e.preventDefault();
  985. app.core.View.closeModal();
  986. window.location.href = $(this).attr("href");
  987. });
  988. } else if (groupsTermsNotAccepted.length > 0) {
  989. // Show terms not accepted popup
  990. app.core.View.showModal({
  991. title: _lc('HOME_MODAL_TERMS_NOT_ACCEPTED_TITLE'),
  992. body: app.core.View.getTemplate('home-modal-terms-not-accepted', { groups: groupsTermsNotAccepted }),
  993. hideButtons: true,
  994. hideCloseBtn: true,
  995. prohibitCloseModal: true,
  996. });
  997. $("body").on( 'click', '[data-type="group-accept-link"]', function()
  998. {
  999. var groupId = $(this).data('group-id');
  1000. window.location.hash = "#/group/" + groupId + "/terms";
  1001. app.core.View.closeModal();
  1002. });
  1003. }
  1004. }
  1005. );
  1006. };
  1007. state.onExit = function( p )
  1008. {
  1009. this.setStateSetting( 'scrollY', window.scrollY );
  1010. };
  1011. return state;
  1012. };