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
124
|
function showAddNewGoal()
{
$("#GoalForm").show();
$("#EditGoals").hide();
$.scrollTo("#AddEditGoals", 400);
return false;
}
function showEditGoals()
{
$("#EditGoals").show();
$("#GoalForm").hide();
$.scrollTo("#AddEditGoals", 400);
return false;
}
// init the goal form with existing goal value, if any
function initGoalForm(goalMethodAPI, submitText, goalName, matchAttribute, pattern, patternType, caseSensitive, revenue, goalId)
{
$('#goal_name').val(goalName);
$('input[@name=match_attribute][value='+matchAttribute+']').attr('checked', true);
$('#match_attribute_name').html(mappingMatchTypeName[matchAttribute]);
$('#examples_pattern').html(mappingMatchTypeExamples[matchAttribute]);
$('option[value='+patternType+']').attr('selected', true);
$('input[name=pattern]').val(pattern);
$('#case_sensitive').attr('checked', caseSensitive);
$('input[name=revenue]').val(revenue);
$('input[name=methodGoalAPI]').val(goalMethodAPI);
$('#goal_submit').val(submitText);
if(goalId != undefined) {
$('input[name=goalIdUpdate]').val(goalId);
}
}
function initAndShowAddGoalForm()
{
initGoalForm('Goals.addGoal', 'Add Goal', '', 'url', '', 'contains', false, '0');
return showAddNewGoal();
}
function bindGoalForm()
{
$('input[@name=match_attribute]').click( function() {
var matchTypeId = $(this).attr('value');
$('#match_attribute_name').html(mappingMatchTypeName[matchTypeId]);
$('#examples_pattern').html(mappingMatchTypeExamples[matchTypeId]);
});
$('#goal_submit').click( function() {
// prepare ajax query to API to add goal
ajaxRequestAddGoal = getAjaxAddGoal();
$.ajax( ajaxRequestAddGoal );
return false;
});
$('a[name=linkAddNewGoal]').click( function(){
initAndShowAddGoalForm();
} );
}
function bindListGoalEdit()
{
$('a[name=linkEditGoal]').click( function() {
var goalId = $(this).attr('id');
var goal = piwik.goals[goalId];
initGoalForm("Goals.updateGoal", "Update Goal", goal.name, goal.match_attribute, goal.pattern, goal.pattern_type, (goal.case_sensitive=='0' ? false : true), goal.revenue, goalId);
showAddNewGoal();
return false;
});
$('a[name=linkDeleteGoal]').click( function() {
var goalId = $(this).attr('id');
var goalName = 'test goal';//piwik.goals[goalId][name]
if(confirm(sprintf('Are you sure you want to delete the Goal %s?','"'+goalName+'"')))
{
$.ajax( getAjaxDeleteGoal( goalId ) );
return false;
}
});
$('a[name=linkEditGoals]').click( function(){
return showEditGoals();
} );
}
function getAjaxDeleteGoal(idGoal)
{
var ajaxRequest = piwikHelper.getStandardAjaxConf();
piwikHelper.toggleAjaxLoading();
var parameters = new Object;
parameters.idSite = piwik.idSite;
parameters.idGoal = idGoal;
parameters.method = 'Goals.deleteGoal';
parameters.module = 'API';
parameters.format = 'json';
parameters.token_auth = piwik.token_auth;
ajaxRequest.data = parameters;
return ajaxRequest;
}
function getAjaxAddGoal()
{
var ajaxRequest = piwikHelper.getStandardAjaxConf();
piwikHelper.toggleAjaxLoading();
var parameters = new Object;
parameters.idSite = piwik.idSite;
parameters.name = encodeURIComponent( $('#goal_name').val() );
parameters.matchAttribute = $('input[name=match_attribute][checked]').val();
parameters.patternType = $('[name=pattern_type]').val();
parameters.pattern = encodeURIComponent( $('input[name=pattern]').val() );
parameters.caseSensitive = $('#case_sensitive').attr('checked') == true ? 1: 0;
parameters.revenue = $('input[name=revenue]').val();
parameters.idGoal = $('input[name=goalIdUpdate]').val();
parameters.method = $('input[name=methodGoalAPI]').val();
parameters.module = 'API';
parameters.format = 'json';
parameters.token_auth = piwik.token_auth;
ajaxRequest.data = parameters;
return ajaxRequest;
}
|