Commit 7963279e authored by salo's avatar salo

added projects data source

parent 26a5b7b1
{'text':'.','children': [
{"success":true, "data":
@file_json;noquote@
}
]}
}
......@@ -127,7 +127,7 @@ template::multirow foreach file_multirow {
# This is the first child of the previous item
# Increasing the level always happens in steps of 1
if {$level > $old_level} {
append file_json ",\n${indent}\tchildren:\[\n"
append file_json ",\n${indent}\t\"children\":\[\n"
}
# A group of children needs to be closed.
......@@ -153,16 +153,21 @@ template::multirow foreach file_multirow {
for {set i 0} {$i < $level} {incr i} { append indent "\t" }
if {0 == $num_children} { set leaf_json "true" } else { set leaf_json "false" }
if {"folder" == $type} { set leaf_json "false" }
set quoted_char_map {"\n" "\\n" "\r" "\\r" "\"" "\\\"" "\\" "\\\\"}
set quoted_file_name [string map $quoted_char_map $file_name]
append file_json "${indent}\{
${indent}\tid:$file_id,
${indent}\tname:\"$quoted_file_name\",
${indent}\ticonCls:\"icon-$type\",
${indent}\texpanded:$expanded,
${indent}\t\"id\":$file_id,
${indent}\t\"name\":\"$quoted_file_name\",
${indent}\t\"iconCls\":\"icon-$type\",
${indent}\t\"expanded\":$expanded,
"
if {"folder" == $type && 0 == $num_children} {
append file_json "${indent}\t\"children\":\[\],\n"
}
foreach var $valid_vars {
# Skip xml_* variables (only used by MS-File)
if {[regexp {^xml_} $var match]} { continue }
......@@ -170,9 +175,9 @@ ${indent}\texpanded:$expanded,
# Append the value to the JSON output
set value [set $var]
set quoted_value [string map $quoted_char_map $value]
append file_json "${indent}\t$var:\"$quoted_value\",\n"
append file_json "${indent}\t\"$var\":\"$quoted_value\",\n"
}
append file_json "${indent}\tleaf:$leaf_json"
append file_json "${indent}\t\"leaf\":$leaf_json"
incr ctr
set old_level $level
......@@ -188,3 +193,7 @@ while {$level < $old_level} {
for {set i 0} {$i < $old_level} {incr i} { append indent "\t" }
}
set json_string "\{\"success\": true, \"children\": $file_json \n\}\n\}\n"
ns_log Debug "file-tree.json returning ($json_string)"
doc_return 200 "application/json" $json_string
# /packages/intranet-rest-fs-openacs/www/file-tree.json.tcl
#
# Copyright (C) 2013-2018 ]project-open[
ad_page_contract {
Returns a JSON tree structure suitable for batch-loading a project TreeStore
@param object_id ]po[ Business Object to which the FS belongs.
0 identifies the global "Home" FS
@author frank.bergmann@project-open.com
@param node Passed by ExtJS to load sub-trees of a tree.
Normally not used, just in case of error.
} {
}
set user_id [auth::require_login]
set query {
select
project_id,
project_nr,
project_name
from
acs_rels r,
im_projects p
where
p.parent_id is null
and r.object_id_one = p.project_id
and r.object_id_two = :user_id
}
set json_projects [list]
db_foreach projects_list $query {
lappend json_projects [util::json::object::create [list \
project_id $project_id \
project_nr $project_nr \
project_name $project_name \
expanded false \
leaf true \
]]
}
set json_string [util::json::gen [util::json::object::create [list \
success true \
children [util::json::array::create $json_projects] \
]]]
doc_return 200 "application/json" $json_string
# vi:set expandtab shiftwidth=4 softtabstop=4 :
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