|
From: <ma...@us...> - 2012-02-05 19:49:41
|
Revision: 689
http://openautomation.svn.sourceforge.net/openautomation/?rev=689&view=rev
Author: makki1
Date: 2012-02-05 19:49:35 +0000 (Sun, 05 Feb 2012)
Log Message:
-----------
imagetrigger-widget: WiP but basics work, plenty things pending
Modified Paths:
--------------
CometVisu/trunk/visu/designs/structure_pure.js
CometVisu/trunk/visu/visu_config.xsd
Modified: CometVisu/trunk/visu/designs/structure_pure.js
===================================================================
--- CometVisu/trunk/visu/designs/structure_pure.js 2012-02-05 18:41:40 UTC (rev 688)
+++ CometVisu/trunk/visu/designs/structure_pure.js 2012-02-05 19:49:35 UTC (rev 689)
@@ -794,6 +794,133 @@
content: false
});
+ this.addCreator("imagetrigger", {
+ create: function( page, path ) {
+ var $p = $(page);
+ var ret_val = $('<div class="widget clearfix image" />');
+ ret_val.setWidgetLayout($p);
+ ret_val.addClass ('imagetrigger');
+ var value = $p.attr('value') ? $p.attr('value') : 0;
+ var labelElement = $p.find('label')[0];
+ ret_val.append( labelElement ? '<div class="label">' + labelElement.textContent + '</div>' : '' );
+ var address = {};
+ $p.find('address').each( function(){
+ var src = this.textContent;
+ ga_list.push( src )
+ address[ '_' + src ] = [
+ this.getAttribute('transform'), {
+ 'readonly' : this.getAttribute('readonly'),
+ 'writeonly' : this.getAttribute('writeonly')
+ }
+ ];
+ //[ transform, readonly=='true', writeonly=='true' ];
+ });
+ var style = ' style=" ';
+ style += $p.attr('width' ) ? 'width:' + $p.attr('width' ) + ';' : 'width: 100%;';
+ style += $p.attr('height' ) ? 'height:' + $p.attr('height' ) + ';"' : '"';
+
+ var actor = '<div class="actor">';
+ /*
+ if ( $p.attr('type')=='bitmask' )
+ for (var i = 0; i <= 7; i++)
+ actor += '<img src="" ' + style + ' class="image" />';
+ else
+ */
+ if ( $p.attr('type')=='show' )
+ actor += '<img src="' + $p.attr('src') + '.' + $p.attr('suffix') + '" ' + style + ' />';
+ else
+ actor += '<img src="" ' + style + ' />';
+ actor += '</div>';
+ /*
+ var map = $p.attr('mapping');
+ if( mappings[map] && mappings[map][value] )
+ actor += '<div class="value">' + mappings[map][value] + '</div>';
+ else
+ actor += '<div class="value">' + value + '</div>'; //no value if no mapping
+ */
+ actor += '</div>';
+ var refresh = $p.attr('refresh') ? $p.attr('refresh')*1000 : 0;
+ var $actor = $(actor).data( {
+ 'address': address,
+ 'refresh': refresh,
+ 'src': $p.attr('src'),
+ 'suffix': $p.attr('suffix'),
+ 'type': $p.attr('type'),
+ 'mapping': map,
+ 'sendValue': $p.attr('sendValue') || ""
+ } )
+ .each(setupRefreshAction) // abuse "each" to call in context... refresh is broken with select right now
+ .bind( 'click', this.action );
+ for( var addr in address ) {
+ $actor.bind( addr, this.update );
+ }
+ ret_val.append( $actor );
+ return ret_val;
+ },
+ update: function(e,d) {
+ var data = $(this).data();
+ if ( data.address[e.type][1].writeonly == "true")
+ return; // skip writeonly FIXME: writeonly shouldnt bind to update at all
+ var val = transformDecode(data.address[e.type][0], d);
+ if (data.type == "show")
+ if (val == 0)
+ $(this).children().hide();
+ else
+ $(this).children().attr("src", data.src + '.' + data.suffix ).show();
+ else if (data.type == "select")
+ if (val == 0)
+ $(this).children().hide();
+ else
+ $(this).children().attr("src", data.src + val + '.' + data.suffix ).show();
+ /*
+ else if (data.type == "bitmask")
+ if (val == 0) { //hide all
+ $(this).children().remove(); //.hide()
+ } else {
+ for (var i = 0; i <= 7; i++) {
+ var mask = Math.pow(2,i);
+ if ((mask & val) == mask) { //show
+ $(this).children().append('<img src="' + data.src + mask + '.' + data.suffix + '" />');
+ }
+ }
+ }
+ */
+
+ //FIXME: add value if mapping exists
+ //FIXME: get image name from mapping
+ //FIXME: add bitmask for multiple images
+ //FIXME: add SVG-magics
+ },
+ action: function() {
+ var data = $(this).data();
+ sendValue = data.sendValue;
+ for( var addr in data.address ) {
+ if( data.address[addr][1].readonly == "true" )
+ continue; // skip read only
+ if( data.sendValue == "" )
+ continue; // skip empty
+ visu.write( addr.substr(1), transformEncode( data.address[addr][0], sendValue ) );
+ }
+ },
+ attributes: {
+ src: { type: 'uri' , required: true },
+ width: { type: 'string' , required: false },
+ height: { type: 'string' , required: false },
+ refresh: { type: 'numeric', required: false },
+ colspan: { type: 'numeric', required: false },
+ rowspan: { type: 'numeric', required: false },
+ sendValue: { type: 'numeric', required: false },
+ type: { type: 'list' , required: true, list: {'show': 'show', 'select': 'select' /* , 'bitmask': 'bitmask' */ } },
+ mapping: { type: 'mapping', required: false },
+ suffix: { type: 'list' , required: false, list: {'png': '.png', 'jpg': '.jpg', 'gif': '.gif', 'svg': '.svg', 'bmp': '.bmp'} }
+ },
+ elements: {
+ label: { type: 'string', required: false, multi: false },
+ address: { type: 'address', required: true, multi: true }
+ },
+ content: false
+ });
+
this.addCreator('video', {
create: function( page, path ) {
var $p = $(page);
Modified: CometVisu/trunk/visu/visu_config.xsd
===================================================================
--- CometVisu/trunk/visu/visu_config.xsd 2012-02-05 18:41:40 UTC (rev 688)
+++ CometVisu/trunk/visu/visu_config.xsd 2012-02-05 19:49:35 UTC (rev 689)
@@ -27,6 +27,7 @@
<xsd:extension base="addr">
<xsd:attribute ref="transform" use="required" />
<xsd:attribute ref="readonly" use="optional" />
+ <xsd:attribute ref="writeonly" use="optional" />
<xsd:attribute name="type" type="xsd:string" use="optional" />
<xsd:attribute name="variant" type="xsd:string" use="optional" />
</xsd:extension>
@@ -62,6 +63,7 @@
<xsd:attribute name="value" type="xsd:string" />
<xsd:attribute name="readonly" type="xsd:boolean" />
+<xsd:attribute name="writeonly" type="xsd:boolean" />
<xsd:attribute name="align" type="xsd:string" />
<xsd:attribute name="variant" type="xsd:string" />
@@ -173,6 +175,7 @@
<xsd:element name="info" type="info" />
<xsd:element name="shade" type="info" />
<xsd:element name="image" type="image" />
+ <xsd:element name="imagetrigger" type="imagetrigger" />
<xsd:element name="video" type="video" />
<xsd:element name="iframe" type="iframe" />
<!-- available plugins - include not checked -->
@@ -220,6 +223,7 @@
<xsd:element name="info" type="info" />
<xsd:element name="shade" type="info" />
<xsd:element name="image" type="image" />
+ <xsd:element name="imagetrigger" type="imagetrigger" />
<xsd:element name="video" type="video" />
<xsd:element name="iframe" type="iframe" />
<!-- available plugins - include not checked -->
@@ -357,6 +361,21 @@
<xsd:attribute name="refresh" type="xsd:decimal" />
</xsd:complexType>
+<xsd:complexType name="imagetrigger">
+ <xsd:choice maxOccurs="unbounded" minOccurs="0">
+ <xsd:element name="label" type="xsd:string" />
+ <xsd:element name="address" type="address" minOccurs="1"/>
+ </xsd:choice>
+ <xsd:attribute name="src" type="xsd:string"/>
+ <xsd:attribute name="suffix" type="xsd:string" use="required" />
+ <xsd:attribute name="type" type="xsd:string" use="optional" />
+ <xsd:attribute name="width" type="dimension" />
+ <xsd:attribute name="height" type="dimension" />
+ <xsd:attribute name="refresh" type="xsd:decimal" />
+ <xsd:attribute ref="mapping" use="optional" />
+ <xsd:attribute name="sendValue" type="xsd:string" use="optional" />
+</xsd:complexType>
+
<xsd:complexType name="video">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="label" type="xsd:string" maxOccurs="1" />
@@ -387,7 +406,7 @@
</xsd:complexType>
<xsd:complexType name="diagram_inline">
- <xsd:choice maxOccurs="unbounded" minOccurs="1">
+ <xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="label" type="xsd:string" maxOccurs="1" />
</xsd:choice>
<xsd:attribute name="rrd" type="xsd:string" use="required" />
@@ -405,7 +424,7 @@
</xsd:complexType>
<xsd:complexType name="diagram_popup" >
- <xsd:choice maxOccurs="unbounded" minOccurs="1">
+ <xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="label" type="xsd:string" maxOccurs="1" />
</xsd:choice>
<xsd:attribute name="rrd" type="xsd:string" use="required" />
@@ -422,7 +441,7 @@
</xsd:complexType>
<xsd:complexType name="diagram_info" >
- <xsd:choice maxOccurs="unbounded" minOccurs="1">
+ <xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="label" type="xsd:string" maxOccurs="1" />
<xsd:element name="address" type="address" minOccurs="1"/>
</xsd:choice>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|