-
Notifications
You must be signed in to change notification settings - Fork 0
/
choco.utils.js
43 lines (38 loc) · 1.2 KB
/
choco.utils.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
var ChocoUtils = function() {
return {
// Load all the models (ajax) and call the callback method when they are all available.
// The Choco app should be launched in this callback.
loadModels: function(models, callback) {
if(models.length == 0) { callback.call(this); }
var count = 0;
_.each(models, function(model) {
model.load(function() {
count++;
if(count == models.length) { callback.call(this); }
});
});
},
// Allows you to add DELETE links to your templates.
// <a href="#/posts/XXX" verb="delete" confirm="Are you sure?">...</a>
activateDeleteLinks: function(app) {
$('a[verb=delete]').click(function() {
var confirmMsg = $(this).attr('confirm');
var a = $(this);
if(confirmMsg) {
if(confirm(confirmMsg)) {
app.runRoute(a.attr('verb'), a.attr('href'));
}
} else {
app.runRoute(a.attr('verb'), a.attr('href'));
}
return false;
});
},
// A call to this function extends all your js-models with the methods
// provided by the plugin.
modelPlugin: function(plugin) {
$.extend(Model.ClassMethods, plugin.modelsClassMethods);
$.extend(Model.InstanceMethods, plugin.modelsInstanceMethods);
}
};
}();