Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-rest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-rest
Commits
44a684c9
Commit
44a684c9
authored
Apr 30, 2016
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Removed non-finished file
parent
d72fd068
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
159 deletions
+0
-159
cost-center-tree.json.tcl
www/data-source/cost-center-tree.json.tcl
+0
-159
No files found.
www/data-source/cost-center-tree.json.tcl
deleted
100644 → 0
View file @
d72fd068
# /packages/sencha-rest/www/cost-center-tree.json.tcl
#
# Copyright (C
)
2013
]
project-open
[
ad_page_contract
{
Returns a JSON tree structure suitable for batch-loading a cost center TreeStore
@param cost_center_id The top cost center
@author frank.bergmann@cost_center-open.com
}
{
{
cost_center_id:integer 0
}
{
debug_p 0
}
}
# --------------------------------------------
# Security & Permissions
#
set
current_user_id
[
auth::require_login
]
if
{
""
==
$cost
_center_id || 0 ==
$cost
_center_id
}
{
# Use the topmost cost center as the base
set cost_center_id
[
im_cost_center_company
]
}
im_cost_center_permissions
$current
_user_id
$cost
_center_id view read write admin
if
{
!$read
}
{
im_rest_error -format
"json"
-http_status 403 -message
"You (user #
$current
_user_id) have no permissions to read cost_center #
$cost
_center_id"
ad_script_abort
}
set
top_cc_id
$cost
_center_id
set
top_cc_code
[
util_memoize
[
list
db_string top_cc_code
"select im_cost_center_code_from_id(
$top
_cc_id) from dual"
]]
set
top_cc_code_len
[
string
length
$top
_cc_code
]
set
top_cc_level
[
expr
(
$top
_cc_code_len / 2
)
- 1
]
# Get all the variables valid for timesheet cost_center
set
valid_vars
[
util_memoize
[
list
im_rest_object_type_columns -deref_p 0 -rest_otype
"im_cost_center"
]]
set
valid_vars
[
lsort
-unique
$valid
_vars
]
set
cost_centers_sql
"
select cc.*,
o.*,
length(cc.cost_center_code) / 2 - :top_cc_level as level,
CASE WHEN bts.open_p = 'o' THEN 'true' ELSE 'false' END as expanded,
(select count(*) from im_cost_centers child where child.parent_id = cc.cost_center_id) as num_children
from acs_objects o,
im_cost_centers cc
LEFT OUTER JOIN im_biz_object_tree_status bts ON (
cc.cost_center_id = bts.object_id and
bts.page_url = 'default' and
bts.user_id = :current_user_id
)
where cc.cost_center_id = o.object_id and
substring(cc.cost_center_code for :top_cc_code_len) = :top_cc_code
order by cc.cost_center_code
"
# Read the query into a Multirow, so that we can order
# it according to sort_order within the individual sub-levels.
db_multirow cost_center_multirow cost_center_list
$cost
_centers_sql
{
# By default keep the main project
"open"
.
if
{
""
==
$parent
_id
}
{
set expanded
"true"
}
}
set
title
""
set
cost_center_json
""
set
ctr 0
set
old_level 1
set
indent
""
template::multirow foreach cost_center_multirow
{
ns_log Notice
"cost-center-tree.json.tcl: cost_center_id=
$cost
_center_id"
if
{
$debug
_p
}
{
append cost_center_json
"
\n
// finish: ctr=
$ctr
, level=
$level
, old_level=
$old
_level
\n
"
}
# -----------------------------------------
# Close off the previous entry
# -----------------------------------------
# This is the first child of the previous item
# Increasing the level always happens in steps of 1
if
{
$level
>
$old
_level
}
{
append cost_center_json
",
\n
${indent}
\t
children:
\[\n
"
}
# A group of children needs to be closed.
# Please note that this can cascade down to several levels.
while
{
$level
<
$old
_level
}
{
append cost_center_json
"
\n
${indent}
\}\]\n
"
incr old_level -1
set indent
""
for
{
set
i 0
}
{
$i
<
$old
_level
}
{
incr
i
}
{
append indent
"
\t
"
}
}
set cost_center_name
"
$cost
_center_code -
$cost
_center_name"
# The current cost_center is on the same level as the previous.
# This is also executed after reducing the old_level in the previous while loop
if
{
$level
==
$old
_level
}
{
if
{
0 !=
$ctr
}
{
append cost_center_json
"
${indent}
\n
${indent}
\}
,
\n
"
}
}
if
{
$debug
_p
}
{
append cost_center_json
"
\n
//
$cost
_center_name: ctr=
$ctr
, level=
$level
, old_level=
$old
_level
\n
"
}
set indent
""
for
{
set
i 0
}
{
$i
<
$level
}
{
incr
i
}
{
append indent
"
\t
"
}
if
{
0 ==
$num
_children
}
{
set leaf_json
"true"
}
else
{
set leaf_json
"false"
}
set successor_cost_centers
[
list
]
set predecessor_cost_centers
[
list
]
if
{[
info
exists successor_hash
(
$cost
_center_id
)]}
{
set successor_cost_centers
$successor
_hash
(
$cost
_center_id
)
}
if
{[
info
exists predecessor_hash
(
$cost
_center_id
)]}
{
set predecessor_cost_centers
$predecessor
_hash
(
$cost
_center_id
)
}
append cost_center_json
"
${indent}
\{
${indent}
\t
id:
$cost
_center_id,
${indent}
\t
text:'
$cost
_center_name',
${indent}
\t
duration:13.5,
${indent}
\t
successors:
\[
[
join
$successor
_cost_centers
","
]
\]
,
${indent}
\t
predecessors:
\[
[
join
$predecessor
_cost_centers
","
]
\]
,
${indent}
\t
iconCls:'cost_center-folder',
${indent}
\t
expanded:
$expanded
,
"
foreach var
$valid
_vars
{
continue
# Skip xml_* variables
(
only used by MS-Cost_Center
)
if
{[
regexp
{
^xml_
}
$var
match
]}
{
continue
}
# Append the value to the JSON output
set value
[
set
$var
]
set mapped_value
[
string
map
{
"
\n
"
"<br>"
"
\r
"
""
}
$value
]
append cost_center_json
"
${indent}
\t
$var:
'
$mapped
_value',
\n
"
}
append cost_center_json
"
${indent}
\t
leaf:
$leaf
_json"
incr ctr
set old_level
$level
}
set
level 0
while
{
$level
<
$old
_level
}
{
# A group of children needs to be closed.
# Please note that this can cascade down to several levels.
append cost_center_json
"
\n
${indent}
\}\]\n
"
incr old_level -1
set indent
""
for
{
set
i 0
}
{
$i
<
$old
_level
}
{
incr
i
}
{
append indent
"
\t
"
}
}
doc_return 200
"text/plain"
"{'text':'.','children':
\[
$cost
_center_json
}
"
ad_script_abort
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment