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.
 
 
 
 
 

311 lines
13 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.Team = {
  8. // Load & Create
  9. index : function( params ) {
  10. TB.GUI.showLoader();
  11. var page = new TB.Page( 'team' );
  12. TB.Service.request( 'Team', 'load', { addPremium: true } , function( data ) {
  13. TB.GUI.hideLoader();
  14. TB.GUI.show( page, data );
  15. page.$container.find('#btn_team_invite').click(function () {
  16. if ( TB.GUI.isTrainer() || TB.GUI.isCoTrainer() ) {
  17. TB.Controller.do('Team', 'invite');
  18. } else {
  19. TB.Ext.Alert.show( 'Bitte validiere zuerst Deine Email Adresse.' );
  20. }
  21. return false;
  22. });
  23. page.$container.find( '#btn_team_invite_more' ).click( function() {
  24. TB.Premium.handleNoPremium();
  25. });
  26. page.$container.find( 'button[data-action="invitation-delete"]').click( function() {
  27. var invitationId = $(this).attr( 'data-invitation_id' );
  28. TB.Ext.Alert.modal({
  29. title: 'Einladung löschen?',
  30. text : 'Wenn diese Einladung gelöscht wird, verliert die Einladung ihre Gültigkeit.'
  31. }, function() {
  32. TB.Service.request( 'Team', 'deleteInvitation', { invitation_id : invitationId }, function( data ) {
  33. if ( data.res && data.res == 'ok' ) {
  34. TB.Ext.Notification.show( 'Einladung erfolgreich gelöscht.', TB.Ext.Notification.TYPE_SUCCESS );
  35. TB.Controller.reload();
  36. } else {
  37. TB.Ext.Notification.show( 'Ein Fehler ist aufgetreten', TB.Ext.Notification.TYPE_DANGER );
  38. }
  39. });
  40. });
  41. });
  42. page.$container.find( 'button[data-action="invitation-reminder"]').click( function() {
  43. var invitationId = $(this).attr('data-invitation_id');
  44. TB.Ext.Alert.modal({
  45. title: 'Einladung erneut verschickten?'
  46. }, function() {
  47. TB.Service.request( 'Team', 'resendInvitation', { invitation_id : invitationId }, function( data ) {
  48. if ( data.res && data.res == 'ok' ) {
  49. TB.Ext.Notification.show( 'Einladung erfolgreich verschickt.', TB.Ext.Notification.TYPE_SUCCESS );
  50. TB.Utils.trackEvent( 'team', 'invitation_resend' );
  51. TB.Controller.reload();
  52. } else if ( data.res && data.res == 'not-enough-time-passed' ) {
  53. TB.Ext.Alert.modal( {
  54. title : 'Nicht möglich',
  55. text : 'Einladungen können erst nach einer Zeit von 24 Stunden erneut verschickt werden.'
  56. });
  57. } else {
  58. TB.Ext.Notification.show( 'Ein Fehler ist aufgetreten', TB.Ext.Notification.TYPE_DANGER );
  59. }
  60. });
  61. });
  62. });
  63. page.$container.find( '#btn_edit_team').click( function() {
  64. TB.Controller.do( 'Team', 'edit' );
  65. return false;
  66. });
  67. page.$container.find( '#btn_edit_team_emblem').click( function() {
  68. TB.Premium.callPremium( 'Team', 'edit_emblem' );
  69. return false;
  70. });
  71. page.$container.find( '#btn-coach-help').click( function() {
  72. TB.GUI.showModal(
  73. "Team",
  74. TB.Config.Content.helpHtml.team
  75. );
  76. });
  77. });
  78. },
  79. edit_emblem : function( params ) {
  80. TB.GUI.showLoader();
  81. var page = new TB.Page( 'team_edit_emblem' ),
  82. slimCropper;
  83. page.onLeave = function() {
  84. slimCropper && slimCropper.destroy()
  85. };
  86. TB.Service.request( 'Team', 'load', {} , function( data ) {
  87. TB.GUI.hideLoader();
  88. TB.GUI.show(page, data);
  89. function initSlimCropper() {
  90. slimCropper = new Slim(
  91. document.getElementsByClassName('slim')[0], {
  92. label: 'Emblem wählen',
  93. ratio: '1:1',
  94. maxFileSize: 6,
  95. size: {
  96. width: 300,
  97. height: 300
  98. },
  99. edit: true,
  100. instantEdit: true,
  101. download: false,
  102. buttonCancelLabel: 'Abbrechen',
  103. buttonConfirmLabel: 'Ok',
  104. statusNoSupport: 'Dein Browser unterstützt diese Funktion nicht.',
  105. statusImageTooSmall: 'Das Bild ist zu klein.',
  106. statusContentLength: 'Das Bild ist zu groß.',
  107. statusFileSize: 'Das Bild ist zu groß. Es darf maximal 6MB groß sein.'
  108. }
  109. );
  110. }
  111. initSlimCropper();
  112. page.$container.find( '#btn_edit_team_emblem_new').click( function() {
  113. if ( TB.Env.isNativeMobile() && "ANDROID" == TB.Env.platform ) {
  114. var myCb = function( data ) {
  115. slimCropper && slimCropper.destroy();
  116. var $myImg = page.$container.find( '#edit-team-emblem-img' );
  117. $myImg.on( 'load', function() {
  118. slimCropper && slimCropper.destroy()
  119. initSlimCropper();
  120. });
  121. $myImg.attr( 'src', "data:image/jpeg;base64," + data.pic64 );
  122. initSlimCropper();
  123. slimCropper.edit();
  124. };
  125. TB.ICom.post( "getPictureData", null, myCb );
  126. } else {
  127. slimCropper.remove();
  128. page.$container.find( 'input[type="file"]' ).click();
  129. }
  130. return false;
  131. });
  132. page.$container.find( '#btn_edit_team_emblem_cancel').click( function() {
  133. TB.Controller.do( 'Team', 'index' );
  134. return false;
  135. });
  136. page.$container.find( '#btn_edit_team_emblem_save').click( function() {
  137. var imgData = slimCropper.dataBase64;
  138. TB.GUI.showLoader();
  139. // Update
  140. TB.Service.request(
  141. 'Team',
  142. 'updateEmblem',
  143. { slim : JSON.stringify( imgData ) },
  144. function(data) {
  145. TB.GUI.hideLoader();
  146. TB.Ext.Notification.show( 'Teamemblem erfolgreich gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
  147. TB.Controller.do( 'Team', 'index' );
  148. TB.Utils.trackEvent( 'team', 'pic_updated' );
  149. },
  150. $(this),
  151. function() {
  152. TB.GUI.hideLoader();
  153. TB.Ext.Notification.show( 'Emblem konnte nicht gespeichert. Versuche es später erneut.', TB.Ext.Notification.TYPE_DANGER );
  154. TB.Controller.do( 'Team', 'index' );
  155. }
  156. );
  157. return false;
  158. });
  159. });
  160. },
  161. edit : function( params )
  162. {
  163. TB.GUI.showLoader();
  164. var page = new TB.Page( 'team_settings_detail' ),
  165. activeTab = 'details';
  166. TB.Service.request( 'Team', 'load', {} , function( data ) {
  167. TB.GUI.hideLoader();
  168. data.activeTab = activeTab;
  169. TB.GUI.show( page, data );
  170. page.$container.find( '#teamcategory' ).easyAutocomplete({
  171. // Note:
  172. // Duplicate list
  173. data : TB.Config.General.team_categories,
  174. list: {
  175. maxNumberOfElements: 10,
  176. match: {
  177. enabled: true
  178. }
  179. }
  180. });
  181. page.$container.find( '#btn_save_team_cancel').click( function() {
  182. TB.Controller.do( 'Team', 'index' );
  183. return false;
  184. });
  185. page.$container.find( '#btn_save_team').click( function() {
  186. if ( !TB.GUI.performFormValidation( $( '#form_save_team' ) ) ) {
  187. return false;
  188. }
  189. var displayName = page.$container.find( 'input[name="team.display_name"]').val(),
  190. regNo = page.$container.find( 'input[name="team.reg_no"]').val(),
  191. teamId = page.$container.find( 'input[name="team.id"]').val(),
  192. category = page.$container.find( 'input[name="team.category"]').val();
  193. // Update
  194. TB.Service.request(
  195. 'Team',
  196. 'update',
  197. { display_name: displayName, reg_no : regNo, category : category },
  198. function(data) {
  199. TB.Ext.Notification.show( 'Teamänderungen erfolgreich gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
  200. TB.Controller.do( 'Team', 'index' );
  201. },
  202. $(this)
  203. );
  204. return false;
  205. });
  206. });
  207. },
  208. invite : function( params ) {
  209. TB.GUI.showLoader();
  210. var page = new TB.Page( 'team_invite' );
  211. TB.Service.request( 'Team', 'load', {} , function( data ) {
  212. data.profile = TB.Client.profile;
  213. TB.GUI.hideLoader();
  214. TB.GUI.show( page, data );
  215. page.$container.find( '#btn_invite_player_cancel').click( function() {
  216. TB.Controller.do( 'Team' );
  217. return false;
  218. });
  219. page.$container.find( '#btn-group-role').find( 'label' ).not( '.btn-disabled').click( function() {
  220. $(this).parent( "div").find( 'label.btn-primary').removeClass( 'btn-primary').addClass( 'btn-default');
  221. $(this).removeClass( 'btn-default').addClass( 'btn-primary');
  222. page.$container.find( '#btn-group-role').find( 'span.fa.fa-check').remove();
  223. $( this ).append( '<span class="fa fa-check"></span>' );
  224. });
  225. page.$container.find( '#btn_invite_player').click( function() {
  226. if ( !TB.GUI.performFormValidation( $( '#form_invite_player' ) ) ) {
  227. return false;
  228. }
  229. var email = page.$container.find( 'input[name="player_invitation_email"]').val(),
  230. firstName = page.$container.find( 'input[name="player_invitation_first_name"]').val(),
  231. lastName = page.$container.find( 'input[name="player_invitation_last_name"]').val(),
  232. role = page.$container.find( 'input[name="player_invitation_role"]:checked').val();
  233. TB.Service.request( 'Team', 'invitePlayer', {
  234. player_invitation_email: email,
  235. player_invitation_first_name: firstName,
  236. player_invitation_last_name: lastName,
  237. player_invitation_role : role
  238. },
  239. function( data ) {
  240. if ( data.error && 'email-already-in-team' == data.error ) {
  241. TB.Ext.Alert.show( 'Email vorhanden', 'Ein Buddy mit dieser Email Adresse befindet sich bereits im Team.' );
  242. }
  243. else if ( data.error && 'email-already-invited' == data.error ) {
  244. TB.Ext.Alert.show( 'Email Einladung', 'Eine Einladung an diese Email Adresse wurde bereits verschickt.' );
  245. }
  246. else {
  247. TB.Ext.Notification.show( 'Einladung wird in Kürze verschickt.', TB.Ext.Notification.TYPE_SUCCESS );
  248. TB.Controller.do( 'Team', 'index' );
  249. TB.Utils.trackEvent( 'team', 'invitation_send' );
  250. }
  251. },
  252. $(this)
  253. );
  254. return false;
  255. });
  256. });
  257. }
  258. };