-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProtocol.js
More file actions
123 lines (109 loc) · 3.58 KB
/
Protocol.js
File metadata and controls
123 lines (109 loc) · 3.58 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
/**
* Класс соблюдения протокола общения с фронтендом.
* Отправляет на клиент данные по установленому протоколу.
*/
Ext.define('B.Protocol', {
statics: {
/**
* Отправляет сообщение с данными.
* @param {Object} response Объект ответа Express.
* @param {Array} data Массив данных.
*/
sendData: function (response, data) {
new this({
expressResponse: response
}).sendData(data);
},
/**
* Отправляет сообщение об успешном выполнении действия.
* @param {Object} response Объект ответа Express.
*/
sendSuccess: function (response) {
new this({
expressResponse: response
}).sendSuccess();
},
/**
* Отправляет сообщение об ошибке.
* @param {Object} response Объект ответа Express.
* @param {String} error Текст ошибки.
*/
sendError: function (response, error) {
new this({
expressResponse: response
}).sendError(error);
},
/**
* Отправляет сообщение об ошибке доступа.
* @param {Object} response Объект ответа Express.
*/
sendAccessDenied: function (response) {
new this({
expressResponse: response
}).sendAccessDenied();
},
/**
* Отправляет сообщение о неверных параметрах запроса.
* @param {Object} response Объект ответа Express.
*/
sendInvalidParams: function (response) {
new this({
expressResponse: response
}).sendInvalidParams();
}
},
config: {
/**
* @cfg {Object} expressResponse Объект ответа Express.
*/
expressResponse: null
},
constructor: function (config) {
this.initConfig(
Ext.apply(
Ext.clone(this.config),
config
)
);
},
/**
* Отправляет сообщение с данными.
* @param {Array} data Массив данных.
*/
sendData: function (data) {
this.getExpressResponse().json({
data: data || [],
success: true,
error: ''
});
},
/**
* Отправляет сообщение об успешном выполнении действия.
*/
sendSuccess: function () {
this.sendData([]);
},
/**
* Отправляет сообщение об ошибке.
* @param {String} error Текст ошибки.
*/
sendError: function (error) {
this.getExpressResponse().json({
data: [],
success: false,
error: error
});
},
/**
* Отправляет сообщение об ошибке доступа.
*/
sendAccessDenied: function () {
this.sendError('Доступ запрещен!');
},
/**
* Отправляет сообщение о неверных параметрах запроса.
*/
sendInvalidParams: function () {
this.sendError('Неверные параметры запроса!');
}
});