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.
 
 
 
 
 

112 regels
4.3 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.News = {
  8. index : function() {
  9. TB.GUI.showLoader();
  10. var page = new TB.Page('news');
  11. TB.Service.request('News', 'get', { filter : TB.Client.getConfig( 'news_filter' ) }, function (data) {
  12. TB.GUI.hideLoader();
  13. data.news_filter = TB.Client.getConfig( 'news_filter' );
  14. // Only scroll down if there are at least 3 news
  15. if ( data && data.news.length > 2 ) {
  16. TB.GUI.show(page, data, true );
  17. } else {
  18. TB.GUI.show(page, data );
  19. }
  20. TB.GUI.updateNewsBadge(0);
  21. page.$container.find( '#btn_news_create').click( function() {
  22. TB.Controller.do( 'News', 'create' );
  23. });
  24. page.$container.find( '#btn-coach-help').click( function() {
  25. TB.GUI.showModal(
  26. "News",
  27. TB.Config.Content.helpHtml.news
  28. );
  29. });
  30. page.$container.find( 'button[data-dropdown-action="toggle-chat-filter"]' ).click( function() {
  31. if ( "all" == $(this).attr( 'data-current-val' ) ) {
  32. TB.Client.setConfig( 'news_filter', 'custom' );
  33. } else {
  34. TB.Client.setConfig( 'news_filter', 'all' );
  35. }
  36. TB.Controller.reload();
  37. });
  38. page.$container.find( 'button[data-action="delete"]').click( function() {
  39. $(this).blur();
  40. var newsId = $(this).attr( 'data-news_id' );
  41. TB.Ext.Alert.modal({
  42. title: 'Diesen Eintrag wirklich löschen?'
  43. }, function() {
  44. TB.Service.request( 'News', 'delete', { news_id : newsId }, function( data ) {
  45. if ( data.res && data.res == 'ok' ) {
  46. TB.Ext.Notification.show( 'News Eintrag erfolgreich entfernt.', TB.Ext.Notification.TYPE_SUCCESS );
  47. TB.Controller.reload();
  48. } else {
  49. TB.Ext.Notification.show( 'Ein Fehler ist aufgetreten', TB.Ext.Notification.TYPE_DANGER );
  50. }
  51. });
  52. });
  53. });
  54. page.$container.find( '#btn_news_chat').click( function() {
  55. var chatContent = $( '#chat_content').val();
  56. if ( !chatContent || 0 == chatContent.length ) {
  57. return false;
  58. }
  59. TB.Service.request( 'News', 'createChat', { content : chatContent }, function( data ) {
  60. if ( data && data.res && data.res == 'ok' ) {
  61. TB.Ext.Notification.show( 'Chat Eintrag erstellt.', TB.Ext.Notification.TYPE_SUCCESS );
  62. TB.Controller.reload();
  63. } else {
  64. TB.Ext.Notification.show( 'Ein Fehler ist aufgetreten', TB.Ext.Notification.TYPE_DANGER );
  65. }
  66. }, $(this) );
  67. return false;
  68. });
  69. });
  70. },
  71. create : function() {
  72. var page = new TB.Page( 'news_create' );
  73. TB.GUI.show( page );
  74. page.$container.find( '#btn_news_create_cancel').click( function() {
  75. TB.Controller.do('News', 'index');
  76. });
  77. page.$container.find( '#btn_news_create_submit').click( function() {
  78. if (!TB.GUI.performFormValidation($('#form_news_create'))) {
  79. return false;
  80. }
  81. var props = $('#form_news_create').serializeObject();
  82. TB.Service.request( 'News', 'create', props, function( data ) {
  83. if ( data.res = 'ok' ) {
  84. TB.Ext.Notification.show( 'News Eintrag erfolgreich erstellt.', TB.Ext.Notification.TYPE_SUCCESS );
  85. } else {
  86. TB.Ext.Notification.show( 'Ein Fehler ist aufgetreten', TB.Ext.Notification.TYPE_DANGER );
  87. }
  88. TB.Controller.do( 'News', 'index' );
  89. }, $(this) );
  90. return false;
  91. });
  92. }
  93. };