|
- /**
- * Created by Benny on 12.10.2014.
- */
-
- "use strict";
-
- var TB = TB || {};
- TB.Control = TB.Control || {};
-
- TB.Control.Team = {
-
- // Load & Create
- index : function( params ) {
- TB.GUI.showLoader();
- var page = new TB.Page( 'team' );
-
- TB.Service.request( 'Team', 'load', { addPremium: true } , function( data ) {
-
- TB.GUI.hideLoader();
- TB.GUI.show( page, data );
-
- page.$container.find('#btn_team_invite').click(function () {
- if ( TB.GUI.isTrainer() || TB.GUI.isCoTrainer() ) {
- TB.Controller.do('Team', 'invite');
- } else {
- TB.Ext.Alert.show( 'Bitte validiere zuerst Deine Email Adresse.' );
- }
- return false;
- });
-
- page.$container.find( '#btn_team_invite_more' ).click( function() {
- TB.Premium.handleNoPremium();
- });
-
- page.$container.find( 'button[data-action="invitation-delete"]').click( function() {
- var invitationId = $(this).attr( 'data-invitation_id' );
- TB.Ext.Alert.modal({
- title: 'Einladung löschen?',
- text : 'Wenn diese Einladung gelöscht wird, verliert die Einladung ihre Gültigkeit.'
- }, function() {
- TB.Service.request( 'Team', 'deleteInvitation', { invitation_id : invitationId }, function( data ) {
- if ( data.res && data.res == 'ok' ) {
- TB.Ext.Notification.show( 'Einladung erfolgreich gelöscht.', TB.Ext.Notification.TYPE_SUCCESS );
- TB.Controller.reload();
- } else {
- TB.Ext.Notification.show( 'Ein Fehler ist aufgetreten', TB.Ext.Notification.TYPE_DANGER );
- }
- });
- });
-
- });
- page.$container.find( 'button[data-action="invitation-reminder"]').click( function() {
- var invitationId = $(this).attr('data-invitation_id');
- TB.Ext.Alert.modal({
- title: 'Einladung erneut verschickten?'
- }, function() {
- TB.Service.request( 'Team', 'resendInvitation', { invitation_id : invitationId }, function( data ) {
- if ( data.res && data.res == 'ok' ) {
- TB.Ext.Notification.show( 'Einladung erfolgreich verschickt.', TB.Ext.Notification.TYPE_SUCCESS );
- TB.Utils.trackEvent( 'team', 'invitation_resend' );
- TB.Controller.reload();
- } else if ( data.res && data.res == 'not-enough-time-passed' ) {
- TB.Ext.Alert.modal( {
- title : 'Nicht möglich',
- text : 'Einladungen können erst nach einer Zeit von 24 Stunden erneut verschickt werden.'
- });
- } else {
- TB.Ext.Notification.show( 'Ein Fehler ist aufgetreten', TB.Ext.Notification.TYPE_DANGER );
- }
- });
- });
- });
-
- page.$container.find( '#btn_edit_team').click( function() {
- TB.Controller.do( 'Team', 'edit' );
- return false;
- });
-
- page.$container.find( '#btn_edit_team_emblem').click( function() {
- TB.Premium.callPremium( 'Team', 'edit_emblem' );
- return false;
- });
-
- page.$container.find( '#btn-coach-help').click( function() {
- TB.GUI.showModal(
- "Team",
- TB.Config.Content.helpHtml.team
- );
- });
- });
- },
-
- edit_emblem : function( params ) {
-
- TB.GUI.showLoader();
- var page = new TB.Page( 'team_edit_emblem' ),
- slimCropper;
-
- page.onLeave = function() {
- slimCropper && slimCropper.destroy()
- };
-
-
- TB.Service.request( 'Team', 'load', {} , function( data ) {
- TB.GUI.hideLoader();
- TB.GUI.show(page, data);
-
- function initSlimCropper() {
- slimCropper = new Slim(
- document.getElementsByClassName('slim')[0], {
- label: 'Emblem wählen',
- ratio: '1:1',
- maxFileSize: 6,
- size: {
- width: 300,
- height: 300
- },
- edit: true,
- instantEdit: true,
- download: false,
- buttonCancelLabel: 'Abbrechen',
- buttonConfirmLabel: 'Ok',
- statusNoSupport: 'Dein Browser unterstützt diese Funktion nicht.',
- statusImageTooSmall: 'Das Bild ist zu klein.',
- statusContentLength: 'Das Bild ist zu groß.',
- statusFileSize: 'Das Bild ist zu groß. Es darf maximal 6MB groß sein.'
- }
- );
- }
-
- initSlimCropper();
-
- page.$container.find( '#btn_edit_team_emblem_new').click( function() {
-
-
- if ( TB.Env.isNativeMobile() && "ANDROID" == TB.Env.platform ) {
-
- var myCb = function( data ) {
- slimCropper && slimCropper.destroy();
- var $myImg = page.$container.find( '#edit-team-emblem-img' );
- $myImg.on( 'load', function() {
- slimCropper && slimCropper.destroy()
- initSlimCropper();
- });
- $myImg.attr( 'src', "data:image/jpeg;base64," + data.pic64 );
- initSlimCropper();
- slimCropper.edit();
- };
-
- TB.ICom.post( "getPictureData", null, myCb );
-
- } else {
-
- slimCropper.remove();
- page.$container.find( 'input[type="file"]' ).click();
- }
- return false;
- });
-
- page.$container.find( '#btn_edit_team_emblem_cancel').click( function() {
- TB.Controller.do( 'Team', 'index' );
- return false;
- });
-
- page.$container.find( '#btn_edit_team_emblem_save').click( function() {
- var imgData = slimCropper.dataBase64;
-
- TB.GUI.showLoader();
-
- // Update
- TB.Service.request(
- 'Team',
- 'updateEmblem',
- { slim : JSON.stringify( imgData ) },
- function(data) {
- TB.GUI.hideLoader();
- TB.Ext.Notification.show( 'Teamemblem erfolgreich gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
- TB.Controller.do( 'Team', 'index' );
- TB.Utils.trackEvent( 'team', 'pic_updated' );
- },
- $(this),
- function() {
- TB.GUI.hideLoader();
- TB.Ext.Notification.show( 'Emblem konnte nicht gespeichert. Versuche es später erneut.', TB.Ext.Notification.TYPE_DANGER );
- TB.Controller.do( 'Team', 'index' );
- }
- );
-
- return false;
- });
-
- });
-
- },
-
- edit : function( params )
- {
- TB.GUI.showLoader();
-
- var page = new TB.Page( 'team_settings_detail' ),
- activeTab = 'details';
-
- TB.Service.request( 'Team', 'load', {} , function( data ) {
- TB.GUI.hideLoader();
-
- data.activeTab = activeTab;
-
- TB.GUI.show( page, data );
-
- page.$container.find( '#teamcategory' ).easyAutocomplete({
- // Note:
- // Duplicate list
- data : TB.Config.General.team_categories,
- list: {
- maxNumberOfElements: 10,
- match: {
- enabled: true
- }
- }
- });
-
- page.$container.find( '#btn_save_team_cancel').click( function() {
- TB.Controller.do( 'Team', 'index' );
- return false;
- });
-
- page.$container.find( '#btn_save_team').click( function() {
- if ( !TB.GUI.performFormValidation( $( '#form_save_team' ) ) ) {
- return false;
- }
-
- var displayName = page.$container.find( 'input[name="team.display_name"]').val(),
- regNo = page.$container.find( 'input[name="team.reg_no"]').val(),
- teamId = page.$container.find( 'input[name="team.id"]').val(),
- category = page.$container.find( 'input[name="team.category"]').val();
-
- // Update
- TB.Service.request(
- 'Team',
- 'update',
- { display_name: displayName, reg_no : regNo, category : category },
- function(data) {
- TB.Ext.Notification.show( 'Teamänderungen erfolgreich gespeichert.', TB.Ext.Notification.TYPE_SUCCESS );
- TB.Controller.do( 'Team', 'index' );
- },
- $(this)
- );
-
- return false;
- });
- });
- },
-
- invite : function( params ) {
- TB.GUI.showLoader();
- var page = new TB.Page( 'team_invite' );
-
- TB.Service.request( 'Team', 'load', {} , function( data ) {
- data.profile = TB.Client.profile;
- TB.GUI.hideLoader();
- TB.GUI.show( page, data );
-
- page.$container.find( '#btn_invite_player_cancel').click( function() {
- TB.Controller.do( 'Team' );
- return false;
- });
-
- page.$container.find( '#btn-group-role').find( 'label' ).not( '.btn-disabled').click( function() {
- $(this).parent( "div").find( 'label.btn-primary').removeClass( 'btn-primary').addClass( 'btn-default');
- $(this).removeClass( 'btn-default').addClass( 'btn-primary');
- page.$container.find( '#btn-group-role').find( 'span.fa.fa-check').remove();
- $( this ).append( '<span class="fa fa-check"></span>' );
- });
-
- page.$container.find( '#btn_invite_player').click( function() {
- if ( !TB.GUI.performFormValidation( $( '#form_invite_player' ) ) ) {
- return false;
- }
-
- var email = page.$container.find( 'input[name="player_invitation_email"]').val(),
- firstName = page.$container.find( 'input[name="player_invitation_first_name"]').val(),
- lastName = page.$container.find( 'input[name="player_invitation_last_name"]').val(),
- role = page.$container.find( 'input[name="player_invitation_role"]:checked').val();
-
- TB.Service.request( 'Team', 'invitePlayer', {
- player_invitation_email: email,
- player_invitation_first_name: firstName,
- player_invitation_last_name: lastName,
- player_invitation_role : role
- },
- function( data ) {
- if ( data.error && 'email-already-in-team' == data.error ) {
- TB.Ext.Alert.show( 'Email vorhanden', 'Ein Buddy mit dieser Email Adresse befindet sich bereits im Team.' );
- }
- else if ( data.error && 'email-already-invited' == data.error ) {
- TB.Ext.Alert.show( 'Email Einladung', 'Eine Einladung an diese Email Adresse wurde bereits verschickt.' );
- }
- else {
- TB.Ext.Notification.show( 'Einladung wird in Kürze verschickt.', TB.Ext.Notification.TYPE_SUCCESS );
- TB.Controller.do( 'Team', 'index' );
- TB.Utils.trackEvent( 'team', 'invitation_send' );
- }
- },
- $(this)
- );
-
- return false;
- });
- });
- }
- };
|