/
switch_sample.class.php
123 lines (108 loc) · 3.39 KB
/
switch_sample.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
include_once DIR_MODULES . 'plans/plan_component.class.php';
class switch_sample extends plan_component {
function __construct($id)
{
$this->name=str_replace('.class.php','',basename(__FILE__));
parent::__construct($id);
}
function getProperties()
{
$properties = parent::getProperties();
$properties[] = array(
'NAME' => 'color',
'TITLE' => LANG_COLOR,
'TYPE' => 'rgb',
'DEFAULT' => '#ff0000'
);
$properties[] = array(
'NAME' => 'bgcolor',
'TITLE' => LANG_COLOR.' (background)',
'TYPE' => 'select',
'DATA' => '#ff0000=Red|#00ff00=Green|#0000ff=Blue',
'DEFAULT' => '#ff0000'
);
$properties[] = array(
'NAME' => 'value',
'TITLE' => LANG_VALUE,
'TYPE' => 'linked_property'
);
/*
$properties[] = array(
'NAME' => 'value_min',
'TITLE' => 'Min',
'TYPE' => 'int',
'DEFAULT' => '0'
);
$properties[] = array(
'NAME' => 'value_max',
'TITLE' => 'Max',
'TYPE' => 'int',
'DEFAULT' => '100'
);
*/
$this->processProperties($properties);
return $properties;
}
function getSVG($attributes)
{
$x=(int)$attributes['x'];
$y=(int)$attributes['y'];
$data=$this->getData();
$current_value=(int)$data['value']['VALUE'];
if ($data['value']['VALUE']) {
$data['value_proc']['VALUE']=100;
} else {
$data['value_proc']['VALUE']=0;
}
$bgcolor=$data['bgcolor']['VALUE'];
$width=(int)$attributes['width'];
if (!$width) $width=200;
$height=(int)$attributes['height'];
if (!$height) $height=20;
$svg="<svg width='$width' height='$height' x='$x' y='$y'>";
$svg.="<rect x='0' y='0' width='100%' height='$height' style=\"fill:{$bgcolor};stroke-width:3;stroke:rgb(0,0,0)\"/>";
$svg.="<rect x='0' y='0' width='%value_proc%%' id='procElem{$this->component_id}' height='$height' style=\"fill:%color%;stroke-width:3;stroke:rgb(0,0,0)\"/>";
$svg.="</svg>";
foreach($data as $k=>$v) {
$svg=str_replace('%'.$k.'%',$v['VALUE'],$svg);
}
return $svg;
}
function getJavascript()
{
$data=$this->getData();
$prop_name=strtolower($data['value']['LINKED_OBJECT'].'.'.$data['value']['LINKED_PROPERTY']);
$code = <<<EOD
function componentUpdated{$this->component_id}(property_name,property_value) {
if (property_name=='$prop_name') {
var elem=$('#procElem{$this->component_id}');
if (property_value=='1') {
elem.attr('widthNum','5');
elem.animate(
{'widthNum':100},
{
step: function(widthNum){
$(this).attr('width', widthNum+'%');
},
duration: 200
}
);
} else {
elem.attr('widthNum','100');
elem.animate(
{'widthNum':0},
{
step: function(widthNum){
$(this).attr('width', widthNum+'%');
},
duration: 200
}
);
}
}
}
EOD;
return $code;
}
}