You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

827 lines
35 KiB

  1. /**
  2. * Created by Benny on 12.10.2014.
  3. */
  4. "use strict";
  5. var TB = TB || {};
  6. TB.Control = TB.Control || {};
  7. TB.Control.Appointment = {
  8. index: function( params ) {
  9. TB.GUI.showLoader();
  10. var page = new TB.Page( 'appointment' ),
  11. pageData = [];
  12. TB.Service.request('Appointment', 'getList', {}, function (data) {
  13. TB.GUI.hideLoader();
  14. pageData = data;
  15. data.profile = TB.Client.profile;
  16. TB.GUI.show( page, data );
  17. // Content Big
  18. page.$container.find( 'table tbody tr').on( "click", "label.btn-disabled", function() {
  19. var $label = $( this),
  20. appointmentId = $label.attr( 'data-appointment-id'),
  21. status = $label.attr( 'data-label-type' ) == 'accept' ? 'accepted' : 'declined';
  22. TB.Service.request(
  23. 'Appointment',
  24. 'setAttendanceStatus',
  25. { status: status, appointment_id: appointmentId, ext_result: true },
  26. function( data ) {
  27. if ( data.error )
  28. {
  29. TB.Ext.Alert.show(
  30. 'Zusagefrist abgelaufen',
  31. data.appointment.feedback_deadline_notice
  32. );
  33. }
  34. else
  35. {
  36. TB.Ext.Notification.show( 'Teilnahme Einstellung gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
  37. if ( 'accept' == $label.attr( 'data-label-type' ) ) {
  38. $label.parent( 'div').find( 'label[data-label-type="decline"]').removeClass( 'active').removeClass( 'btn-danger').addClass( 'btn-disabled' );
  39. $label.addClass( 'btn-success').addClass( 'active').removeClass( 'btn-disabled' );
  40. } else {
  41. $label.parent( 'div').find( 'label[data-label-type="accept"]' ).removeClass( 'active').removeClass( 'btn-success' ).addClass( 'btn-disabled' );
  42. $label.addClass( 'btn-danger').addClass( 'active').removeClass( 'btn-disabled' );
  43. }
  44. page.$container.find( 'span[data-accepted-label-id="' + appointmentId + '"]').html( data.ext_result.num_accepted );
  45. page.$container.find( 'span[data-declined-label-id="' + appointmentId + '"]').html( data.ext_result.num_declined );
  46. }
  47. },
  48. $( this )
  49. );
  50. });
  51. // Content Small
  52. page.$container.find( 'table tbody tr').on( "click", 'span[data-action="setstatus"].clickable', function() {
  53. var $span = $(this),
  54. appointmentId = $span.attr( 'data-appointment-id'),
  55. status = $span.attr( 'data-label-type' );
  56. TB.Service.request(
  57. 'Appointment',
  58. 'setAttendanceStatus',
  59. { status: status, appointment_id: appointmentId, ext_result: false },
  60. function( data ) {
  61. if ( data.error ) {
  62. TB.Ext.Alert.show(
  63. 'Zusagefrist abgelaufen',
  64. data.appointment.feedback_deadline_notice
  65. );
  66. } else {
  67. TB.Ext.Notification.show( 'Teilnahme Einstellung gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
  68. if ( 'accepted' == status ) {
  69. $span.addClass( 'label-success').removeClass( 'clickable' );
  70. $span.parent( 'td').find( 'span[data-label-type="declined"]').removeClass( 'label-danger').addClass( 'clickable' );
  71. } else {
  72. $span.addClass( 'label-danger').removeClass( 'clickable' );
  73. $span.parent( 'td' ).find( 'span[data-label-type="accepted"]').removeClass( 'label-success').addClass( 'clickable' );
  74. }
  75. page.$container.find( 'span[data-accepted-label-id="' + appointmentId + '"]').html( data.ext_result.num_accepted );
  76. page.$container.find( 'span[data-declined-label-id="' + appointmentId + '"]').html( data.ext_result.num_declined );
  77. }
  78. },
  79. $( this )
  80. );
  81. return false;
  82. });
  83. page.$container.find( 'button[data-id="btn_appointment_create_match"]').click( function() {
  84. TB.Controller.do( 'Appointment', 'create_match' );
  85. });
  86. page.$container.find( '#btn-coach-help').click( function() {
  87. TB.GUI.showModal(
  88. "Termine",
  89. TB.Config.Content.helpHtml.termine
  90. );
  91. });
  92. page.$container.find( 'button[data-id="btn_appointment_export"]').click( function()
  93. {
  94. if ( TB.Premium.isPremium() )
  95. {
  96. TB.Service.request( 'Team', 'load', { addPremium: true } , function( teamData ) {
  97. var filename = TB.Client.getCurrentTeam().display_name + "-" + moment().format( 'D-M-Y' ),
  98. appointmentDate, appointmentName, appointmentLocation, attendees,
  99. fnGetAttendeeFirstname, fnGetAttendeeLastname,
  100. config = {},
  101. rows = [];
  102. fnGetAttendeeFirstname = function( profileId )
  103. {
  104. var firstName = 'Unbekannt';
  105. for ( var pi = 0; pi < teamData.profiles.length; pi++ )
  106. {
  107. if ( profileId == teamData.profiles[ pi ].id )
  108. {
  109. firstName = teamData.profiles[ pi ].first_name;
  110. break;
  111. }
  112. }
  113. return firstName;
  114. };
  115. fnGetAttendeeLastname = function( profileId )
  116. {
  117. var lastName = 'Unbekannt';
  118. for ( var pi = 0; pi < teamData.profiles.length; pi++ )
  119. {
  120. if ( profileId == teamData.profiles[ pi ].id )
  121. {
  122. lastName = teamData.profiles[ pi ].last_name;
  123. break;
  124. }
  125. }
  126. return lastName;
  127. };
  128. // Wann | Was | Wo | Vorname | Nachname | Mailadresse | Status | Status vom | Kommentar
  129. rows.push(
  130. [
  131. { value : 'Wann', type : 'string' },
  132. { value : 'Was', type : 'string' },
  133. { value : 'Wo', type : 'string' },
  134. { value : 'Vorname', type : 'string' },
  135. { value : 'Nachname', type : 'string' },
  136. { value : 'Status', type : 'string' },
  137. { value : 'Status vom', type : 'string' },
  138. { value : 'Kommentar', type : 'string' }
  139. ]
  140. );
  141. for ( var ai = 0; ai < pageData.appointments.length; ai++ )
  142. {
  143. appointmentDate = TB.Utils.getDatetimeStringFromUnixTimestamp( pageData.appointments[ ai ].starttime );
  144. appointmentName = TB.Utils.getAppointmentName( pageData.appointments[ ai ] );
  145. appointmentLocation = pageData.appointments[ ai ].location;
  146. if ( false === pageData.hasOwnProperty( 'attendees_' + pageData.appointments[ ai ].id ) )
  147. {
  148. continue;
  149. }
  150. attendees = pageData[ "attendees_" + pageData.appointments[ ai ].id ];
  151. if ( 0 === attendees.length )
  152. {
  153. continue;
  154. }
  155. for ( var aai = 0; aai < attendees.length; aai++ )
  156. {
  157. rows.push(
  158. [
  159. { value : appointmentDate , type : 'string' },
  160. { value : appointmentName , type : 'string' },
  161. { value : appointmentLocation , type : 'string' },
  162. { value : fnGetAttendeeFirstname( attendees[ aai ].profile_id ) , type : 'string' },
  163. { value : fnGetAttendeeLastname( attendees[ aai ].profile_id ) , type : 'string' },
  164. { value : attendees[ aai ].status === "accepted" ? 'zugesagt' : 'abgesagt' , type : 'string' },
  165. { value : TB.Utils.getDatetimeStringFromUnixTimestamp( attendees[ aai ].last_update ) , type : 'string' },
  166. { value : attendees[ aai ].comment ? attendees[ aai ].comment : '' , type : 'string' }
  167. ]
  168. )
  169. }
  170. }
  171. //TB.Utils.exportToCsv( filename, rows, ',' );
  172. config.filename = filename;
  173. config.sheet = { data : rows };
  174. zipcelx( config );
  175. });
  176. }
  177. else
  178. {
  179. TB.Premium.handleNoPremium();
  180. }
  181. });
  182. page.$container.find( 'button[data-id="btn_appointment_subscribe"]').click( function()
  183. {
  184. TB.Premium.callPremium( 'Appointment', 'subscribe' );
  185. });
  186. page.$container.find( 'button[data-id="btn_appointment_create_other"]').click( function() {
  187. TB.Controller.do( 'Appointment', 'create_other' );
  188. });
  189. page.$container.find( 'button[data-id="btn-show-old-appointments"]').click( function() {
  190. if ( TB.Premium.isPremium() )
  191. {
  192. $(this).blur();
  193. $(this).find( 'i.glyphicon-chevron-right').toggle();
  194. $(this).find( 'i.glyphicon-chevron-down').toggle();
  195. if ( page.$container.find( '.specialContentSmall').is( ":visible" ) ) {
  196. page.$container.find( '#appointment-table-old-appointment-small').slideToggle("slow");
  197. } else {
  198. page.$container.find( '#appointment-table-old-appointment').slideToggle("slow");
  199. }
  200. }
  201. else
  202. {
  203. TB.Premium.handleNoPremium();
  204. }
  205. });
  206. // Create new match appointment
  207. page.$container.find('#btn_appointment_save_match').click( function () {
  208. if ( !TB.GUI.performFormValidation( $( '#form_new_appointment_match' ) ) ) {
  209. return false;
  210. }
  211. var props = $( '#form_new_appointment_match').serializeObject();
  212. props.starttime = TB.Utils.getUnixTimestampFromDatetimeString( props.starttime );
  213. TB.Service.request(
  214. 'Appointment',
  215. 'create',
  216. props,
  217. function() {
  218. TB.Ext.Notification.show( 'Spieltermin erstellt.', TB.Ext.Notification.TYPE_SUCCESS );
  219. // Reload
  220. TB.Controller.do( 'Appointment', 'index' )
  221. },
  222. $( this )
  223. );
  224. // Dont do FORM post
  225. return false;
  226. });
  227. // Create new other appointment
  228. page.$container.find('#btn_appointment_save_other').click( function () {
  229. if ( !TB.GUI.performFormValidation( $( '#form_new_appointment_other' ) ) ) {
  230. return false;
  231. }
  232. var props = $( '#form_new_appointment_other').serializeObject();
  233. props.starttime = TB.Utils.getUnixTimestampFromDatetimeString( props.starttime );
  234. TB.Service.request(
  235. 'Appointment',
  236. 'create',
  237. props,
  238. function() {
  239. TB.Ext.Notification.show( 'Termin erstellt.', TB.Ext.Notification.TYPE_SUCCESS );
  240. // Reload
  241. TB.Controller.do( 'Appointment', 'index' )
  242. },
  243. $( this )
  244. );
  245. // Dont do FORM post
  246. return false;
  247. });
  248. });
  249. },
  250. subscribe : function( params )
  251. {
  252. TB.GUI.showLoader();
  253. var page = new TB.Page( 'appointment_subscribe' ),
  254. pageData = [],
  255. fnCopyToClipboard = function( $elem ) {
  256. var input = $elem.get(0);
  257. var isiOSDevice = navigator.userAgent.match(/ipad|iphone/i);
  258. if (isiOSDevice) {
  259. var editable = input.contentEditable;
  260. var readOnly = input.readOnly;
  261. input.contentEditable = true;
  262. input.readOnly = false;
  263. var range = document.createRange();
  264. range.selectNodeContents(input);
  265. var selection = window.getSelection();
  266. selection.removeAllRanges();
  267. selection.addRange(range);
  268. input.setSelectionRange(0, 999999);
  269. input.contentEditable = editable;
  270. input.readOnly = readOnly;
  271. } else {
  272. input.select();
  273. }
  274. return document.execCommand('copy');
  275. };
  276. TB.Service.request( 'Appointment', 'subscribe', {}, function (data) {
  277. TB.GUI.hideLoader();
  278. pageData = data;
  279. pageData.profile = TB.Client.profile;
  280. TB.GUI.show( page, pageData );
  281. page.$container.find('[data-id="btn-copy-ics-team"]').click(function ()
  282. {
  283. var copyResult = fnCopyToClipboard( page.$container.find('[data-id="tbuddy-ics-team"]').first() ),
  284. html = '<p>Die URL zu deinem Kalender befindet sich nun im Zwischenspeicher.</p><p>Gehe nun in die Kalenderapp deiner Wahl und importiere dort den Kalender.</p><p><b>Tipp</b></p><p>Schau in unsere Hilfe für weitere Tipps</p>';
  285. if (false === copyResult) {
  286. html = '<p>Drücke STRG+C, um die URL zum Kalender in den Zwischenspeicher zu kopieren.</p><p>Gehe nun in die Kalenderapp deiner Wahl und importiere dort den Kalender.</p><p><b>Tipp</b></p><p>Schau in unsere Hilfe für weitere Tipps</p>';
  287. }
  288. TB.Ext.Alert.modal({
  289. title: 'Kalender URL kopiert',
  290. html: html,
  291. showCancelButton: false,
  292. confirmButtonColor: '#048DBF',
  293. type: 'success'
  294. });
  295. });
  296. page.$container.find('[data-id="btn-copy-ics-team-profile"]').click(function ()
  297. {
  298. var copyResult = fnCopyToClipboard( page.$container.find('[data-id="tbuddy-ics-team-profile"]').first() ),
  299. html = '<p>Die URL zu deinem Kalender befindet sich nun im Zwischenspeicher.</p><p>Gehe nun in die Kalenderapp deiner Wahl und importiere dort den Kalender.</p><p><b>Tipp</b></p><p>Schau in unsere Hilfe für weitere Tipps</p>';
  300. if (false === copyResult) {
  301. page.$container.find('[data-id="tbuddy-ics-team-profile"]').first().removeAttr( 'readonly' );
  302. page.$container.find('[data-id="tbuddy-ics-team-profile"]').first().select();
  303. html = '<p>Drücke STRG/CMD+C, um die URL zum Kalender in den Zwischenspeicher zu kopieren.</p><p>Gehe nun in die Kalenderapp deiner Wahl und importiere dort den Kalender.</p><p><b>Tipp</b></p><p>Schau in unsere Hilfe für weitere Tipps</p>';
  304. }
  305. TB.Ext.Alert.modal({
  306. title: 'Kalender URL kopiert',
  307. html: html,
  308. showCancelButton: false,
  309. confirmButtonColor: '#048DBF',
  310. type: 'success'
  311. });
  312. });
  313. });
  314. },
  315. create_match : function( params ) {
  316. TB.GUI.showLoader();
  317. var page = new TB.Page( 'appointment_create_match' ),
  318. pageData = [];
  319. TB.Service.request('Team', 'getCurrent', { including_members : true }, function (data) {
  320. TB.GUI.hideLoader();
  321. pageData = data;
  322. var isAllowed = true;
  323. if ( data.team.active_premium_package === TB.Premium.PACKAGE_STANDARD &&
  324. data.team.created_ts < ( moment().unix() - (86400 * 60) ) &&
  325. data.team_members.length > 10 )
  326. {
  327. isAllowed = false;
  328. }
  329. data.isAllowed = isAllowed;
  330. TB.GUI.show(page, data);
  331. $('[data-toggle="tooltip"]').tooltip();
  332. page.$container.find('#btn_appointment_save_match_cancel').click(function () {
  333. TB.Controller.do('Appointment', 'index');
  334. });
  335. page.$container.find('button[data-use="teamshortlink"]').click(function () {
  336. $(this).blur();
  337. var $input = $(this).parent().next('input');
  338. if ('' == $input.val()) {
  339. $input.val( pageData.team.display_name );
  340. $input.focus();
  341. $input.blur();
  342. } else {
  343. $input.val('');
  344. $input.focus();
  345. $input.blur();
  346. }
  347. });
  348. // Create new match appointment
  349. page.$container.find('#btn_appointment_save_match').click(function () {
  350. if (!TB.GUI.performFormValidation($('#form_new_appointment_match'))) {
  351. return false;
  352. }
  353. var props = $('#form_new_appointment_match').serializeObject();
  354. props.starttime = TB.Utils.getUnixTimestampFromDatetimeString(props.starttime);
  355. TB.Service.request(
  356. 'Appointment',
  357. 'create',
  358. props,
  359. function () {
  360. TB.Ext.Notification.show('Spieltermin erstellt.', TB.Ext.Notification.TYPE_SUCCESS);
  361. // Reload
  362. TB.Controller.do('Appointment', 'index')
  363. },
  364. $(this)
  365. );
  366. // Dont do FORM post
  367. return false;
  368. });
  369. });
  370. },
  371. create_other : function( params ) {
  372. TB.GUI.showLoader();
  373. var page = new TB.Page( 'appointment_create_other' ),
  374. pageData = [];
  375. TB.Service.request('Team', 'getCurrent', { including_members : true }, function (data) {
  376. TB.GUI.hideLoader();
  377. pageData = data;
  378. var isAllowed = true;
  379. if (data.team.active_premium_package === TB.Premium.PACKAGE_STANDARD &&
  380. data.team.created_ts < (moment().unix() - (86400 * 60)) &&
  381. data.team_members.length > 10) {
  382. isAllowed = false;
  383. }
  384. data.isAllowed = isAllowed;
  385. TB.GUI.show(page, data);
  386. page.$container.find('#btn_appointment_save_other_cancel').click(function () {
  387. TB.Controller.do('Appointment', 'index');
  388. });
  389. page.$container.find('input[type="radio"][name="frequency"]').change(function () {
  390. page.$container.find('div[data-id="frequency-serial-details"]').slideToggle("slow");
  391. });
  392. // Create new other appointment
  393. page.$container.find('#btn_appointment_save_other').click(function () {
  394. if (!TB.GUI.performFormValidation($('#form_new_appointment_other'))) {
  395. return false;
  396. }
  397. var props = $('#form_new_appointment_other').serializeObject(), action = 'create';
  398. props.starttime = TB.Utils.getUnixTimestampFromDatetimeString(props.starttime);
  399. if ("serial" === props.frequency) {
  400. action = 'createSerial'
  401. }
  402. TB.Service.request(
  403. 'Appointment',
  404. action,
  405. props,
  406. function () {
  407. TB.Ext.Notification.show('Termin erstellt.', TB.Ext.Notification.TYPE_SUCCESS);
  408. // Reload
  409. TB.Controller.do('Appointment', 'index')
  410. },
  411. $(this)
  412. );
  413. // Dont do FORM post
  414. return false;
  415. });
  416. });
  417. },
  418. detail : function( params ) {
  419. TB.GUI.showLoader();
  420. var page = new TB.Page( 'appointment_detail'),
  421. pageData = [];
  422. TB.Service.request('Appointment', 'getDetail', { appointment_id: params.appointment_id }, function (data) {
  423. var createCalendarLinks,
  424. canSetStatus = ( (data.appointment.starttime ) > TB.Utils.getUnixTimestamp() );
  425. // Prepare data
  426. data.listAccepted = [],
  427. data.listUndecided = [],
  428. data.listDeclined = [];
  429. $.each( data.profiles, function( i, p ) {
  430. p.orig_status = p.status;
  431. p.status = null;
  432. p.comment = null;
  433. $.each( data.attendees, function( j, a ) {
  434. if ( a.profile_id == p.id ) {
  435. p.status = a.status;
  436. p.comment = a.comment;
  437. p.last_update = a.last_update;
  438. p.last_accepted_ms = ( a.last_accepted !== null ) ? moment(a.last_accepted).toDate().getTime() : null;
  439. return false;
  440. }
  441. });
  442. if ( p.status == 'accepted' ) {
  443. data.listAccepted.push( p );
  444. } else if ( p.status == 'declined' ) {
  445. data.listDeclined.push( p );
  446. } else {
  447. // Only add to list if not a fan
  448. if ( !TB.GUI.isFan( p ) ) {
  449. data.listUndecided.push( p );
  450. }
  451. }
  452. });
  453. data.listAccepted = data.listAccepted.sort( function( a, b ) {
  454. if ( a.last_accepted_ms == null && b.last_accepted_ms == null ) {
  455. return 0;
  456. } else if ( a.last_accepted_ms == null ) {
  457. return 1;
  458. } else if ( b.last_accepted_ms == null ) {
  459. return -1;
  460. } else {
  461. return a.last_accepted_ms - b.last_accepted_ms;
  462. }
  463. });
  464. TB.GUI.hideLoader();
  465. // Create calendarLinks
  466. createCalendarLinks = TB.Utils.createCalendar( {
  467. title: (( data.appointment.subject ) ? data.appointment.subject : data.appointment.home + ':' + data.appointment.guest),
  468. start : TB.Utils.getDateFromUnixTimestamp( data.appointment.starttime ),
  469. duration : data.appointment.duration,
  470. address : data.appointment.location,
  471. description : data.appointment.comment
  472. });
  473. data.addToCalendarLinks = createCalendarLinks;
  474. data.canSetStatus = canSetStatus;
  475. TB.GUI.show(page, data);
  476. page.$container.find( '#btn_edit_appointment').click( function() {
  477. TB.Controller.do( 'Appointment', 'edit', { appointment_id: params.appointment_id } );
  478. });
  479. page.$container.find( '#btn_delete_appointment').click( function() {
  480. TB.Ext.Alert.modal({
  481. title: 'Diesen Termin wirklich löschen?'
  482. }, function() {
  483. TB.Controller.do('Appointment', 'delete', { appointment_id: params.appointment_id } );
  484. });
  485. });
  486. page.$container.find( '#btn_appointment_reminder').click( function() {
  487. if ( !data || !data.listUndecided || 0 == data.listUndecided ) {
  488. TB.Ext.Notification.show( 'Alle Buddies haben bereits zu- oder abgesagt.', TB.Ext.Notification.TYPE_INFO );
  489. return false;
  490. }
  491. TB.Ext.Alert.modal({
  492. title: 'Erinnerung senden?',
  493. text : 'Möchtest du wirklich allen ausstehenden Buddies eine Erinnerung via Email senden?'
  494. }, function() {
  495. TB.Service.request(
  496. 'Appointment',
  497. 'sendReminder',
  498. {
  499. appointment_id : data.appointment.id
  500. },
  501. function() {
  502. TB.Ext.Notification.show( 'Erinnerung verschickt.', TB.Ext.Notification.TYPE_SUCCESS );
  503. // Reload
  504. TB.Controller.do( 'Appointment', 'detail', { appointment_id: data.appointment.id } )
  505. },
  506. $( this )
  507. );
  508. });
  509. });
  510. page.$container.find( '[data-id="btn-whats-app-reminder"]' ).click( function()
  511. {
  512. if ( !TB.Env.isMobile() )
  513. {
  514. TB.Ext.Notification.show( 'Diese Funktion kann nur auf mobilen Geräten verwendet werden, die WhatsApp installiert haben', TB.Ext.Notification)
  515. return false;
  516. }
  517. });
  518. page.$container.find( '#btn_pdf_export').click( function() {
  519. TB.Ext.PDF.downloadAppointment( data );
  520. return false;
  521. });
  522. page.$container.find( '#btn_edit_appointment_attendees').click( function() {
  523. TB.Premium.callPremium( 'Appointment', 'edit_attendees', { appointment_id: params.appointment_id } );
  524. return false;
  525. });
  526. page.$container.find( '#btn_set_attendee_status').click( function() {
  527. var appointmentId = $( this).attr( 'data-appointment-id'),
  528. comment = $( '#comment').val(),
  529. status = ( $( '#form_appointment_attendance label.active').attr( 'data-label-type') == 'accept' ) ? 'accepted' : 'declined';
  530. if ( !( $( '#form_appointment_attendance label.active').attr( 'data-label-type') == 'accept' ) &&
  531. !( $( '#form_appointment_attendance label.active').attr( 'data-label-type') == 'decline' ) ) {
  532. return false;
  533. }
  534. TB.Service.request(
  535. 'Appointment',
  536. 'setAttendanceStatus',
  537. { appointment_id: appointmentId, comment: comment, status: status },
  538. function( data ) {
  539. if ( data.error ) {
  540. TB.Ext.Alert.show(
  541. 'Zusagefrist abgelaufen',
  542. data.appointment.feedback_deadline_notice
  543. );
  544. } else {
  545. TB.Ext.Notification.show( 'Teilnahme Einstellung gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
  546. TB.Controller.reload();
  547. }
  548. },
  549. $( this )
  550. );
  551. return false;
  552. });
  553. page.$container.find( '#form_appointment_attendance').on( "click", "label.btn-disabled", function() {
  554. var $label = $( this),
  555. appointmentId = $label.attr( 'data-appointment-id'),
  556. status = $label.attr( 'data-label-type' ) == 'accept' ? 'accepted' : 'declined';
  557. if ( 'accept' == $label.attr( 'data-label-type' ) ) {
  558. $label.parent( 'div').find( 'label[data-label-type="decline"]').removeClass( 'active').removeClass( 'btn-danger').addClass( 'btn-disabled' );
  559. $label.addClass( 'btn-success').addClass( 'active').removeClass( 'btn-disabled' );
  560. } else {
  561. $label.parent( 'div').find( 'label[data-label-type="accept"]' ).removeClass( 'active').removeClass( 'btn-success' ).addClass( 'btn-disabled' );
  562. $label.addClass( 'btn-danger').addClass( 'active').removeClass( 'btn-disabled' );
  563. }
  564. });
  565. });
  566. },
  567. reminder : function( params ) {
  568. return false;
  569. TB.GUI.showLoader();
  570. var page = new TB.Page( 'appointment_send_reminder'),
  571. pageData = [];
  572. TB.Service.request('Appointment', 'getReminder', { appointment_id: params.appointment_id }, function (data) {
  573. TB.GUI.hideLoader();
  574. pageData = data;
  575. TB.GUI.show(page, data);
  576. page.$container.find( '#btn_appointment_reminder_cancel').click( function() {
  577. TB.Controller.do( 'Appointment', 'detail', { appointment_id: pageData.appointment.id } );
  578. });
  579. page.$container.find( '#btn_appointment_reminder_submit').click( function() {
  580. if ( !TB.GUI.performFormValidation( $( '#form_appointment_edit' ) ) ) {
  581. return false;
  582. }
  583. var props = $( '#form_appointment_send_reminder').serializeObject();
  584. TB.Service.request(
  585. 'Appointment',
  586. 'sendReminder',
  587. props,
  588. function() {
  589. TB.Ext.Notification.show( 'Erinnerung verschickt.', TB.Ext.Notification.TYPE_SUCCESS );
  590. // Reload
  591. TB.Controller.do( 'Appointment', 'detail', { appointment_id: pageData.appointment.id } )
  592. },
  593. $( this )
  594. );
  595. // Dont do FORM post
  596. return false;
  597. });
  598. });
  599. },
  600. delete : function( params ) {
  601. TB.Service.request(
  602. 'Appointment',
  603. 'delete',
  604. { appointment_id: params.appointment_id },
  605. function (data) {
  606. TB.Ext.Notification.show( 'Termin erfolgreich gelöscht.', TB.Ext.Notification.TYPE_SUCCESS );
  607. TB.Controller.do( 'Appointment' );
  608. },
  609. $( '#btn_delete_appointment' )
  610. );
  611. },
  612. edit : function( params ) {
  613. TB.GUI.showLoader();
  614. var page = new TB.Page( 'appointment_edit' ),
  615. pageData = [];
  616. TB.Service.request('Appointment', 'getDetail', { appointment_id: params.appointment_id }, function (data) {
  617. TB.GUI.hideLoader();
  618. pageData = data;
  619. TB.GUI.show(page, data);
  620. page.$container.find( '#btn_update_appointment_cancel').click( function() {
  621. TB.Controller.do( 'Appointment', 'detail', { appointment_id: params.appointment_id } );
  622. });
  623. page.$container.find( '#btn_update_appointment').click( function() {
  624. if ( !TB.GUI.performFormValidation( $( '#form_appointment_edit' ) ) ) {
  625. return false;
  626. }
  627. var props = $( '#form_appointment_edit').serializeObject();
  628. props.starttime = TB.Utils.getUnixTimestampFromDatetimeString( props.starttime );
  629. TB.Service.request(
  630. 'Appointment',
  631. 'update',
  632. props,
  633. function() {
  634. TB.Ext.Notification.show( 'Termin geändert.', TB.Ext.Notification.TYPE_SUCCESS );
  635. // Reload
  636. TB.Controller.do( 'Appointment', 'detail', { appointment_id: props.id } )
  637. },
  638. $( this )
  639. );
  640. // Dont do FORM post
  641. return false;
  642. });
  643. });
  644. },
  645. edit_attendees : function( params ) {
  646. TB.GUI.showLoader();
  647. var page = new TB.Page( 'appointment_edit_attendees');
  648. TB.Service.request('Appointment', 'getDetail', { appointment_id: params.appointment_id }, function (data) {
  649. var appointmentId = data.appointment.id;
  650. TB.GUI.hideLoader();
  651. $.each( data.profiles, function( i, p ) {
  652. p.status = null;
  653. p.comment = null;
  654. $.each( data.attendees, function( j, a ) {
  655. if ( a.profile_id == p.id ) {
  656. p.status = a.status;
  657. p.comment = a.comment;
  658. p.last_update = a.last_update;
  659. return false;
  660. }
  661. });
  662. });
  663. TB.GUI.show(page, data);
  664. $( 'td[data-title="Status"]' ).find( 'span.label' ).on( "click", function() {
  665. var $span = $(this);
  666. TB.Service.request( 'Appointment', 'setAttendanceStatusByTrainer', {
  667. appointment_id : appointmentId,
  668. profile_id : $(this).closest( "tr").attr( "data-profile_id"),
  669. status : $(this).attr( "data-status" )
  670. }, function() {
  671. TB.Ext.Notification.show( "Status erfolgreich geändert.", TB.Ext.Notification.TYPE_SUCCESS );
  672. if ( "accepted" === $span.attr( "data-status") ) {
  673. $span.toggleClass( "label-success" );
  674. $span.next( "span.label").removeClass( "label-danger" );
  675. } else {
  676. $span.toggleClass( "label-danger" );
  677. $span.prev( "span.label").removeClass( "label-success" );
  678. }
  679. });
  680. });
  681. });
  682. }
  683. };