-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomForm.js
More file actions
140 lines (107 loc) · 3.75 KB
/
Copy pathCustomForm.js
File metadata and controls
140 lines (107 loc) · 3.75 KB
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
var p = MindFusion.Scheduling;
var CustomForm = function (calendar, item, type) {
p.BaseForm.call(this, calendar, item);
this._id = "CustomForm";
this._type = type;
this.headerText = "Custom Form";
this.colors = [{ value: 0, text: "white" }, { value: 1, text: "green" }, { value: 2, text: "red" }, { value: 3, text: "violet" }];
}
CustomForm.prototype = Object.create(p.BaseForm.prototype);
CustomForm.prototype.constructor = CustomForm;
CustomForm.prototype.drawContent = function () {
p.BaseForm.prototype.drawContent.call(this);
var content = this.getContent();
// create a text-area for the item subject
var control = this.createTextArea({ id: "subject", initValue: this.item.subject });
control.element.style.width = "200px";
this.addControl(control);
var row = this.row();
row.innerHTML = this.localInfo.subjectCaption;
content.appendChild(row);
row = this.row();
row.appendChild(control.element);
content.appendChild(row);
// create a drop-down list for ranks
row = this.row();
row.innerHTML = "Rank";
content.appendChild(row);
control = this.createDropDownList({ id: "rank", items: this.getLocations(), initValue: this.getItemLocationIndex(), addEmptyValue: false });
control.element.style.width = "200px";
this.addControl(control);
row = this.row();
row.appendChild(control.element);
content.appendChild(row);
// create a drop-down list for colors
row = this.row();
row.innerHTML = "Color";
content.appendChild(row);
var item = this.item;
control = this.createDropDownList({ id: "cssClass", items: this.colors, initValue: this.colors.find(c => c.text === item.cssClass).value, addEmptyValue: false });
control.element.style.width = "200px";
this.addControl(control);
row = this.row();
row.appendChild(control.element);
content.appendChild(row);
return content;
};
// create an array of objects to fill the Ranks drop-down
CustomForm.prototype.getLocations = function () {
var result = [];
this.calendar.schedule.locations.forEach(function (l, i) {
result.push({ value: i, text: l.toString() });
}, this);
return result;
}
// get the index of the current item's rank to set the value of the Ranks drop-down
CustomForm.prototype.getItemLocationIndex = function () {
if (this.item != null && this.item.location != null) {
return this.calendar._schedule.locations.items().indexOf(this.item.location);
}
return -1;
}
// override BaseForm's drawButtons method to create form buttons
CustomForm.prototype.drawButtons = function () {
var thisObj = this;
var btnSave = this.createButton({
id: "btnSave",
text: this.localInfo.saveButtonCaption,
events: {
"click": function click(e) {
return thisObj.onSaveButtonClick(e);
}
}
});
var btnCancel = this.createButton({
id: "btnCancel",
text: this.localInfo.cancelButtonCaption,
events: {
click: function click(e) {
return thisObj.onCancelButtonClick(e);
}
}
});
var buttons = this.row();
buttons.classList.add("mfp-buttons-row");
buttons.appendChild(btnSave.element);
buttons.appendChild(btnCancel.element);
return buttons;
};
CustomForm.prototype.onSaveButtonClick = function (e) {
// update the item with the form data
this.item.subject = this.getControlValue("subject");
var rankIndex = +this.getControlValue("rank");
this.item.location = this.calendar.schedule.locations.items()[rankIndex];
var colorIndex = +this.getControlValue("cssClass");
this.item.cssClass = this.colors.find(c => c.value === colorIndex).text;
// if a new item is created, add it to the schedule.items collection
if (this.type === "new")
this.calendar.schedule.items.add(this.item);
// close the form
this.closeForm();
// repaint the calendar
this.calendar.repaint(true);
};
CustomForm.prototype.onCancelButtonClick = function (e) {
// close the form
this.closeForm();
};