No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

1104 líneas
56 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. // For paging
  208. self.currentPage = 1;
  209. self.appointments = appointments;
  210. self.teamMembers = {};
  211. app.gui.PageLoader.show();
  212. app.core.Rpc.call(
  213. 'Profile',
  214. 'get',
  215. {
  216. includeTeamMembers : true
  217. },
  218. function( res )
  219. {
  220. app.model.SessionUser.updateUserData( res.profile, res.profile_teams );
  221. userGroups = app.model.SessionUser.getGroups();
  222. for ( var ui = 0; ui < userGroups.length; ui++ )
  223. {
  224. gcgIds = userGroups[ ui ].getCourseCategories();
  225. for ( var gci = 0; gci < gcgIds.length; gci++ )
  226. {
  227. allowedCategoryIds.push( gcgIds[ gci ].id );
  228. }
  229. }
  230. if ( !filter || !filter.hasOwnProperty( 'version' ) )
  231. {
  232. filter = {
  233. version : app.core.App.getVersion(),
  234. previous : false,
  235. appointmentCategoryIds : allowedCategoryIds,
  236. disallowedCategoryIds : [],
  237. isModified : false
  238. };
  239. }
  240. else
  241. {
  242. filter.appointmentCategoryIds = $( allowedCategoryIds ).not( filter.disallowedCategoryIds ).get();
  243. }
  244. // Set value of isModified
  245. if ( filter.previous || filter.disallowedCategoryIds.length )
  246. {
  247. filter.isModified = true;
  248. }
  249. else
  250. {
  251. filter.isModified = false;
  252. }
  253. function callSetAttendanceStatus( appId, status, profileChildId = null)
  254. {
  255. app.core.Rpc.call(
  256. 'Appointment',
  257. 'setAttendanceStatus',
  258. {
  259. appointmentId : appId,
  260. status : status,
  261. profileChildId : profileChildId
  262. },
  263. function( res )
  264. {
  265. if ( false === res.hasOwnProperty( 'err' ) )
  266. {
  267. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  268. renderAppointmentItem( new app.model.Appointment( res.appointment, res.attendee_data ) );
  269. let profileContainer = profileChildId !== null ?
  270. $('[data-row-child-profile-id="' + profileChildId + '"]') :
  271. $('[data-row-parent="true"]');
  272. if (status === 'accepted') {
  273. profileContainer.find("section").hide();
  274. profileContainer.find('[data-type="section-rsvp-icon-accepted"]').show();
  275. } else {
  276. profileContainer.find("section").hide();
  277. profileContainer.find('[data-type="section-rsvp-icon-unchecked"]').show();
  278. }
  279. }
  280. else
  281. {
  282. if ( res.err == 'max_reached' )
  283. {
  284. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first();
  285. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().hide();
  286. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().show();
  287. app.core.View.confirm(
  288. _lc( 'MAX_REACHED_DO_YOU_WANT_ON_BE_ADDED_TO_THE_WAITLIST' ),
  289. function() {
  290. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  291. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  292. app.core.Rpc.call(
  293. 'Appointment',
  294. 'setAttendanceStatus',
  295. {
  296. appointmentId : appId,
  297. status : 'waiting',
  298. profileChildId : profileChildId
  299. },
  300. function( res )
  301. {
  302. var newAppointment = new app.model.Appointment( res.appointment, res.attendee_data );
  303. app.core.View.toastWarning(
  304. _lc(
  305. 'SUCCESSFULLY_ADDED_TO_WAITING_LIST',
  306. [
  307. newAppointment.getWaitingPositionForProfileId( app.model.SessionUser.getUserProfile().getId() )
  308. ]
  309. )
  310. );
  311. let profileContainer = profileChildId !== null ?
  312. $('[data-row-child-profile-id="' + profileChildId + '"]') :
  313. $('[data-row-parent="true"]');
  314. profileContainer.find("section").hide();
  315. profileContainer.find('[data-type="section-rsvp-icon-waiting"]').show();
  316. // if (status === 'accepted') {
  317. // profileContainer.find("section").hide();
  318. // profileContainer.find('[data-type="section-rsvp-icon-accepted"]').show();
  319. // } else {
  320. // profileContainer.find("section").hide();
  321. // profileContainer.find('[data-type="section-rsvp-icon-unchecked"]').show();
  322. // }
  323. renderAppointmentItem( newAppointment );
  324. }
  325. );
  326. },
  327. _lc( 'BTN_OK' ),
  328. );
  329. }
  330. else if ( "deadline_over" === res.err )
  331. {
  332. app.core.View.toastError( _lc( 'DEADLINE_IS_OVER' ) );
  333. renderAppointmentItem( getAppointment( appId ) );
  334. }
  335. else if ( "deadline_reject_over" === res.err )
  336. {
  337. app.core.View.toastError( 'Die Absagefrist ist verstrichen. Bitte nehme direkten Kontakt auf.' );
  338. renderAppointmentItem( getAppointment( appId ) );
  339. }
  340. else
  341. {
  342. app.core.View.toastError( _lc( 'GENERAL_SERVER_ERROR' ) );
  343. renderAppointmentItem( getAppointment( appId ) );
  344. }
  345. }
  346. },
  347. function( res )
  348. {
  349. renderAppointmentItem( getAppointment( appId ) );
  350. }
  351. );
  352. };
  353. function renderAppointmentItem( appointment )
  354. {
  355. updateAppointment( appointment );
  356. $content.find( '[data-type="appointment-item-container"][data-appointment-id="' + appointment.getId() + '"]' ).first().html(
  357. app.core.View.getTemplate( 'home-appointment-item', { a : appointment } )
  358. );
  359. }
  360. /**
  361. *
  362. * @param appointmentId
  363. * @returns {*}
  364. */
  365. function getAppointment( appointmentId )
  366. {
  367. var app = null;
  368. for ( var ai = 0; ai < appointments.length; ai++ )
  369. {
  370. if ( appointments[ ai ].getId() == appointmentId )
  371. {
  372. app = appointments[ ai ];
  373. break;
  374. }
  375. }
  376. return app;
  377. }
  378. /**
  379. *
  380. * @param appointment
  381. */
  382. function updateAppointment( appointment )
  383. {
  384. for ( var ai = 0; ai < appointments.length; ai++ )
  385. {
  386. if ( appointments[ ai ].getId() == appointment.getId() )
  387. {
  388. appointments[ ai ] = appointment;
  389. break;
  390. }
  391. }
  392. }
  393. /**
  394. * Render appointments according to pager setting
  395. * @param pageNo
  396. */
  397. function updatePaging( pageNo )
  398. {
  399. var pager = self.createPager(
  400. appointments,
  401. +pageNo
  402. ),
  403. $content = app.core.View.getContent();
  404. $content.html(
  405. app.core.View.getTemplate(
  406. 'home',
  407. {
  408. appointments : pager.pageElements,
  409. pager : pager,
  410. filter : filter
  411. }
  412. )
  413. );
  414. // Animate scroll to top
  415. $("html, body").animate({ scrollTop: 0 });
  416. }
  417. // Note
  418. // This needs to be called once at the beginning to trigger correct handlers and body classes
  419. app.core.View.setContent( 'Loading...' );
  420. for ( let teamId in res.profile_team_members )
  421. {
  422. self.teamMembers[ teamId ] = [];
  423. for ( let tmi = 0; tmi < res.profile_team_members[ teamId ].length; tmi++ )
  424. {
  425. self.teamMembers[ teamId ].push( new app.model.Profile( res.profile_team_members[ teamId ][ tmi ] ) );
  426. }
  427. }
  428. app.core.Rpc.call(
  429. 'Appointment',
  430. 'getList',
  431. {
  432. filter: filter
  433. },
  434. function( res )
  435. {
  436. appointments = [];
  437. for ( var ai = 0 ; ai < res.appointments.length; ai++ )
  438. {
  439. appointments.push(
  440. new app.model.Appointment(
  441. res.appointments[ ai ],
  442. res[ 'attendees_' + res.appointments[ ai ].id ]
  443. )
  444. );
  445. }
  446. self.appointments = appointments;
  447. updatePaging();
  448. $content.on( 'change', '[data-id="pager"]', function( e )
  449. {
  450. updatePaging( +$( this ).val() );
  451. });
  452. $content.on( 'click', '[data-type="appointment-short-info"]', function( e )
  453. {
  454. var $eTarget = $( e.target );
  455. if ( $eTarget.attr( 'data-type') === 'appointment-rsvp-container' ||
  456. $eTarget.parents( '[data-type="appointment-rsvp-container"]' ).length )
  457. {
  458. return true;
  459. }
  460. var appId = $(this).attr( 'data-appointment-id' );
  461. $content.find( '[data-type="appointment-detail-container"][data-appointment-id="' + appId + '"]' ).first().collapse( 'toggle' );
  462. });
  463. // start: News item action
  464. $content.on( 'click', '[data-type="news-item"]', function( e )
  465. {
  466. var newsId = $(this).attr( 'data-news-id' );
  467. $(this).find( '[data-type="news-collapse-icon"]' ).first().toggleClass( 'news-collapse-icon-rotate-down' );
  468. $content.find( '[data-type="news-item-detail-container"][data-news-id="' + newsId + '"]' ).first().collapse( 'toggle' );
  469. });
  470. // stop: News item action
  471. $content.on( 'click', '[data-type="btn-filter"]', function()
  472. {
  473. var p = {
  474. title : _lc( 'HEADER_APPOINTMENT_FILTER' ),
  475. body : app.core.View.getTemplate( 'home-modal-appointment-filter', { filter: filter, groups: app.model.SessionUser.getGroups() } ),
  476. onShow : function()
  477. {
  478. var $modal = app.core.View.getModalContent();
  479. },
  480. onConfirm : function()
  481. {
  482. var $modal = app.core.View.getModalContent(),
  483. newDisallowed = [];
  484. if ( $modal.find( '[data-id="filter-include-previous"]' ).first().is( ':checked') )
  485. {
  486. filter.previous = true;
  487. }
  488. else
  489. {
  490. filter.previous = false;
  491. }
  492. $modal.find( 'input[data-type="appointment-category"]:not(:checked )' ).each( function()
  493. {
  494. newDisallowed.push( $(this).val() );
  495. });
  496. filter.disallowedCategoryIds = newDisallowed;
  497. self.setStateSetting( 'filter', filter );
  498. app.core.Controller.reload();
  499. app.core.View.closeModal();
  500. }
  501. };
  502. app.core.View.showModal( p );
  503. });
  504. $content.on( 'click', '[data-type="rsvp-button-recall"]', function()
  505. {
  506. var $btn = $(this),
  507. appId = $btn.attr('data-appointment-id'),
  508. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first(),
  509. appointment = getAppointment(appId),
  510. profileStatus = appointment.getAttendeeStatusForProfileId( app.model.SessionUser.getUserProfile().getId() );
  511. if ( "accepted" !== profileStatus && "waiting" !== profileStatus )
  512. {
  513. return false;
  514. }
  515. app.core.View.confirm(
  516. _lc( 'REALLY_RECALL_ATTENDEE_STATUS' ),
  517. function()
  518. {
  519. $rsvpContainer.find( '[data-type="section-rsvp-icon-accepted"]' ).first().hide();
  520. $rsvpContainer.find( '[data-type="section-rsvp-icon-waiting"]' ).first().hide();
  521. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  522. app.core.Rpc.call(
  523. 'Appointment',
  524. 'setAttendanceStatus',
  525. {
  526. appointmentId : appId,
  527. status : "declined"
  528. },
  529. function( res )
  530. {
  531. if ( false === res.hasOwnProperty( 'err' ) )
  532. {
  533. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  534. renderAppointmentItem( new app.model.Appointment( res.appointment, res.attendee_data ) );
  535. }
  536. else if ( "deadline_over" === res.err )
  537. {
  538. app.core.View.toastError( _lc( 'DEADLINE_IS_OVER' ) );
  539. renderAppointmentItem( getAppointment( appId ) );
  540. }
  541. else if ( "deadline_reject_over" === res.err )
  542. {
  543. app.core.View.toastError( _lc( 'DEADLINE_REJECT_IS_OVER' ) );
  544. renderAppointmentItem( getAppointment( appId ) );
  545. }
  546. else if ( "appointment_is_cancelled" === res.err )
  547. {
  548. app.core.View.toastError( _lc( 'APPOINTMENT_IS_ALREADY_CANCELLED' ) );
  549. renderAppointmentItem( getAppointment( appId ) );
  550. }
  551. else if ( "appointment_not_accessible" === res.err )
  552. {
  553. app.core.View.toastSuccess( _lc( 'SAVED' ) );
  554. setTimeout( function()
  555. {
  556. app.core.Controller.reload();
  557. }, 250 );
  558. }
  559. else
  560. {
  561. app.core.View.toastError( _lc( 'GENERAL_SERVER_ERROR' ) );
  562. renderAppointmentItem( getAppointment( appId ) );
  563. }
  564. }
  565. );
  566. }
  567. );
  568. });
  569. $content.on( 'click', '[data-type="rsvp-button-accept-multiple"], [data-type="rsvp-button-recall-multiple"]', function()
  570. {
  571. var $btn = $(this),
  572. appId = $btn.attr('data-appointment-id'),
  573. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first(),
  574. appointment = getAppointment(appId),
  575. profileStatus = appointment.getAttendeeStatusForProfileId( app.model.SessionUser.getUserProfile().getId() );
  576. $rsvpContainer.find( '[data-type="section-rsvp-icon-accepted"]' ).first().hide();
  577. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  578. $rsvpContainer.find( '[data-type="section-rsvp-icon-waiting"]' ).first().hide();
  579. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  580. app.core.View.showModal(
  581. {
  582. 'title' : appointment.getSubject() + ', am ' + appointment.getMomentStart().format( 'DD.MM.' ) + ' um ' + appointment.getMomentStart().format( 'HH:mm' ) + 'Uhr',
  583. 'body' : app.core.View.getTemplate( 'home-modal-appointment-subprofile', { a : appointment, currentProfile: app.model.SessionUser.getUserProfile() } ),
  584. 'cancelButtonText' : null,
  585. 'okButtonText' : 'Schließen',
  586. 'onShow' : function()
  587. {
  588. const $modalRoot = app.core.View.getModalContent();
  589. $modalRoot.on( 'click', '[data-type="rsvp-button-accept"]', function()
  590. {
  591. callSetAttendanceStatus( appId, "accepted", $(this).attr( 'data-child-profile-id' ) );
  592. console.log('accept');
  593. //app.core.View.closeModal();
  594. //renderAppointmentItem( appointment );
  595. });
  596. $modalRoot.on( 'click', '[data-type="rsvp-button-recall"]', function()
  597. {
  598. callSetAttendanceStatus( appId, "declined", $(this).attr( 'data-child-profile-id' ) );
  599. console.log('decline');
  600. //app.core.View.closeModal();
  601. //renderAppointmentItem( appointment );
  602. });
  603. },
  604. 'onHide' : function()
  605. {
  606. const $modalRoot = app.core.View.getModalContent();
  607. $modalRoot.off( 'click', '[data-type="rsvp-button-accept"]' );
  608. console.log('onHide - 685');
  609. renderAppointmentItem( getAppointment(appId) );
  610. },
  611. 'onConfirm' : function()
  612. {
  613. app.core.View.closeModal();
  614. console.log('onConfirm - 690');
  615. }
  616. }
  617. );
  618. });
  619. $content.on( 'click', '[data-type="rsvp-button-accept"]', function()
  620. {
  621. var $btn = $(this),
  622. appId = $btn.attr('data-appointment-id'),
  623. $rsvpContainer = $content.find( '[data-type="appointment-rsvp-container"][data-appointment-id="' + appId + '"]' ).first(),
  624. appointment = getAppointment(appId),
  625. profileStatus = appointment.getAttendeeStatusForProfileId( app.model.SessionUser.getUserProfile().getId() );
  626. if ( "accepted" === profileStatus )
  627. {
  628. return false;
  629. }
  630. $rsvpContainer.find( '[data-type="section-rsvp-icon-unchecked"]' ).first().hide();
  631. $rsvpContainer.find( '[data-type="section-rsvp-icon-loading"]' ).first().show();
  632. callSetAttendanceStatus( appId, 'accepted', null );
  633. });
  634. $content.on( 'click', '[data-type="btn-appointment-edit"]', function()
  635. {
  636. var appToEdit = getAppointment( $(this).attr( 'data-appointment-id' ) );
  637. if ( appToEdit.isSerial() )
  638. {
  639. app.core.View.showModal({
  640. title : _lc( 'EDIT_SERIAL_APPOINTMENT' ),
  641. body : app.core.View.getTemplate( 'appointment-edit-modal-serial', { a : appToEdit } ),
  642. showOnlyCloseButton : true,
  643. onShow : function()
  644. {
  645. var $m = app.core.View.getModalContent();
  646. $m.find( '[data-id="btn-edit-single-appointment"]' ).first().click( function()
  647. {
  648. app.core.View.closeModal();
  649. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) )
  650. }
  651. );
  652. $m.find( '[data-id="btn-edit-serial-appointment"]' ).first().click( function()
  653. {
  654. app.core.View.closeModal();
  655. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) + '/serial' )
  656. }
  657. );
  658. }
  659. });
  660. }
  661. else
  662. {
  663. app.core.Controller.redirect( '#/appointment/edit/' + appToEdit.getId() );
  664. }
  665. }
  666. );
  667. $content.on( 'click', '[data-type="btn-appointment-edit-attendee"]', function()
  668. {
  669. var appToEdit = getAppointment( $(this).attr( 'data-appointment-id' ) );
  670. if ( appToEdit.isSerial() )
  671. {
  672. app.core.View.showModal({
  673. title : _lc( 'EDIT_SERIAL_APPOINTMENT' ),
  674. body : app.core.View.getTemplate( 'appointment-edit-modal-serial', { a : appToEdit } ),
  675. showOnlyCloseButton : true,
  676. onShow : function()
  677. {
  678. var $m = app.core.View.getModalContent();
  679. $m.find( '[data-id="btn-edit-single-appointment"]' ).first().click( function()
  680. {
  681. app.core.View.closeModal();
  682. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) + '/attendee' );
  683. }
  684. );
  685. $m.find( '[data-id="btn-edit-serial-appointment"]' ).first().click( function()
  686. {
  687. app.core.View.closeModal();
  688. app.core.Controller.redirect( '/#/appointment/edit/' + $(this).attr( 'data-appointment-id' ) + '/attendee/serial' );
  689. }
  690. );
  691. }
  692. });
  693. }
  694. else
  695. {
  696. app.core.Controller.redirect( '#/appointment/edit/' + appToEdit.getId() + '/attendee' );
  697. }
  698. });
  699. $content.on( 'click', '[data-type="btn-appoint-cancel"]', function()
  700. {
  701. var appointmentId = $(this).attr( 'data-appointment-id' );
  702. app.core.View.confirm(
  703. _lc( 'DO_YOU_REALLY_WANT_TO_CANCEL_APPOINTMENT' ),
  704. function()
  705. {
  706. app.core.Rpc.call(
  707. 'Appointment',
  708. 'cancel',
  709. {
  710. appointmentId : appointmentId
  711. },
  712. function( res )
  713. {
  714. app.core.View.toastSuccess( _lc( 'CANCEL_APPOINTMENT_SUCCESS' ) );
  715. app.core.Controller.reload();
  716. }
  717. );
  718. },
  719. _lc( 'BTN_CONFIRM_CANCEL_APPOINTMENT' )
  720. );
  721. });
  722. $content.on( 'click', '[data-type="btn-appoint-delete"]', function()
  723. {
  724. var appointmentId = $(this).attr( 'data-appointment-id' );
  725. var appToDelete = getAppointment( appointmentId );
  726. if ( appToDelete.isDraft() && appToDelete.isSerial() )
  727. {
  728. app.core.View.showModal({
  729. title : _lc( 'DELETE_SERIAL_APPOINTMENT' ),
  730. body : app.core.View.getTemplate( 'appointment-delete-modal-serial', { a : appToDelete } ),
  731. showOnlyCloseButton : true,
  732. onShow : function()
  733. {
  734. var $m = app.core.View.getModalContent();
  735. $m.find( '[data-id="btn-delete-single-appointment"]' ).first().click( function()
  736. {
  737. app.gui.PageLoader.show();
  738. app.core.View.closeModal();
  739. app.core.Rpc.call(
  740. 'Appointment',
  741. 'delete',
  742. {
  743. appointmentId : appToDelete.getId(),
  744. serialDeletion : false
  745. },
  746. function( res )
  747. {
  748. app.core.View.toastSuccess( _lc( 'DELETE_APPOINTMENT_SUCCESS' ) );
  749. setTimeout( function()
  750. {
  751. app.core.Controller.reload();
  752. }, 250 );
  753. }
  754. );
  755. }
  756. );
  757. $m.find( '[data-id="btn-delete-serial-appointment"]' ).first().click( function()
  758. {
  759. app.gui.PageLoader.show();
  760. app.core.View.closeModal();
  761. app.core.Rpc.call(
  762. 'Appointment',
  763. 'delete',
  764. {
  765. appointmentId : appToDelete.getId(),
  766. serialDeletion : true
  767. },
  768. function( res )
  769. {
  770. app.core.View.toastSuccess( _lc( 'DELETE_APPOINTMENT_SUCCESS' ) );
  771. setTimeout( function()
  772. {
  773. app.core.Controller.reload();
  774. }, 250 );
  775. }
  776. );
  777. }
  778. );
  779. }
  780. });
  781. }
  782. else
  783. {
  784. var warnTxt = '';
  785. if ( true === appToDelete.hasContractAttendances() )
  786. {
  787. warnTxt = '<br /><br /><div class="alert alert-danger"><strong>Achtung:</strong> ';
  788. warnTxt += 'Dieser Termin wurde mit mindestens einem Mitglieder-Vertrag verrechnet. ';
  789. warnTxt += 'Diese Zuweisung ginge bei verloren.';
  790. warnTxt += '</div>';
  791. }
  792. app.core.View.confirm(
  793. _lc( 'DO_YOU_REALLY_WANT_TO_DELETE_APPOINTMENT' ) + warnTxt,
  794. function()
  795. {
  796. app.gui.PageLoader.show();
  797. app.core.Rpc.call(
  798. 'Appointment',
  799. 'delete',
  800. {
  801. appointmentId : appToDelete.getId()
  802. },
  803. function( res )
  804. {
  805. app.core.View.toastSuccess( _lc( 'DELETE_APPOINTMENT_SUCCESS' ) );
  806. setTimeout( function()
  807. {
  808. app.core.Controller.reload();
  809. }, 250 );
  810. }
  811. );
  812. },
  813. _lc( 'BTN_CONFIRM_DELETE_APPOINTMENT' )
  814. );
  815. }
  816. });
  817. $content.on( 'click', '[data-type="btn-appoint-publish"]', function()
  818. {
  819. var appointmentId = $(this).attr('data-appointment-id'),
  820. appToPublish = getAppointment( appointmentId );
  821. if ( appToPublish.isDraft() && appToPublish.isSerial() )
  822. {
  823. app.core.View.showModal({
  824. title : _lc( 'PUBLISH_SERIAL_APPOINTMENT' ),
  825. body : app.core.View.getTemplate( 'appointment-publish-modal-serial', { a : appToPublish } ),
  826. showOnlyCloseButton : true,
  827. onShow : function()
  828. {
  829. var $m = app.core.View.getModalContent();
  830. $m.find( '[data-id="btn-publish-single-appointment"]' ).first().click( function()
  831. {
  832. app.gui.PageLoader.show();
  833. app.core.View.closeModal();
  834. app.core.Rpc.call(
  835. 'Appointment',
  836. 'publish',
  837. {
  838. appointmentId : appToPublish.getId(),
  839. serialPublishing : false
  840. },
  841. function( res )
  842. {
  843. app.core.View.toastSuccess( _lc( 'APPOINTMENT_SUCCESSFULLY_PUBLISHED' ) );
  844. setTimeout( function()
  845. {
  846. app.core.Controller.reload();
  847. }, 250 );
  848. }
  849. );
  850. }
  851. );
  852. $m.find( '[data-id="btn-publish-serial-appointment"]' ).first().click( function()
  853. {
  854. app.gui.PageLoader.show();
  855. app.core.View.closeModal();
  856. app.core.Rpc.call(
  857. 'Appointment',
  858. 'publish',
  859. {
  860. appointmentId : appToPublish.getId(),
  861. serialPublishing : true
  862. },
  863. function( res )
  864. {
  865. app.core.View.toastSuccess( _lc( 'APPOINTMENT_SUCCESSFULLY_PUBLISHED' ) );
  866. setTimeout( function()
  867. {
  868. app.core.Controller.reload();
  869. }, 250 );
  870. }
  871. );
  872. }
  873. );
  874. }
  875. });
  876. }
  877. else
  878. {
  879. app.core.View.confirm(
  880. _lc('DO_YOU_REALLY_WANT_TO_PUBLISH_APPOINTMENT'),
  881. function () {
  882. app.gui.PageLoader.show();
  883. app.core.Rpc.call(
  884. 'Appointment',
  885. 'publish',
  886. {
  887. appointmentId : appToPublish.getId()
  888. },
  889. function( res )
  890. {
  891. app.core.View.toastSuccess( _lc( 'APPOINTMENT_SUCCESSFULLY_PUBLISHED' ) );
  892. setTimeout( function()
  893. {
  894. app.core.Controller.reload();
  895. }, 250 );
  896. }
  897. );
  898. }
  899. );
  900. }
  901. });
  902. /*
  903. if ( flag === "new-group-created" )
  904. {
  905. setTimeout( function()
  906. {
  907. app.core.View.showModal({
  908. title : _lc( 'WELCOME_TO_PROBUDDY' ),
  909. body : app.core.View.getTemplate( 'home-modal-welcome-trainer' ),
  910. showOnlyCloseButton : true,
  911. cancelButtonText : _lc( 'CLOSE' )
  912. });
  913. }, 500 );
  914. }
  915. else if ( flag === "new-member" )
  916. {
  917. setTimeout( function()
  918. {
  919. app.core.View.showModal({
  920. title: _lc('WELCOME_TO_PROBUDDY'),
  921. body: app.core.View.getTemplate('home-modal-welcome-member'),
  922. showOnlyCloseButton: true,
  923. cancelButtonText: _lc('CLOSE')
  924. });
  925. }, 500 );
  926. }
  927. */
  928. if ( true === isBackButton )
  929. {
  930. setTimeout( function()
  931. {
  932. window.scrollTo( 0, scrollY);
  933. }, 500 );
  934. }
  935. app.gui.PageLoader.hide();
  936. }
  937. );
  938. let profile = app.model.SessionUser.getUserProfile();
  939. let groupId = null;
  940. let groupName = null;
  941. let status = null;
  942. let showPopup = false;
  943. let deleteStorageValues = true;
  944. let storageGroupIds = JSON.parse(sessionStorage.getItem("g_ids_popup_shown"));
  945. if (storageGroupIds === null) {
  946. storageGroupIds = [];
  947. }
  948. for (let i = 0; i < userGroups.length; i++) {
  949. groupId = userGroups[i].getId();
  950. status = profile.getGroupData(groupId).status;
  951. if (status === 'not_approved') {
  952. deleteStorageValues = false;
  953. if (!storageGroupIds.includes(groupId)) {
  954. groupName = userGroups[i].getName();
  955. showPopup = true;
  956. storageGroupIds.push(groupId);
  957. window.sessionStorage.setItem("g_ids_popup_shown", JSON.stringify(storageGroupIds));
  958. break;
  959. }
  960. }
  961. }
  962. if (deleteStorageValues) {
  963. sessionStorage.removeItem("g_ids_popup_shown");
  964. }
  965. if (showPopup) {
  966. app.core.View.showModal({
  967. title: _lc('HOME_MODAL_NOT_ACTIVATED_TITLE'),
  968. body: app.core.View.getTemplate('home-modal-not-activated', { groupName: groupName }),
  969. hideButtons: true,
  970. hideCloseBtn: true,
  971. cancelButtonText: _lc('HOME_MODAL_NOT_ACTIVATED_BUTTON')
  972. });
  973. $("body").on( 'click', '[data-id="not-activated"]', function(e)
  974. {
  975. e.preventDefault();
  976. app.core.View.closeModal();
  977. window.location.href = $(this).attr("href");
  978. });
  979. }
  980. app.core.View.showModal({
  981. title: _lc('HOME_MODAL_TERMS_NOT_ACCEPTED_TITLE'),
  982. body: app.core.View.getTemplate('home-modal-terms-not-accepted', {}),
  983. hideButtons: true,
  984. hideCloseBtn: true,
  985. prohibitCloseModal: true,
  986. });
  987. }
  988. );
  989. };
  990. state.onExit = function( p )
  991. {
  992. this.setStateSetting( 'scrollY', window.scrollY );
  993. };
  994. return state;
  995. };