Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2789 rexy 1
function renderPlugin_bat(data) {
2
    var batcount = 0;
3
    var directives = {
4
        Name: {
5
            text: function () {
6
                return (this.Name !== undefined) ? this.Name : 'Battery'+(batcount++);
7
            }
8
        },
9
        DesignCapacity: {
10
            html: function () {
11
                return this.DesignCapacity + String.fromCharCode(160) + this.CapacityUnit;
12
            }
13
        },
14
        FullCapacity: {
15
            html: function () {
16
                return this.FullCapacity + String.fromCharCode(160) + this.CapacityUnit;
17
            }
18
        },
19
        FullCapacityBar: {
20
            html: function () {
21
                if (( this.CapacityUnit !== "%" ) && (this.DesignCapacity !== undefined)){
22
                    var percent = (this.DesignCapacity > 0) ? round(100*this.FullCapacity/this.DesignCapacity,0) : 0;
23
                    return '
div>' +
24
'</div>
' + percent + '%div>';
25
} else {
26
return '';
27
}
28
}
29
},
30
RemainingCapacity: {
31
html: function () {
32
if ( this.CapacityUnit === "%" ) {
33
return '<div class="progress"><div class="progress-bar progress-bar-info" style="width:' + round(this.RemainingCapacity,0) + '%;"></div>' +
34
'div><div class="percent">' + round(this.RemainingCapacity,0) + '%</div>';
35
} else {
36
return this.RemainingCapacity + String.fromCharCode(160) + this.CapacityUnit;
37
}
38
}
39
},
40
RemainingCapacityBar: {
41
html: function () {
42
if (( this.CapacityUnit !== "%" ) && (this.FullCapacity !== undefined)){
43
var percent = (this.FullCapacity > 0) ? round(100*this.RemainingCapacity/this.FullCapacity,0) : 0;
44
return '<div class="progress"><div class="progress-bar progress-bar-info" style="width:' + percent + '%;"></div>' +
45
'</div><div class="percent">' + percent + '%</div>';
46
} else {
47
return '';
48
}
49
}
50
},
51
PresentVoltage: {
52
text: function () {
53
return this.PresentVoltage + String.fromCharCode(160) + 'mV';
54
}
55
},
56
BatteryTemperature: {
57
html: function () {
58
return formatTemp(this.BatteryTemperature, data.Options["@attributes"].tempFormat);
59
}
60
},
61
DesignVoltage: {
62
text: function () {
63
return this.DesignVoltage + String.fromCharCode(160) + 'mV';
64
}
65
},
66
DesignVoltageMax: {
67
text: function () {
68
return (this.DesignVoltageMax !== undefined) ? this.DesignVoltageMax + String.fromCharCode(160) + 'mV' : '';
69
}
70
}
71
};
72
 
73
if (data.Plugins.Plugin_BAT !== undefined) {
74
var bats = items(data.Plugins.Plugin_BAT.Bat);
75
if (bats.length > 0) {
76
var html = "";
77
var paramlist = {Model:15,Manufacturer:14,SerialNumber:16,DesignCapacity:2,FullCapacity:13,RemainingCapacity:3,ChargingState:8,DesignVoltage:4,PresentVoltage:5,BatteryType:9,BatteryTemperature:10,BatteryCondition:11,CycleCount:12};
78
var paramlis2 = {FullCapacity:'FullCapacityBar',RemainingCapacity:'RemainingCapacityBar',DesignVoltage:'DesignVoltageMax'};
79
var i, proc_param;
80
 
81
for (i = 0; i < bats.length; i++) {
82
if (bats[i]["@attributes"].CapacityUnit === undefined) {
83
bats[i]["@attributes"].CapacityUnit = 'mWh';
84
} else if ((bats[i]["@attributes"].CapacityUnit === '%') && (bats[i]["@attributes"].RemainingCapacity !== undefined)) {
85
if (bats[i]["@attributes"].DesignCapacity !== undefined) {
86
delete bats[i]["@attributes"].DesignCapacity;
87
}
88
if (bats[i]["@attributes"].FullCapacity !== undefined) {
89
delete bats[i]["@attributes"].FullCapacity;
90
}
91
}
92
 
93
try {
94
html+="<tr id=\"bat-" + i + "\" class=\"treegrid-bat-" + i + "\" style=\"display:none;\" >";
95
html+="<td colspan=\"3\"><span class=\"treegrid-spanbold\" data-bind=\"Name\"></span></td>";
96
html+="</tr>";
97
for (proc_param in paramlist) {
98
if (bats[i]["@attributes"][proc_param] !== undefined) {
99
html+="<tr id=\"bat-" + i + "-" + proc_param + "\" class=\"treegrid-parent-bat-" + i + "\">";
100
html+="<td><span class=\"treegrid-spanbold\">" + genlang(paramlist[proc_param], 'bat') + "</span></td>";
101
html+="<td><span data-bind=\"" + proc_param + "\"></span></td>";
102
if (paramlis2[proc_param] !== undefined) {
103
html+="<td class=\"rightCell\"><span data-bind=\"" + paramlis2[proc_param] + "\"></span></td>";
104
} else {
105
html+="<td></td>";
106
}
107
html+="</tr>";
108
}
109
}
110
}
111
catch (err) {
112
$("#bat-" + i).hide();
113
}
114
}
115
 
116
$("#bat-data").empty().append(html);
117
 
118
for (i = 0; i < bats.length; i++) {
119
try {
120
$('#bat-'+ i).render(bats[i]["@attributes"], directives);
121
$("#bat-" + i).show();
122
for (proc_param in paramlist) {
123
if (bats[i]["@attributes"][proc_param] !== undefined) {
124
$('#bat-'+ i+ "-" + proc_param).render(bats[i]["@attributes"], directives);
125
}
126
}
127
}
128
catch (err) {
129
$("#bat-" + i).hide();
130
}
131
}
132
 
133
$('#bat').treegrid({
134
initialState: 'expanded',
135
expanderExpandedClass: 'normalicon normalicon-down',
136
expanderCollapsedClass: 'normalicon normalicon-right'
137
});
138
 
139
$('#block_bat').show();
140
} else {
141
$('#block_bat').hide();
142
}
143
} else {
144
$('#block_bat').hide();
145
}
146
}