<script type=
"text/javascript"
>
function
formatProgress(value){
if
(value){
var
s = &
#39;<div style="width:100%;border:1px solid #ccc">' +
&
#39;<div style="width:' + value + '%;background:#cc0000;color:#fff">' + value + '%' + '</div>'
&
#39;</div>';
return
s;
}
else
{
return
&
#39;';
}
}
var
editingId;
function
deleteRow(){
if
(editingId != undefined){
$(&
#39;#tg').treegrid('select', editingId);
return
;
}
var
row = $(&
#39;#tg').treegrid('getSelected');
if
(row){
editingId = row.id
$(&
#39;#tg').treegrid('remove', editingId);
$(&
#39;#tg').treegrid('reloadFooter');
}
$(
".actionbtn"
).toggleClass(
"l-btn-disabled"
);
}
function
edit(){
if
(editingId != undefined){
$(&
#39;#tg').treegrid('select', editingId);
return
;
}
var
row = $(&
#39;#tg').treegrid('getSelected');
if
(row){
editingId = row.id
$(&
#39;#tg').treegrid('beginEdit', editingId);
}
$(
".actionbtn"
).toggleClass(
"l-btn-disabled"
);
}
function
insert(){
if
(editingId != undefined){
$(&
#39;#tg').treegrid('select', editingId);
return
;
}
var
rows = $(&
#39;#tg').treegrid('getChildren');
editingId = rows.length+1;
var
row =
null
;
var
_data = {
"id"
:editingId,
"name"
:
"new name"
,
"persons"
:0,
"begin"
:
"3/19/2010"
,
"end"
:
"3/20/2010"
,
"progress"
:10};
var
_parentId = 0;
var
row = $(&
#39;#tg').treegrid('getSelected');
if
(row){
$(&
#39;#tg').treegrid('expand',row.id);
_parentId = row.id;
}
else
{
var
root = $(&
#39;#tg').treegrid('getRoot');
_parentId =
null
;
}
$(&
#39;#tg').treegrid('append',{
parent: _parentId,
data: [_data]
});
$(&
#39;#tg').treegrid('beginEdit',_data.id);
$(
".actionbtn"
).toggleClass(
"l-btn-disabled"
);
}
function
save(){
if
(editingId != undefined){
var
t = $(&
#39;#tg');
t.treegrid(&
#39;endEdit', editingId);
editingId = undefined;
var
persons = 0;
var
rows = t.treegrid(&
#39;getChildren');
for
(
var
i=0; i<rows.length; i++){
var
p = parseInt(rows[i].persons);
if
(!isNaN(p)){
persons += p;
}
}
var
frow = t.treegrid(&
#39;getFooterRows')[0];
frow.persons = persons;
t.treegrid(&
#39;reloadFooter');
$(
".actionbtn"
).toggleClass(
"l-btn-disabled"
);
}
}
function
cancel(){
if
(editingId != undefined){
$(&
#39;#tg').treegrid('cancelEdit', editingId);
editingId = undefined;
}
$(
".actionbtn"
).toggleClass(
"l-btn-disabled"
);
}
</script>
<div style=
"margin:10px 0;"
>
<a href=
"javascript:void(0)"
disabled=
"disabled"
class=
"easyui-linkbutton actionbtn"
onclick=
"save()"
>Save</a>
<a href=
"javascript:void(0)"
disabled=
"disabled"
class=
"easyui-linkbutton actionbtn"
onclick=
"cancel()"
>Cancel</a>
</div>