Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

306 lignes
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.Player = {
  8. // List of players
  9. index : function( params ) {
  10. TB.GUI.showLoader();
  11. var page = new TB.Page( 'player'),
  12. profileId = ( params && params.profile_id ) ? params.profile_id : TB.Client.profile.id;
  13. TB.Service.request( 'Profile', 'get', { profile_id: profileId } , function( data ) {
  14. TB.GUI.hideLoader();
  15. TB.GUI.show( page, data );
  16. page.$container.find( '#btn_playerpic_edit').click( function() {
  17. TB.Premium.callPremium( 'Player', 'edit_pic', { profile_id: profileId } );
  18. //TB.Controller.do( 'Player', 'edit_pic', { profile_id: profileId } );
  19. return false;
  20. });
  21. page.$container.find( '#btn_player_edit,#btn_traineropt_player_edit').click( function() {
  22. TB.Controller.do( 'Player', 'edit', { profile_id: profileId }, $(this) );
  23. return false;
  24. });
  25. page.$container.find( '#btn_player_delete, #btn_traineropt_player_delete').click( function() {
  26. //TB.Ext.Alert.show( 'Die Funktion steht derzeit noch nicht zur verfügung.' );
  27. TB.Controller.do( 'Player', 'confirmdelete', { profile_id: profileId }, $(this) );
  28. return false;
  29. });
  30. page.$container.find( '#btn-coach-help').click( function() {
  31. TB.GUI.showModal(
  32. "Profile",
  33. TB.Config.Content.helpHtml.profil
  34. );
  35. });
  36. });
  37. },
  38. edit : function( params ) {
  39. TB.GUI.showLoader();
  40. var page = new TB.Page( 'player_edit'),
  41. profileId = params.profile_id;
  42. TB.Service.request( 'Profile', 'get', { profile_id: profileId } , function( data ) {
  43. TB.GUI.hideLoader();
  44. TB.GUI.show( page, data );
  45. page.$container.find( '#btn-group-status').find( 'label' ).click( function() {
  46. $(this).parent( "div").find( 'label.btn-primary').removeClass( 'btn-primary').addClass( 'btn-default');
  47. $(this).removeClass( 'btn-default').addClass( 'btn-primary');
  48. page.$container.find( '#btn-group-status').find( 'span.fa.fa-check').remove();
  49. $( this ).append( '<span class="fa fa-check"></span>' );
  50. });
  51. page.$container.find( '#btn-group-role').find( 'label' ).not( '.btn-disabled').click( function() {
  52. $(this).parent( "div").find( 'label.btn-primary').removeClass( 'btn-primary').addClass( 'btn-default');
  53. $(this).removeClass( 'btn-default').addClass( 'btn-primary');
  54. page.$container.find( '#btn-group-role').find( 'span.fa.fa-check').remove();
  55. $( this ).append( '<span class="fa fa-check"></span>' );
  56. });
  57. page.$container.find( '#btn_player_update').click( function() {
  58. if ( !TB.GUI.performFormValidation( $( '#form_player_edit' ) ) ) {
  59. return false;
  60. }
  61. var props = $('#form_player_edit').serializeObject();
  62. props.birthday = props.birthday.length ? TB.Utils.convertDatepickerDateStringToSQLDate( props.birthday ) : null;
  63. TB.Service.request(
  64. 'Profile',
  65. 'update',
  66. props,
  67. function( data ) {
  68. TB.Ext.Notification.show( 'Änderungen gespeichert. Es kann einige Minuten dauern, bis die Änderungen aktualisiert werden.', TB.Ext.Notification.TYPE_SUCCESS );
  69. if ( data.own_profile ) {
  70. TB.Client.updateSessionProfile( data.own_profile );
  71. }
  72. // Reload
  73. TB.Controller.do( 'Player', 'index', { profile_id: props.id } )
  74. },
  75. $( this )
  76. );
  77. return false;
  78. });
  79. page.$container.find( '#btn_player_update_cancel').click( function() {
  80. TB.Controller.do( 'Player', 'index', { profile_id: profileId } );
  81. });
  82. });
  83. },
  84. edit_pic : function( params ) {
  85. TB.GUI.showLoader();
  86. var page = new TB.Page( 'player_edit_pic' ),
  87. profileId = ( params && params.profile_id ) ? params.profile_id : TB.Client.profile.id,
  88. serviceAction = TB.Client.can( TB.ACL.RIGHTS.PROFILE_UPDATEPICBYTRAINER ) ? 'updatePicByTrainer' : 'updatePic',
  89. slimCropper;
  90. page.onLeave = function() {
  91. slimCropper && slimCropper.destroy()
  92. };
  93. TB.Service.request( 'Profile', 'get', { profile_id: profileId } , function( data ) {
  94. TB.GUI.hideLoader();
  95. TB.GUI.show(page, data);
  96. function initSlimCropper() {
  97. slimCropper = new Slim(
  98. document.getElementsByClassName( 'slim' )[0], {
  99. label : 'Bild wählen',
  100. ratio : '1:1',
  101. maxFileSize : 6,
  102. size : {
  103. width: 300,
  104. height : 300
  105. },
  106. edit : true,
  107. instantEdit : true,
  108. download : false,
  109. buttonCancelLabel : 'Abbrechen',
  110. buttonConfirmLabel: 'Ok',
  111. statusNoSupport : 'Dein Browser unterstützt diese Funktion nicht.',
  112. statusImageTooSmall : 'Das Bild ist zu klein.',
  113. statusContentLength : 'Das Bild ist zu groß.',
  114. statusFileSize : 'Das Bild ist zu groß. Es darf maximal 6MB groß sein.'
  115. }
  116. );
  117. }
  118. initSlimCropper();
  119. page.$container.find( '#btn_edit_profile_pic_new').click( function() {
  120. if ( TB.Env.isNativeMobile() && "ANDROID" == TB.Env.platform ) {
  121. var myCb = function( data ) {
  122. slimCropper && slimCropper.destroy();
  123. var $myImg = page.$container.find( '#edit-profil-pic-img' );
  124. $myImg.on( 'load', function() {
  125. slimCropper && slimCropper.destroy()
  126. initSlimCropper();
  127. });
  128. $myImg.attr( 'src', "data:image/jpeg;base64," + data.pic64 );
  129. initSlimCropper();
  130. slimCropper.edit();
  131. };
  132. TB.ICom.post( "getPictureData", null, myCb );
  133. } else {
  134. slimCropper.remove();
  135. page.$container.find( 'input[type="file"]' ).click();
  136. }
  137. return false;
  138. });
  139. page.$container.find( '#btn_edit_profile_pic_cancel').click( function() {
  140. TB.Controller.do( 'Player', 'index', { profile_id: profileId } );
  141. return false;
  142. });
  143. page.$container.find( '#btn_edit_profile_pic_save').click( function() {
  144. var imgData = slimCropper.dataBase64;
  145. TB.GUI.showLoader();
  146. // Update
  147. TB.Service.request(
  148. 'Profile',
  149. serviceAction,
  150. { slim : JSON.stringify( imgData ), profile_id : profileId },
  151. function(data) {
  152. TB.GUI.hideLoader();
  153. if ( TB.Client.profile.id == profileId ) {
  154. TB.Client.updateSessionProfile( data.profile );
  155. $( '#offcanvasmenu img[data-id="userpic"]').first().attr( 'src', TB.GUI.getProfilePicUrl() );
  156. }
  157. TB.Ext.Notification.show( 'Profilbild erfolgreich gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
  158. TB.Controller.do( 'Player', 'index', { profile_id: profileId } );
  159. TB.Utils.trackEvent( 'profile', 'pic_updated' );
  160. },
  161. $(this),
  162. function() {
  163. TB.GUI.hideLoader();
  164. TB.Ext.Notification.show( 'Profilbild konnte nicht gespeichert. Versuche es später erneut.', TB.Ext.Notification.TYPE_DANGER );
  165. TB.Controller.do( 'Player', 'index', { profile_id: profileId } );
  166. }
  167. );
  168. return false;
  169. });
  170. });
  171. },
  172. confirmdelete : function( params ) {
  173. TB.GUI.showLoader();
  174. var page = new TB.Page( 'player_confirmdelete'),
  175. profileId = params.profile_id;
  176. TB.Service.request( 'Profile', 'get', { profile_id: profileId, includePremiumLogs : true } , function( data ) {
  177. var currentTeam = null,
  178. premiumCanBeDeleted = true,
  179. isOwn = TB.GUI.isOwnProfile( data.profile );
  180. if ( data.premium_logs && data.premium_logs.length > 0 )
  181. {
  182. for ( var pli = 0; pli < data.premium_logs.length; pli++ )
  183. {
  184. if ( data.premium_logs[ pli ].package_id !== TB.Premium.PACKAGE_PREMIUM100_FREE &&
  185. data.profile.account_id === data.premium_logs[ pli ].account_id )
  186. {
  187. premiumCanBeDeleted = false;
  188. break;
  189. }
  190. }
  191. }
  192. $.each( TB.Client.teams, function( i, t ) {
  193. if ( TB.Client.profile.team_id == t.id ) {
  194. currentTeam = t;
  195. return false;
  196. }
  197. });
  198. TB.GUI.hideLoader();
  199. TB.GUI.show(page, {
  200. profile : TB.Client.profile,
  201. profileToDelete : data.profile,
  202. profileTeam : currentTeam,
  203. profles : TB.Client.profiles,
  204. account : TB.Client.account,
  205. teams : TB.Client.teams,
  206. premiumCanBeDeleted : premiumCanBeDeleted,
  207. premium_logs : data.premium_logs
  208. });
  209. page.$container.find( '#btn-cancel' ).click( function() {
  210. TB.Controller.do( 'Player', 'index', { profile_id: profileId } );
  211. return false;
  212. });
  213. page.$container.find( '#btn-confirm-deletion' ).click( function() {
  214. // Security check
  215. if ( !page.$container.find( '#checkbox-confirm-deletion').prop( 'checked' ) ) {
  216. TB.Ext.Notification.show(
  217. 'Bitte bestätige die Löschung im Bestätigungsfeld.',
  218. TB.Ext.Notification.TYPE_DANGER
  219. );
  220. } else {
  221. // Perform deletion
  222. TB.Service.request( 'Profile', 'delete', { profile_id: profileId } , function( data ) {
  223. if ( data && data.deletionsuccess ) {
  224. if ( isOwn ) {
  225. TB.Ext.Alert.modal( {
  226. 'showCancelButton' : false,
  227. 'title' : 'Löschung erfolgreich.',
  228. 'text' : 'Du wirst automatisch auf die Startseite weitergeleitet.',
  229. 'allowEscapeKey' : false
  230. },
  231. function() {
  232. TB.Client.logout();
  233. TB.Controller.do('Auth', 'login');
  234. TB.Utils.trackEvent( 'profile', 'deleted' );
  235. }
  236. );
  237. } else {
  238. TB.Ext.Notification.show(
  239. 'Löschung erfolgreich.',
  240. TB.Ext.Notification.TYPE_SUCCESS
  241. );
  242. TB.Controller.do( 'Team', 'index', {} );
  243. return false;
  244. }
  245. } else {
  246. TB.Ext.Notification.show(
  247. 'Es ist ein Fehler beim Löschvorgang aufgetreten. Bitte melde dich beim Support.',
  248. TB.Ext.Notification.TYPE_DANGER
  249. );
  250. }
  251. });
  252. }
  253. return false;
  254. });
  255. });
  256. }
  257. };