-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEvent.js
More file actions
78 lines (69 loc) · 2.25 KB
/
Event.js
File metadata and controls
78 lines (69 loc) · 2.25 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
/**
* Возвращает объект Event
*
* @param {String} [name = "Событие"] Имя события
* @param {String} [address = ""] Адресс события
* @param {Object} time Дата события
* @param {Array} member Участники
* @param {Number} [raiting=3] Важность события (по шкале от 0 до 5)
*
* @example
* Event(
* "Совещание", "Екатеринбург, ул. Тургенева, д. 4, ауд. 150",
* EventTime(new Date(2011, 10, 10, 14, 48, 00), 60), ["я"], 5)
*
* @see EventTime
*/
var Event = function (name, address, time, member, raiting) {
"use strict";
Model.call(this);
var myTime = time || new EventTime(new Date(), 60);
this.set({
name: name || "Событие",
address: address || "",
timeStart: myTime.start,
timeLength: myTime.length,
member: member || [],
raiting: +raiting || 3
});
}
inherits(Event, Model);
Event.prototype.constructor = Event;
/**
* Возвращает объект EventTime
*
* @private
* @param {Number|Date} start Начало события
* @param {Number} [length=0] Длительность события в минутрах
*
* @example
* EventTime(new Date(2011, 10, 10, 14, 48, 00), 60)
*
* @return {Object}
*/
function EventTime(start, length) {
"use strict";
return {
"start": +start,
"length": +length || 0
};
}
/**
* Валидация собития
*
* @return {Array} Список ошибок
*/
Event.prototype.validate = function () {
"use strict";
var errors = [];
if (this.get("timeLength") < 0) {
errors.push("Продолжительность события меньше допустимой величины");
}
if (this.get("raiting") < 0) {
errors.puch("Рэйтинг собития меньше допустимой величины");
}
else if (this.get("raiting") > 5) {
errors.push("Рэйтинг события больше допустимой величины");
}
return errors;
};