/
hangout-clone.js
161 lines (142 loc) · 4.93 KB
/
hangout-clone.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
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
import QuillEditor from "../../libs/QuillEditor";
Template.cloneHangoutModal.onCreated(function() {
this.subscribe("myStudyGroups");
});
Template.cloneHangoutModal.onRendered(function() {
var templateInstance = Template.instance();
var editorHostElement = templateInstance.$("[data-editor-host]").get(0);
var start = this.$("#start-date-time-picker");
templateInstance.editor = QuillEditor.createEditor({
container: editorHostElement
});
templateInstance.editor.setContents(
templateInstance.data.hangout.data.description_in_quill_delta || templateInstance.data.hangout.data.description
);
//instructions for start date time picker
start.datetimepicker({
ignoreReadonly: true,
widgetPositioning: { horizontal: "auto", vertical: "bottom" },
minDate: new Date()
});
//whether external checkbox is checked
const external_fields = $("#external-fields");
if ($("input#external-checkbox").is(":checked") === true) {
external_fields.show();
} else {
external_fields.hide();
}
const instance = this;
instance.autorun(() => {
let roles = Meteor.user().roles;
let studyGroupsKeys = [];
Object.entries(roles).forEach(([key, value]) => {
if (value.includes("owner") || value.includes("admin") || (value.includes("moderator") && key !== "CB")) {
studyGroupsKeys.push(key);
} else if (value.includes("member") && key !== "CB") {
// check for exempt_from_default_permission
if (StudyGroups.findOne({ _id: key }) && StudyGroups.findOne({ _id: key }).exempt_from_default_permission) {
studyGroupsKeys.push(key);
}
}
});
let studyGroups = [{ id: "CB", text: "CodeBuddies Default" }];
StudyGroups.find({ _id: { $in: studyGroupsKeys } }).forEach(sg => {
studyGroups.push({ id: sg._id, text: sg.title });
});
Meteor.setTimeout(function() {
instance.$(".study-group-single", studyGroups).select2({
placeholder: "Select a group you organize",
data: studyGroups
});
const groupId = templateInstance.data.hangout.data.group.id || "";
if (groupId !== "") {
instance
.$(".study-group-single")
.val(groupId)
.trigger("change");
}
}, 1500);
});
});
Template.cloneHangoutModal.events({
"click input#external-checkbox": function(event) {
$("#external-fields").toggle();
},
"click #clone-hangout": function(e) {
var templateInstance = Template.instance();
const topic = $("#topic").val();
const description = QuillEditor.generatePlainTextFromDeltas(templateInstance.editor.getContents());
const description_in_quill_delta = templateInstance.editor.getContents();
const start = $("#start-date-time").val();
const startDate = new Date(start);
// If date was not set, return 24 hours later. Else, return end date time
const duration = Number($("#end-date-time").val()) || 1440;
const end = new Date(startDate.getTime() + 1000 * 60 * duration);
const type = $('input[name="hangout-type"]:checked').val();
const groupId = $(".study-group-single").val();
const externalCheckbox = $('input[name="externalCheckbox"]').prop("checked");
const externalButtonText = $('input[name="externalButtonText"]').val();
const externalURL = $('input[name="externalURL"]').val();
const data = {
topic: topic,
slug: topic.replace(/\s+/g, "-").toLowerCase(),
description: description,
description_in_quill_delta: description_in_quill_delta,
start: new Date(start),
end: new Date(end),
duration: duration,
type: type,
groupId: groupId,
externalCheckbox: externalCheckbox,
externalButtonText: externalButtonText,
externalURL: externalURL
};
if ($.trim(start) == "") {
swal({
title: TAPi18n.__("select_start_time"),
confirmButtonText: TAPi18n.__("ok"),
type: "error"
});
return;
}
if ($.trim(topic) == "") {
$("#topic").focus();
swal({
title: TAPi18n.__("enter_topic"),
confirmButtonText: TAPi18n.__("ok"),
type: "error"
});
return;
}
if ($.trim(groupId) == "") {
$(".study-group-single").focus();
swal({
title: TAPi18n.__("select_study_group"),
confirmButtonText: TAPi18n.__("ok"),
type: "error"
});
}
if ($.trim(description) == "") {
$("#description").focus();
swal({
title: TAPi18n.__("enter_description"),
confirmButtonText: TAPi18n.__("ok"),
type: "error"
});
return;
}
Meteor.call("createHangout", data, function(err, result) {
if (result) {
Modal.hide();
swal({
title: TAPi18n.__("hangout_created_title"),
text: TAPi18n.__("hangout_created_message"),
confirmButtonText: TAPi18n.__("ok"),
type: "success",
closeOnConfirm: true
});
FlowRouter.go("hangouts");
}
});
}
});