-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodeacross2016.js
136 lines (112 loc) · 3.48 KB
/
codeacross2016.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
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
Events = new Mongo.Collection('events');
Accounts.config({
forbidClientAccountCreation : true,
})
if (Meteor.isClient) {
Accounts.ui.config({
passwordSignupFields: 'USERNAME_ONLY',
});
$.cloudinary.config({
cloud_name: "lets"
});
Template.body.helpers({
events: function () {
return Events.find({});
}
});
Template.body.events({
"click .seja-parceiro": function (event) {
alert('Bela iniciativa! Entre em contato conosco para conversar sobre parceiria [<o>] ')
},
"click .buy-drink": function (event) {
alert('Obrigado! Olha nossos próximos eventos no Meetup e vêm compartilhar este drink conosco :D !')
},
"submit .new-event": function (event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form element
var name = event.target.name.value;
var datetime = event.target.datetime.value;
var website = event.target.website.value;
var images = event.target.image.files;
var description = event.target.description.value;
var city = event.target.city.value;
var place = event.target.place.value;
var address = event.target.address.value;
var contato = event.target.contato.value;
var email = event.target.email.value;
if (name && datetime && contato && email && description && images) {
// Insert an event into the collection
event_id = Events.insert({
name: name,
datetime: datetime,
website: website,
description: description,
city: city,
place: place,
address: address,
contato: contato,
email: email,
createdAt: new Date() // current time
});
Cloudinary.upload(images, {}, function(err, res) {
if (err) {
alert("A imagem não foi carregada.");
} else {
if (res.public_id) {
Events.update(event_id, {
$set: { image: res.public_id }
});
console.log('Image ' + res.public_id + ' saved');
}
}
});
// Clear form
event.target.name.value = "";
event.target.datetime.value = "";
event.target.website.value = "";
event.target.imagepath.value = "";
event.target.description.value = "";
event.target.city.value = "";
event.target.place.value = "";
event.target.address.value = "";
event.target.contato.value = "";
event.target.email.value = "";
alert('Demais! O seu evento foi inserido. Confere a lista dos eventos acima.')
} else {
alert("Por favor preencher todos os campos requiridos");
}
}
});
Template.event.helpers({
isAdmin: function() {
return Meteor.user();
},
descriptionHtml: function() {
return this.description.replace(/\r?\n/g, "<br>");
},
});
Template.event.events({
"click .delete": function () {
if (confirm('Tem certeza que deseja deletar "' + this.name + '"')) {
Events.remove(this._id);
}
}
});
}
if (Meteor.isServer) {
Cloudinary.config({
cloud_name: 'lets',
api_key: '924521254223698',
api_secret: 's2GiPJ4TVqUzvDXCSxUY6oPTunY'
});
Meteor.startup(function () {
// code to run on server at startup
if (Accounts.findUserByUsername("admin") == null) {
Accounts.createUser({
"username": "admin",
"password": "CC2016"
});
}
});
}