Commit c40d576c authored by Frank Bergmann's avatar Frank Bergmann

- Sencha TT:

    - Changed the way asynchronous AJAX calls return values
parent 58f13ccd
......@@ -107,7 +107,8 @@ ad_proc -private im_rest_post_object_type_im_project {
# Write Audit Trail
im_project_audit -project_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
return [array get hash_array]
}
......@@ -232,7 +233,9 @@ ad_proc -private im_rest_post_object_type_im_ticket {
im_project_audit -project_id $rest_oid -action create
ns_log Notice "im_rest_post_object_type_im_ticket: Successfully created object with object_id=$rest_oid"
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(ticket_id) $rest_oid
return [array get hash_array]
}
......@@ -338,7 +341,9 @@ ad_proc -private im_rest_post_object_type_im_timesheet_task {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(task_id) $rest_oid
return [array get hash_array]
}
......@@ -421,7 +426,9 @@ ad_proc -private im_rest_post_object_type_im_trans_task {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(task_id) $rest_oid
return [array get hash_array]
}
......@@ -572,7 +579,9 @@ ad_proc -private im_rest_post_object_type_im_company {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(company_id) $rest_oid
return [array get hash_array]
}
......@@ -678,7 +687,9 @@ ad_proc -private im_rest_post_object_type_im_user_absence {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(absence_id) $rest_oid
return [array get hash_array]
}
# --------------------------------------------------------
......@@ -861,7 +872,11 @@ ad_proc -private im_rest_post_object_type_user {
im_audit -user_id $user_id -object_type $rest_otype -object_id $new_user_id -action create
return $new_user_id
set rest_oid $new_user_id
set hash_array(rest_oid) $rest_oid
set hash_array(user_id) $rest_oid
return [array get hash_array]
}
......@@ -965,7 +980,9 @@ ad_proc -private im_rest_post_object_type_im_invoice {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(invoice_id) $rest_oid
return [array get hash_array]
}
......@@ -998,7 +1015,9 @@ ad_proc -private im_rest_post_object_type_im_trans_invoice {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(invoice_id) $rest_oid
return [array get hash_array]
}
......@@ -1095,7 +1114,9 @@ ad_proc -private im_rest_post_object_type_im_invoice_item {
# No audit here, invoice_item is not a real object
# im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(item_id) $rest_oid
return [array get hash_array]
}
......@@ -1184,7 +1205,9 @@ ad_proc -private im_rest_post_object_type_im_hour {
# Not a real object, so no audit!
# im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(hour_id) $rest_oid
return [array get hash_array]
}
......@@ -1329,7 +1352,9 @@ ad_proc -private im_rest_post_object_type_membership_rel {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(rel_id) $rest_oid
return [array get hash_array]
}
......@@ -1406,7 +1431,9 @@ ad_proc -private im_rest_post_object_type_im_biz_object_member {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(rel_id) $rest_oid
return [array get hash_array]
}
......@@ -1482,7 +1509,9 @@ ad_proc -private im_rest_post_object_type_im_ticket_ticket_rel {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(rel_id) $rest_oid
return [array get hash_array]
}
......@@ -1557,7 +1586,9 @@ ad_proc -private im_rest_post_object_type_im_key_account_rel {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(rel_id) $rest_oid
return [array get hash_array]
}
......@@ -1631,6 +1662,8 @@ ad_proc -private im_rest_post_object_type_im_company_employee_rel {
im_audit -user_id $user_id -object_type $rest_otype -object_id $rest_oid -action create
return $rest_oid
set hash_array(rest_oid) $rest_oid
set hash_array(rel_id) $rest_oid
return [array get hash_array]
}
......@@ -959,7 +959,7 @@ ad_proc -private im_rest_get_object_type {
json {
# Calculate the total number of objects
set total [db_string total "select count(*) from ($unlimited_sql) t" -default 0]
set result "{\"success\": true,\n\"total\": $total,\n\"message\": \"Data loaded\",\n\"data\": \[\n$result\n\]\n}"
set result "{\"success\": true,\n\"total\": $total,\n\"message\": \"im_rest_get_object_type: Data loaded\",\n\"data\": \[\n$result\n\]\n}"
doc_return 200 "text/html" $result
return
}
......@@ -1288,7 +1288,7 @@ ad_proc -private im_rest_get_im_categories {
}
json {
# Deal with different JSON variants for different AJAX frameworks
set result "{\"success\": true,\n\"message\": \"Data loaded\",\n\"data\": \[\n$result\n\]\n}"
set result "{\"success\": true,\n\"message\": \"im_rest_get_im_categories: Data loaded\",\n\"data\": \[\n$result\n\]\n}"
doc_return 200 "text/html" $result
return
}
......@@ -1420,13 +1420,17 @@ ad_proc -private im_rest_post_object_type {
if {0 != [llength [info commands im_rest_post_object_type_$rest_otype]]} {
ns_log Notice "im_rest_post_object_type: Before calling im_rest_post_object_type_$rest_otype"
set rest_oid [eval [list im_rest_post_object_type_$rest_otype \
array set hash_array [eval [list im_rest_post_object_type_$rest_otype \
-format $format \
-user_id $user_id \
-content $content \
-rest_otype $rest_otype \
]]
ns_log Notice "im_rest_post_object_type: After calling im_rest_post_object_type_$rest_otype. rest_oid=$rest_oid"
# Extract the object's id from the return array and write into object_id in case a client needs the info
set rest_oid $hash_array(rest_oid)
set hash_array(object_id) $rest_oid
ns_log Notice "im_rest_post_object_type: After calling im_rest_post_object_type_$rest_otype: rest_oid=$rest_oid, hash_array=[array get hash_array]"
switch $format {
html {
......@@ -1438,9 +1442,16 @@ ad_proc -private im_rest_post_object_type {
</table>[im_footer]
"
}
json {
set data "\[{\"object_id\": $rest_oid}\]"
set result "{\"success\": true,\n\"message\": \"Object created\",\n\"data\": $data\n\n}"
json {
# Return a JSON structure with all fields of the object.
set data_list [list]
foreach key [array names hash_array] {
set value $hash_array($key)
lappend data_list "\"$key\": \"[ns_quotehtml $value]\""
}
set data "\[{[join $data_list ", "]}\]"
set result "{\"success\": \"true\",\"message\": \"Object updated\",\"data\": $data}"
doc_return 200 "text/html" $result
}
xml {
......@@ -1523,8 +1534,17 @@ ad_proc -private im_rest_post_object {
"
}
json {
set data "\[{\"object_id\": $rest_oid}\]"
set result "{\"success\": true,\n\"message\": \"Object created\",\n\"data\": $data\n\n}"
# Empty data: The empty array is necessary for Sencha in order to call callbacks
# without error. However, adding data here will create empty records in the store later,
# so the array needs to be empty.
set data_list [list]
foreach key [array names hash_array] {
set value $hash_array($key)
lappend data_list "\"$key\": \"[ns_quotehtml $value]\""
}
set data "\[{[join $data_list ", "]}\]"
set result "{\"success\": \"true\",\"message\": \"Object updated\",\"data\": $data}"
doc_return 200 "text/html" $result
}
xml {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment