spacedeck_vue.js 4.22 KB
Newer Older
mntmn's avatar
mntmn committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

function boot_spacedeck() {
  console.log("booting...");
  // custom directives

  setup_directives();
  setup_whiteboard_directives();
  setup_exclusive_audio_video_playback();

  var data = {
    active_view: null,
    online: true,
    was_offline: false,
    account: "profile",
    logged_in: false,
    guest_nickname: null,
    user: {},

    active_profile: null,
    active_profile_spaces: [],
    active_dropdown: "none",

    creating_user: false,
    signup_error: null,
    login_error: null,
    password_reset_send: false,
    password_reset_error: null,
    password_reset_email: null,
    password_reset_confirm_error: null,
    reset_token: null,

    global_spinner: false
  };

  var methods = {
    activate_dropdown: function(id, evt) {
      if (this.active_dropdown == id) {
        this.active_dropdown = "none";
        return;
      }
      this.active_dropdown = id;
    },

    close_dropdown: function(evt) {
      if (evt) {
        if ($(evt.target).parents(".dropdown").length) {
          return;
        }
      }

      this.active_dropdown = "none";
    },

    translate: function() {
      return i18n.t(arguments)
    },
  };

  // mix in functions from all Spacedeck modules

  methods = _.extend(methods, SpacedeckUsers.methods);
  methods = _.extend(methods, SpacedeckWebsockets.methods);
  methods = _.extend(methods, SpacedeckSpaces.methods);
  methods = _.extend(methods, SpacedeckTeams.methods);
  methods = _.extend(methods, SpacedeckBoardArtifacts);
  methods = _.extend(methods, SpacedeckFormatting);
  methods = _.extend(methods, SpacedeckSections.methods);
  methods = _.extend(methods, SpacedeckAvatars.methods);
  methods = _.extend(methods, SpacedeckModals.methods);
  methods = _.extend(methods, SpacedeckAccount.methods);
  methods = _.extend(methods, SpacedeckRoutes);

  data = _.extend(data, SpacedeckUsers.data);
  data = _.extend(data, SpacedeckAccount.data);
  data = _.extend(data, SpacedeckWebsockets.data);
  data = _.extend(data, SpacedeckSpaces.data);
  data = _.extend(data, SpacedeckTeams.data);
  data = _.extend(data, SpacedeckSections.data);
  data = _.extend(data, SpacedeckAvatars.data);
  data = _.extend(data, SpacedeckModals.data);

  Vue.filter('select', function (array, key, operant, value) {
      var res = _.filter(array, function(e){
      var test = eval(e[key] + " " + operant + " " + value);
      return test;
    });
    return res;
  });

  Vue.filter('date', function (value, format) {
    var day = moment(value);
    return day.format(format).replace("\'", "").replace("\'", "");
  });

  Vue.filter('exceptFilter', function (array, key) {
    var filtered = _.filter(array, function(i){
      return i[key]==undefined;
    });
    return filtered;
  });

  Vue.filter('size', function (array) {
    return array.length;
  });

  Vue.filter('empty?', function (array) {
    return array.length==0;
  });

  Vue.filter('urls_to_links', function (text) {
    return urls_to_links(text);
  });

  window.spacedeck = new Vue({
    el: "body",
    data: data,
    methods: methods
  });

  var lang = "en";

  window.refreshLocale = function() {
    if (spacedeck && spacedeck.user && spacedeck.user.preferences) {
      lang = spacedeck.user.preferences.language || "en";
    } else if (window.browser_lang) {
      lang = window.browser_lang;
    }
  }

  window.refreshLocale();
  
  i18n.init({ lng: lang, resStore: window.locales }, function(err, t) {
    console.log("i18n initialized: "+lang);
  });

  window.__ = function() { 
    var params = Array.prototype.slice.call(arguments);
    params.shift();
    window.refreshLocale();
    return i18n.t(arguments[0], { postProcess: "sprintf", sprintf: params });
  };

  spacedeck.setup_section_module();
  spacedeck.load_user(function() {
    spacedeck.route();
  },function() {
    spacedeck.route();
  });

  window.addEventListener("paste", function(evt) {
    if (evt.target.nodeName=="INPUT" || (evt.target.nodeName=="TEXTAREA" && evt.target.id!="clipboard-ta") || evt.target.contenteditable) {
      // cancel
      return;
    }
    if (spacedeck.active_space) {
      spacedeck.handle_section_paste(evt);
    }
  });
}

$(document).ready(function(){
  window.smoke = smoke;
  window.alert = smoke.alert;
  
  FastClick.attach(document.body);
  boot_spacedeck();
});