forked from mitchgre/gregsList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoals.js
191 lines (157 loc) · 3.54 KB
/
goals.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
function insertGoal()
{
var object = this;
var goalText = $("#GoalToAdd")[0].value;
$.ajax
(
{
url: "butler.php",
type: "post",
dataType: "text",
data:
{
user: object.user.name,
pass: object.user.password,
func: "insertGoal",
goal: goalText
},
success: function(resp)
{
console.log(resp);
//
// clear text fields
$("#GoalToAdd")[0].value = '';
if (JSON.parse(resp) === true)
{
console.log("input worked");
// displayTable(object,[]);
getStuff(object.goals);
// object.refresh();
}
else
{
console.log("input failed");
}
} // end success function
} // end ajax data
) // end ajax function call
} // end insertGoal function
/*
Open a dialog box containing the current goals's contents.
Send them off to the server when finished.
*/
function editGoal()
{
var object = this.data;
console.log("this.sid:"); // user_goal.id
console.log(this.sid);
var link = this.sid;
var index;
// find hash index
for (var i=0; i < object.contents.length; i++)
{
if (object.contents[i].sid === link)
index = i;
}
console.log("index:"+index);
var current = object.contents[index];
// build form
var string = '<div id="goalUpdater" title="Update '+object.type+'">';
string += '<table>';
string += '<tr>';
string += '<td>value</td>';
string += '<td>';
string += '<input id="embedValue" value="'+current.value+'">';
string += '</td>';
string += '</tr>';
string += '</table></div>';
$(string).dialog
(
{
modal:true,
buttons:
{
Cancel: function()
{
$(this).dialog("close")
},
"Update":function()
{
// get values from form
var value = $("#embedValue")[0].value;
// give values to butler
$(this).dialog("close");
// emptyElement($("#postingUpdater")[0]);
var toDestroy =
[
"embedValue","goalUpdater"
];
for (var i=0; i < toDestroy.length; i++)
removeElement(toDestroy[i]);
$.ajax
(
{
url: "butler.php",
type: "post",
dataType: "text",
data:
{
user: object.parent.user.name,
pass: object.parent.user.password,
func: object.updater,
sid: link,
value: value,
},
success: function(resp)
{
console.log(resp);
//console.log(JSON.parse(resp));
//
if (JSON.parse(resp) === true)
{
console.log("removal worked");
// displayTable(object,[]);
getStuff(object);
}
else
{
console.log("removal failed");
}
}
}
);
}
}
}
);
}
function fillGoals(object,input)
{
// erase object's contents and refill them from input
object.contents = [];
var contents = object.contents;
for (var i = 0; i < input.ids.length; i++)
{
var id = input.ids[i];
var value = input.values[i];
var p = new goal(id,value);
contents.push(p);
}
displayTable(object);
displayGoalsPortlet(object);
}
function displayGoalsPortlet(object)
{
$("#goalsPortlet").empty();
var main = $("#goalsPortlet")[0];
var table = createAppendedChildToParent('table',main);
table.className += "io";
for (var i = 0; i < object.contents.length; i++)
{
var tr = createAppendedChildToParent('tr',table);
var td = createAppendedChildToParent('td',tr);
var value = object.contents[i].value;
var content = document.createTextNode(value);
td.appendChild(content);
}
}