/
jquery_rest.js
54 lines (48 loc) · 1.09 KB
/
jquery_rest.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
var utils = require("../utils")
exports.mixin = function(model) {
var fn = model.prototype
fn._destroy = function(cb) {
var self = this
$.post(model.url + "/destroy", {json: this.toJSON()}, function(text) {
cb(text == "ok")
})
}
fn._persist = function(cb) {
var self = this
$.post(model.url + "/save", {json: JSON.stringify(this.toJSON())}, function(text) {
var o = JSON.parse(text)
task.merge(o)
cb()
})
}
fn._saveStack = [
fn.validate,
fn._persist,
fn._saved
]
// model.find = function(id, cb) {
// $.get(model.url , {}, function(text) {
// cb(model.DB[id])
// }
// }
//
// model.count = function(cb) {
// var i=0;
// for(var id in model.DB) i++
// cb(i)
// }
//
// model.exists = function(id, cb) {
// cb(!!model.DB[id])
// }
//
// model.loadFromIds = function(ids, cb) {
// var ret=[];
// for(var id in ids) ret.push(model.DB[id])
// cb(ret)
// }
//
// model.all = function(cb) {
// cb(model.DB)
// }
}