-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADataProvider.js
116 lines (103 loc) · 2.79 KB
/
ADataProvider.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
(function (ns) {
"use strict";
/**
* @name wader.ADataProvider
* @class Wader Abstract Data Provider
* @abstract
* @author sc0rp10 <dev@weblab.pro>
* @version 0.3
*/
$.Class.extend("wader.ADataProvider",
/** @lends wader.ADataProvider */
{
errorHandlers: {
"critical": [],
"error": [],
"notice": [],
"login": []
},
/**
* @param {String} level
* @param {Function} callback
* @return {undefined}
*/
addErrorHandler: function (level, callback) {
if (level in this.errorHandlers) {
this.errorHandlers[level].push(callback);
};
},
/**
* @param {String} level
* @param {*} data
* @return {undefined}
*/
handleError: function (level, data) {
if (level in this.errorHandlers) {
this.errorHandlers[level].forEach(function (cb) {
cb(data);
});
};
}
},
/** @lends wader.ADataProvider# */
{
/*
* @var resourse {String} общий ключ объектов, например, таблица в БД
*/
resource: null,
/**
* @param {String} resource
* @return {undefined}
*/
init: function (resource) {
this.resource = resource;
},
/**
* @param {String} key
* @return {$.Deferred}
*/
get: function (key) {
return this._makeRequest("get", key);
},
/**
* @param {String} key
* @param {String} value
* @return {$.Deferred}
*/
set: function (key, value) {
return this._makeRequest("post", key, value);
},
/**
* @param {String} key
* @param {String} value
* @return {$.Deferred}
*/
update: function (key, value) {
return this._makeRequest("put", key, value);
},
/**
* @param {String} key
* @return {$.Deferred}
*/
remove: function (key) {
return this._makeRequest("delete", key);
},
/**
* @param {String} filter
* @return {$.Deferred}
*/
getMulti: function (filter) {
return this._makeRequest("getMulti", filter);
},
/**
* @abstract
* @return {$.Deferred}
*/
_makeRequest: function () {
throw new Error(this.constructor.fullName + ": не реализован метод _makeRequest");
}
});
if (ns !== wader) {
ns.ADataProvider = wader.ADataProvider;
}
})(window.WADER_NS || window);