-
Notifications
You must be signed in to change notification settings - Fork 112
/
admin.js
78 lines (67 loc) · 2.4 KB
/
admin.js
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
"use strict";
define(function(require) {
var _ = require('underscore'),
View = require('view'),
NavbarView = require('views/navbar'),
Templates = require('templates'),
Config = require('config'),
Util = require('util'),
Moment = require('moment');
// load in tz data
require('moment-timezone');
var AdminNavbarView = NavbarView.extend({
title: 'Admin',
});
/**
* The admin View
*/
var AdminView = View.extend({
template: Templates['admin'],
events: {
'click #save-button': 'saveSettings'
},
_load: function() {
// Retrieve config.
this.App.ajax({
url: Config.api_root + 'admin',
success: this.cbLoaded(function(resp) {
this.data = resp;
// prep tz data for display
this.data['timezones'] = _.map(Moment.tz.names(), function(tz){
return {timezone: tz, selected: (tz === this.data['timezone'])};
}, this);
this.data['timezones'].unshift({timezone: '', selected: ('' === this.data['timezone']) });
this.render();
}),
complete: $.proxy(this.App.hideLoader, this.App)
});
},
_render: function() {
this.App.setTitle('Admin');
this.registerView(new AdminNavbarView(this.App), true);
this.$el.append(this.template(this.data));
Util.autosize(this.registerElement('textarea[name=announcement]'));
this.App.hideLoader();
},
saveSettings: function() {
this.App.showLoader();
var form = this.$('#admin-form');
var data = Util.serializeForm(form);
this.App.ajax({
url: Config.api_root + 'admin',
method: 'post',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
success: this.cbRendered(function(resp) {
this.App.addMessage('Update successful', 2);
this.data = resp;
}),
complete: $.proxy(function() {
this.App.hideLoader();
}, this)
});
return false;
}
});
return AdminView;
});