您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

560 行
22 KiB

  1. "use strict";
  2. var TB = TB || {};
  3. TB.Control = TB.Control || {};
  4. TB.Control.Settings = {
  5. // Overview
  6. account : function( params )
  7. {
  8. TB.GUI.showLoader();
  9. var page = new TB.Page('settings_account');
  10. TB.Service.request('Account', 'getEmailChange', {}, function (data) {
  11. TB.GUI.hideLoader();
  12. if ( data && data.acc ) {
  13. TB.Client.updateSessionAccount( data.acc );
  14. }
  15. TB.GUI.show(page, {account: TB.Client.account, ec : (data.ec ? data.ec : null) });
  16. page.$container.find('#btn-change-password-cancel').click(function () {
  17. TB.Ext.Notification.show('Keine Änderungen vorgenommen.', TB.Ext.Notification.TYPE_INFO);
  18. TB.Controller.reload();
  19. });
  20. page.$container.find('#btn-change-password-submit').click(function () {
  21. if (!TB.GUI.performFormValidation($('#form_change_password'))) {
  22. return false;
  23. }
  24. TB.Service.request(
  25. 'Account',
  26. 'changePassword',
  27. $('#form_change_password').serializeObject(),
  28. function (res) {
  29. if (res && res.ok) {
  30. TB.Ext.Notification.show('Passwort erfolgreich geändert.', TB.Ext.Notification.TYPE_SUCCESS);
  31. TB.Controller.reload();
  32. } else if (res && res.nochange) {
  33. TB.Ext.Notification.show('Neues und altes Passwort sind identisch. Keine Änderungen.', TB.Ext.Notification.TYPE_WARNING);
  34. } else if (res && res.oldpasswordnok) {
  35. TB.Ext.Notification.show('Das alte Password ist nicht korrekt.', TB.Ext.Notification.TYPE_DANGER);
  36. }
  37. },
  38. $(this)
  39. );
  40. return false;
  41. });
  42. page.$container.find('#btn-change-email-cancel').click(function () {
  43. TB.Ext.Notification.show('Keine Änderungen vorgenommen.', TB.Ext.Notification.TYPE_INFO);
  44. TB.Controller.reload();
  45. });
  46. page.$container.find('#btn-change-email-submit').click(function () {
  47. if (!TB.GUI.performFormValidation($('#form_change_email'))) {
  48. return false;
  49. }
  50. TB.Service.request(
  51. 'Account',
  52. 'changeEmail',
  53. $('#form_change_email').serializeObject(),
  54. function (res) {
  55. if (res && res.ok) {
  56. TB.Ext.Notification.show('Eine Validierungsnachricht wurde an die neue Email Adresse geschickt. Bitte folge den Anweisungen in der Mail.', TB.Ext.Notification.TYPE_SUCCESS);
  57. TB.Controller.reload();
  58. } else if (res && res.nochange) {
  59. TB.Ext.Notification.show('Neue Email Adresse ist identisch mit deiner alten Adresse. Keine Änderungen.', TB.Ext.Notification.TYPE_WARNING);
  60. } else if (res && res.emailexists) {
  61. TB.Ext.Notification.show('Die Email Adresse existiert bereits im System. Wenn du mehrere Accounts zusammenlegen möchtest, wende dich bitte an den Support.', TB.Ext.Notification.TYPE_WARNING);
  62. } else if (res && res.invalidpw) {
  63. TB.Ext.Notification.show('Das eingegebene Passwort ist falsch.', TB.Ext.Notification.TYPE_WARNING);
  64. }
  65. },
  66. $(this)
  67. );
  68. return false;
  69. });
  70. });
  71. }
  72. ,
  73. premium : function( params )
  74. {
  75. TB.GUI.showLoader();
  76. var page = new TB.Page('settings_premium' ),
  77. showSuccess = params.hasOwnProperty( 'success' ) && "1" == params.success ? true : false,
  78. showCancellation = params.hasOwnProperty( 'cancellation' ) && "1" == params.cancellation ? true : false;
  79. TB.Service.request(
  80. 'Settings',
  81. 'getPremiumDetails',
  82. {},
  83. function( data )
  84. {
  85. var teamName,
  86. teams = data && data.teams && data.teams.length ? data.teams : [];
  87. if ( data && data.premium_logs && data.premium_logs.length > 0 )
  88. {
  89. teamName = '-gelöscht-';
  90. for ( var pli = 0; pli < data.premium_logs.length; pli++ )
  91. {
  92. for ( var ti = 0; ti < teams.length; ti++ )
  93. {
  94. if ( teams[ ti ].id == data.premium_logs[ pli ].team_id )
  95. {
  96. teamName = teams[ ti ].display_name;
  97. break;
  98. }
  99. }
  100. data.premium_logs[ pli ].__teamName = teamName;
  101. }
  102. }
  103. TB.GUI.show( page, data );
  104. page.$container.find( '[data-type="book-premium"]' ).on( 'click', function()
  105. {
  106. var currentTeam = TB.Client.getCurrentTeam(),
  107. premiumTeamId = $(this).attr( 'data-team-id' ),
  108. profileId;
  109. if ( premiumTeamId == currentTeam.id )
  110. {
  111. TB.Controller.do( 'Settings', 'order_premium' );
  112. }
  113. else
  114. {
  115. // Change team - redirect to Setting-order_premium, reload
  116. for ( var pi = 0; pi < TB.Client.profiles.length; pi++ )
  117. {
  118. if ( TB.Client.profiles[ pi ].team_id == premiumTeamId )
  119. {
  120. profileId = TB.Client.profiles[ pi ].id;
  121. break;
  122. }
  123. }
  124. if ( profileId )
  125. {
  126. TB.Service.request( 'Profile', 'change', { profile_id : profileId },
  127. function( data )
  128. {
  129. if ( data && data.session && data.profile && data.profiles && data.teams )
  130. {
  131. TB.Client.setSessionData( TB.Client.account, data.profile, data.session, data.profiles, data.teams );
  132. $( window ).off( 'hashchange' );
  133. TB.Controller.updateHash( 'Settings', 'order_premium' );
  134. location.reload( true );
  135. }
  136. }
  137. );
  138. }
  139. }
  140. });
  141. TB.GUI.hideLoader();
  142. if ( true === showSuccess )
  143. {
  144. TB.Ext.Alert.modal({
  145. title : 'Kauf erfolgreich abgeschlossen',
  146. text : 'Vielen Dank, dass du dich für TBuddy Premium entschieden hast.',
  147. type : 'success',
  148. showCancelButton : false
  149. });
  150. }
  151. else if ( true === showCancellation )
  152. {
  153. TB.Ext.Alert.modal({
  154. title : 'Premium Paket storniert.',
  155. text : 'Achtung. Sobald das Premium Paket abgelaufen ist, stehen dem gesamten Team die Premiumfunktionen nicht mehr zur Verfügung.',
  156. type : 'warning',
  157. showCancelButton : false
  158. });
  159. }
  160. }
  161. );
  162. }
  163. ,
  164. premium_detail : function( params )
  165. {
  166. TB.GUI.showLoader();
  167. var page = new TB.Page('settings_premium_detail' );
  168. TB.Service.request(
  169. 'Settings',
  170. 'getPremiumDetail',
  171. { premiumLogId : params.premium_log_id },
  172. function( data )
  173. {
  174. TB.GUI.show( page, data );
  175. TB.GUI.hideLoader();
  176. }
  177. );
  178. }
  179. ,
  180. premium_edit : function( params )
  181. {
  182. TB.GUI.showLoader();
  183. var page = new TB.Page('settings_premium_edit' ),
  184. premiumLogId = params.premium_log_id ? params.premium_log_id : null,
  185. $bf,
  186. billingData = {};
  187. TB.Service.request(
  188. 'Settings',
  189. 'getPremiumDetail',
  190. { premiumLogId : premiumLogId },
  191. function( data )
  192. {
  193. TB.GUI.show( page, data );
  194. page.$container.find( '[data-id="btn-cancel-subscription"]' ).first().click( function()
  195. {
  196. TB.Ext.Alert.modal(
  197. {
  198. title: "Bist du sicher, dass Du das Premium Paket stornieren möchtest?",
  199. text: "Du und dein Team verlierst damit zum nächsten Abrechnungsdatum den Premium Status und somit die Möglichkeit, die TBuddy Prmeium Funktionen nützen zu können.",
  200. confirmButtonText : 'Ja, stornieren!',
  201. type: 'warning'
  202. },
  203. function()
  204. {
  205. $("html, body").animate({ scrollTop: 0 }, "slow");
  206. TB.GUI.showLoader();
  207. TB.Service.request(
  208. 'Settings',
  209. 'cancelSubscription',
  210. {
  211. premiumLogId : premiumLogId
  212. },
  213. function( res )
  214. {
  215. TB.Controller.do( 'Settings', 'premium', { cancellation : 1 } );
  216. }
  217. );
  218. }
  219. )
  220. });
  221. page.$container.find( '[data-id="btn-update-subscription"]' ).first().click( function()
  222. {
  223. if ( !TB.GUI.performFormValidation( $( '#form_billing_address' ) ) )
  224. {
  225. TB.Ext.Alert.modal(
  226. {
  227. title: "Fehlerhafter Rechnungsempfänger",
  228. text: "Bitte kontrolliere die Eingaben im Bereich des Rechnungsempfängers.",
  229. confirmButtonText : 'Stornieren!',
  230. type: 'warning',
  231. showCancelButton: false
  232. }
  233. );
  234. return false;
  235. }
  236. // BillingForm
  237. $bf = $( '#form_billing_address' );
  238. billingData.company_name = $bf.find( 'input[name="company_name"]' ).val();
  239. billingData.tax_id = $bf.find( 'input[name="tax_id"]' ).val();
  240. billingData.first_name = $bf.find( 'input[name="first_name"]' ).val();
  241. billingData.last_name = $bf.find( 'input[name="last_name"]' ).val();
  242. billingData.street = $bf.find( 'input[name="street"]' ).val();
  243. billingData.zip_code = $bf.find( 'input[name="zip_code"]' ).val();
  244. billingData.city = $bf.find( 'input[name="city"]' ).val();
  245. billingData.email = $bf.find( 'input[name="email"]' ).val();
  246. TB.Service.request(
  247. 'Settings',
  248. 'updatePremiumDetail',
  249. {
  250. premiumLogId : premiumLogId,
  251. billingData : billingData
  252. },
  253. function( data )
  254. {
  255. TB.Ext.Notification.show(
  256. 'Daten erfolreich aktualisiert. Sie werden ab der nächsten Buchung berücksichtigt.',
  257. TB.Ext.Notification.TYPE_SUCCESS
  258. );
  259. TB.Controller.do( 'Settings', 'premium_detail', { premium_log_id : premiumLogId } );
  260. }
  261. );
  262. return false;
  263. });
  264. TB.GUI.hideLoader();
  265. }
  266. );
  267. }
  268. ,
  269. order_premium : function( params )
  270. {
  271. TB.GUI.showLoader();
  272. var page,
  273. braintreeCustomerData = null,
  274. billingData = {},
  275. $bf,
  276. selectedPremiumId = params.hasOwnProperty( 'selectedpackage' ) ? params.selectedpackage.toUpperCase() : null,
  277. activeTab = 'premium';
  278. TB.Service.request( 'Team', 'load', { addPremium : true } , function( data ) {
  279. TB.GUI.hideLoader();
  280. if ( false === TB.Premium.isValidPremiumPackage( selectedPremiumId ) )
  281. {
  282. selectedPremiumId = TB.Premium.getRecommendedPremiumPackageForTeam( data.team, data.profiles );
  283. }
  284. data.numProfiles = data.profiles.length;
  285. data.activeTab = activeTab;
  286. data.braintreeCustomerData = braintreeCustomerData;
  287. data.selectedPremiumId = selectedPremiumId;
  288. data.possiblePackages = TB.Premium.getPossiblePremiumPackagesForTeam( data.team, data.profiles );
  289. data.account = TB.Client.account;
  290. page = new TB.Page( 'settings_premium_order' );
  291. TB.GUI.show(page, data);
  292. page.$container.find( 'button[data-type="btn-premium-select"]' ).click( function()
  293. {
  294. var $btn = $(this);
  295. // Remove all active states
  296. page.$container.find( 'button.btn-premium-selected' ).each( function( i, v ) {
  297. var $btn = $(this);
  298. $btn.removeClass( 'btn-premium-selected' );
  299. $btn.find( 'span.btn-premium-selected-text' ).hide();
  300. $btn.find( 'span.btn-premium-select-text' ).show();
  301. });
  302. // Set active state to pressed button
  303. $btn.addClass( 'btn-premium-selected' );
  304. $btn.find( 'span.btn-premium-select-text' ).hide();
  305. $btn.find( 'span.btn-premium-selected-text' ).show();
  306. selectedPremiumId = $btn.attr( 'data-premium-id' );
  307. data.selectedPremiumId = selectedPremiumId;
  308. page.$container.find( '[data-id="premium-summary-container"]' ).first().html(
  309. tmpl( 'tpl_settings_premium_order_summary', { data: data } )
  310. );
  311. return false;
  312. });
  313. braintree.setup(
  314. TB.Client.BRAINTREE_CLIENT_TOKEN,
  315. //'sandbox_ddbykh5t_mmr6s9yxbhkcf57q', // SANDBOX
  316. //'production_w8xgg4jb_4n796zqzrv66pysf', // PRODUCTION
  317. 'custom',
  318. {
  319. paypal : {
  320. container : 'paypal-container',
  321. locale : 'de_DE',
  322. displayName : 'TBuddy UG (haftungsbeschränkt)',
  323. onCancelled : function()
  324. {
  325. braintreeCustomerData = null;
  326. data.braintreeCustomerData = braintreeCustomerData;
  327. page.$container.find( '[data-id="premium-summary-container"]' ).first().html(
  328. tmpl( 'tpl_settings_premium_order_summary', { data: data } )
  329. );
  330. }
  331. },
  332. onPaymentMethodReceived : function( obj )
  333. {
  334. braintreeCustomerData = obj;
  335. data.braintreeCustomerData = braintreeCustomerData;
  336. page.$container.find( '[data-id="premium-summary-container"]' ).first().html(
  337. tmpl( 'tpl_settings_premium_order_summary', { data: data } )
  338. );
  339. }
  340. }
  341. );
  342. page.$container.find( 'button[data-id="btn-create-premium"]' ).first().click( function()
  343. {
  344. if ( !braintreeCustomerData )
  345. {
  346. TB.Ext.Alert.modal(
  347. {
  348. title: "Fehlender Paypal Account",
  349. text : "Drücke auf den Paypal-Button und wähle das Rechnungskonto aus.",
  350. type: 'warning',
  351. showCancelButton : false
  352. }
  353. );
  354. return false;
  355. }
  356. else if ( !selectedPremiumId )
  357. {
  358. TB.Ext.Alert.modal(
  359. {
  360. title: "Unbekanntes Premium Paket",
  361. text : "Das angegebene Paket scheint nicht zu existieren.",
  362. type: 'error',
  363. showCancelButton : false
  364. }
  365. );
  366. return false;
  367. }
  368. else if ( !TB.GUI.performFormValidation( $( '#form_billing_address' ) ) )
  369. {
  370. TB.Ext.Alert.modal(
  371. {
  372. title: "Fehlerhafter Rechnungsempfänger",
  373. text : "Bitte kontrolliere die Eingaben im Bereich des Rechnungsempfängers.",
  374. type: 'warning',
  375. showCancelButton : false
  376. }
  377. );
  378. return false;
  379. }
  380. else if ( false === page.$container.find( '[data-id="checkbox-billing-premium-agb"]' ).first().is( ':checked' ) )
  381. {
  382. TB.Ext.Alert.modal(
  383. {
  384. title: "Akzeptiere die AGBs",
  385. text : "Du musst die AGBs akzeptieren, bevor du die Bestellung abschicken kannst.",
  386. type: 'warning',
  387. showCancelButton : false
  388. }
  389. );
  390. return false;
  391. }
  392. else
  393. {
  394. // BillingForm
  395. $bf = $( '#form_billing_address' );
  396. billingData.company_name = $bf.find( 'input[name="company_name"]' ).val();
  397. billingData.tax_id = $bf.find( 'input[name="tax_id"]' ).val();
  398. billingData.first_name = $bf.find( 'input[name="first_name"]' ).val();
  399. billingData.last_name = $bf.find( 'input[name="last_name"]' ).val();
  400. billingData.street = $bf.find( 'input[name="street"]' ).val();
  401. billingData.zip_code = $bf.find( 'input[name="zip_code"]' ).val();
  402. billingData.city = $bf.find( 'input[name="city"]' ).val();
  403. billingData.email = $bf.find( 'input[name="email"]' ).val();
  404. $("html, body").animate({ scrollTop: 0 }, "slow");
  405. TB.GUI.showLoader();
  406. TB.Service.request(
  407. 'Team',
  408. 'createPremium',
  409. {
  410. billingData : billingData,
  411. braintreeCustomerData : braintreeCustomerData,
  412. packageId : selectedPremiumId
  413. },
  414. function( data )
  415. {
  416. var pageSuccess;
  417. if ( data && data.team )
  418. {
  419. TB.Client.updateSessionTeam( data.team );
  420. }
  421. TB.Utils.trackEvent( 'premium', 'booked' );
  422. TB.Controller.do( 'Settings', 'premium', { success : 1 } );
  423. }
  424. );
  425. }
  426. });
  427. });
  428. }
  429. ,
  430. billing : function( params )
  431. {
  432. TB.GUI.showLoader();
  433. var page = new TB.Page('settings_billing' );
  434. TB.Service.request(
  435. 'Settings',
  436. 'getBilling',
  437. {},
  438. function( data )
  439. {
  440. TB.GUI.show( page, data );
  441. page.$container.find( '[data-invoice-id]' ).click( function()
  442. {
  443. TB.Controller.do( 'Settings', 'billingdetail', { bid : $(this).attr( 'data-invoice-id' ) } );
  444. });
  445. TB.GUI.hideLoader();
  446. }
  447. );
  448. }
  449. ,
  450. billingdetail : function( params )
  451. {
  452. var billingId = params.bid || null;
  453. TB.GUI.showLoader();
  454. var page = new TB.Page('settings_billing_detail' );
  455. TB.Service.request(
  456. 'Settings',
  457. 'getBillingDetail',
  458. { id : billingId },
  459. function( data )
  460. {
  461. TB.GUI.show( page, data );
  462. page.$container.find( '[data-id="btn-invoice-print"]' ).click( function()
  463. {
  464. window.print();
  465. });
  466. TB.GUI.hideLoader();
  467. }
  468. );
  469. }
  470. };