sc | funnels form model 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
mcp.FunnelFormModel = function (config) {
var self = this;
self.funnelUrl = config.funnelUrl;
self.uniquenessServiceConfig = {
'url': config.uniquenessUrl,
'coll': 'app_funnels',
'name': 'name'
};
self.errors = ko.observableArray([]);
self.funnelName = ko.observable('');
self.checkParams = function() {
if (self.funnelName() === '') {
self.errors.push('Name field is required.');
} else {
if (!(self.checkNameUniqueness())){
self.errors.push('Funnel with name: "' + self.funnelName() + '" already exists.');
}
}
return (!(self.errors().length)) ? true : false;
}
self.checkNameUniqueness = function() {
console.log('!!! checkNameUniqueness: ');
params = {
'coll': self.uniquenessServiceConfig['coll'],
'name': self.uniquenessServiceConfig['name'],
'value': self.funnelName()
};
$.get(self.uniquenessServiceConfig['url'], params, function(response, textStatus, jqXHR) {
if (response.data) {
if (response.data.length)) {
return false;
}
}
}, 'json' );
return true;
}
self.save = function() {
self.errors([]);
if (self.checkParams()) {
console.log('Everything is correct!');
} else {
console.log('We have errors!');
console.log('Errors: ', self.errors());
}
// $.post(self.funnelUrl, params, function(response, textStatus, jqXHR) {
// console.log('response');
// }, 'json' );
}
}