spacedeck_vue.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. function boot_spacedeck() {
  2. console.log("booting...");
  3. // custom directives
  4. setup_directives();
  5. setup_whiteboard_directives();
  6. setup_exclusive_audio_video_playback();
  7. var data = {
  8. active_view: null,
  9. online: true,
  10. was_offline: false,
  11. account: "profile",
  12. logged_in: false,
  13. guest_nickname: null,
  14. user: {},
  15. active_profile: null,
  16. active_profile_spaces: [],
  17. active_dropdown: "none",
  18. creating_user: false,
  19. signup_error: null,
  20. login_error: null,
  21. password_reset_send: false,
  22. password_reset_error: null,
  23. password_reset_email: null,
  24. password_reset_confirm_error: null,
  25. reset_token: null,
  26. global_spinner: false
  27. };
  28. var methods = {
  29. activate_dropdown: function(id, evt) {
  30. if (this.active_dropdown == id) {
  31. this.active_dropdown = "none";
  32. return;
  33. }
  34. this.active_dropdown = id;
  35. },
  36. close_dropdown: function(evt) {
  37. if (evt) {
  38. if ($(evt.target).parents(".dropdown").length) {
  39. return;
  40. }
  41. }
  42. this.active_dropdown = "none";
  43. },
  44. translate: function() {
  45. return i18n.t(arguments)
  46. },
  47. };
  48. // mix in functions from all Spacedeck modules
  49. methods = _.extend(methods, SpacedeckUsers.methods);
  50. methods = _.extend(methods, SpacedeckWebsockets.methods);
  51. methods = _.extend(methods, SpacedeckSpaces.methods);
  52. methods = _.extend(methods, SpacedeckTeams.methods);
  53. methods = _.extend(methods, SpacedeckBoardArtifacts);
  54. methods = _.extend(methods, SpacedeckFormatting);
  55. methods = _.extend(methods, SpacedeckSections.methods);
  56. methods = _.extend(methods, SpacedeckAvatars.methods);
  57. methods = _.extend(methods, SpacedeckModals.methods);
  58. methods = _.extend(methods, SpacedeckAccount.methods);
  59. methods = _.extend(methods, SpacedeckRoutes);
  60. data = _.extend(data, SpacedeckUsers.data);
  61. data = _.extend(data, SpacedeckAccount.data);
  62. data = _.extend(data, SpacedeckWebsockets.data);
  63. data = _.extend(data, SpacedeckSpaces.data);
  64. data = _.extend(data, SpacedeckTeams.data);
  65. data = _.extend(data, SpacedeckSections.data);
  66. data = _.extend(data, SpacedeckAvatars.data);
  67. data = _.extend(data, SpacedeckModals.data);
  68. Vue.filter('select', function (array, key, operant, value) {
  69. var res = _.filter(array, function(e){
  70. var test = eval(e[key] + " " + operant + " " + value);
  71. return test;
  72. });
  73. return res;
  74. });
  75. Vue.filter('date', function (value, format) {
  76. var day = moment(value);
  77. return day.format(format).replace("\'", "").replace("\'", "");
  78. });
  79. Vue.filter('exceptFilter', function (array, key) {
  80. var filtered = _.filter(array, function(i){
  81. return i[key]==undefined;
  82. });
  83. return filtered;
  84. });
  85. Vue.filter('size', function (array) {
  86. return array.length;
  87. });
  88. Vue.filter('empty?', function (array) {
  89. return array.length==0;
  90. });
  91. Vue.filter('urls_to_links', function (text) {
  92. return urls_to_links(text);
  93. });
  94. window.spacedeck = new Vue({
  95. el: "body",
  96. data: data,
  97. methods: methods
  98. });
  99. var lang = "en";
  100. window.refreshLocale = function() {
  101. if (spacedeck && spacedeck.user && spacedeck.user.preferences) {
  102. lang = spacedeck.user.preferences.language || "en";
  103. } else if (window.browser_lang) {
  104. lang = window.browser_lang;
  105. }
  106. }
  107. window.refreshLocale();
  108. i18n.init({ lng: lang, resStore: window.locales }, function(err, t) {
  109. console.log("i18n initialized: "+lang);
  110. });
  111. window.__ = function() {
  112. var params = Array.prototype.slice.call(arguments);
  113. params.shift();
  114. window.refreshLocale();
  115. return i18n.t(arguments[0], { postProcess: "sprintf", sprintf: params });
  116. };
  117. spacedeck.setup_section_module();
  118. spacedeck.load_user(function() {
  119. spacedeck.route();
  120. },function() {
  121. spacedeck.route();
  122. });
  123. window.addEventListener("paste", function(evt) {
  124. if (evt.target.nodeName=="INPUT" || (evt.target.nodeName=="TEXTAREA" && evt.target.id!="clipboard-ta") || evt.target.contenteditable) {
  125. // cancel
  126. return;
  127. }
  128. if (spacedeck.active_space) {
  129. spacedeck.handle_section_paste(evt);
  130. }
  131. });
  132. }
  133. document.addEventListener("DOMContentLoaded",function() {
  134. window.smoke = smoke;
  135. window.alert = smoke.alert;
  136. FastClick.attach(document.body);
  137. boot_spacedeck();
  138. });