|
From: <ma...@us...> - 2010-11-20 18:23:47
|
Revision: 145
http://openautomation.svn.sourceforge.net/openautomation/?rev=145&view=rev
Author: mayerch
Date: 2010-11-20 18:23:39 +0000 (Sat, 20 Nov 2010)
Log Message:
-----------
* Changed location (and name) of the structure files (i.e. the JS that defines the HTML of the widgets)
* renamed visuclient.js to cometvisu-client.js
Modified Paths:
--------------
CometVisu/trunk/visu/edit_config.html
CometVisu/trunk/visu/index.html
Added Paths:
-----------
CometVisu/trunk/visu/designs/structure_custom.js
CometVisu/trunk/visu/designs/structure_pure.js
CometVisu/trunk/visu/lib/cometvisu-client.js
Removed Paths:
-------------
CometVisu/trunk/visu/lib/visuclient.js
CometVisu/trunk/visu/lib/visudesign_custom.js
CometVisu/trunk/visu/lib/visudesign_pure.js
Copied: CometVisu/trunk/visu/designs/structure_custom.js (from rev 144, CometVisu/trunk/visu/lib/visudesign_custom.js)
===================================================================
--- CometVisu/trunk/visu/designs/structure_custom.js (rev 0)
+++ CometVisu/trunk/visu/designs/structure_custom.js 2010-11-20 18:23:39 UTC (rev 145)
@@ -0,0 +1,75 @@
+/* visudesign_custom.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+
+/**
+ * This class defines all the custom changes to the visu
+ */
+function VisuDesign_Custom() {}; // do NOT change here
+VisuDesign_Custom.prototype = new VisuDesign(); // do NOT chagen here
+
+/**
+ * Custom changes could go here and look e.g. like
+****************************************
+VisuDesign_Custom.prototype.addCreator("line", {
+ create: function( page, path ) {
+ return $( '<hr />' );
+ },
+ attributes: {
+ },
+ content: false
+});
+****************************************
+ */
+
+/**
+ * This is a custom function that extends the available widgets.
+ * It's purpose is to change the design of the visu during runtime
+ * to demonstrate all available
+ */
+VisuDesign_Custom.prototype.addCreator("designtoggle", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'switch' );
+ var label = '<div class="label">' + page.textContent + '</div>';
+ var actor = '<div class="actor switchUnpressed">';
+ var value = $('link[href*="designs"]').attr('href').split('/')[1];
+ actor += '<div class="value">' + value + '</div>';
+ actor += '</div>';
+ ret_val.append(label).append($(actor)
+ .data({
+ 'mapping' : $(page).attr('mapping'),
+ 'styling' : $(page).attr('styling'),
+ 'value' : value,
+ 'type' : 'toggle'
+ })
+ .bind('click', function() {
+ var designs = [ 'pure', 'discreet' ];
+ var oldDesign = $('.value',this).text();
+ var newDesign = designs[ (designs.indexOf(oldDesign) + 1) % designs.length ];
+ $('.value',this).text(newDesign);
+ $('link[href*="designs"]').each(function(){
+ this.href = this.href.replace( oldDesign, newDesign );
+ });
+ })
+ );
+ return ret_val;
+ },
+ attributes: {
+ },
+ content: {type: "string", required: true}
+});
+
Copied: CometVisu/trunk/visu/designs/structure_pure.js (from rev 144, CometVisu/trunk/visu/lib/visudesign_pure.js)
===================================================================
--- CometVisu/trunk/visu/designs/structure_pure.js (rev 0)
+++ CometVisu/trunk/visu/designs/structure_pure.js 2010-11-20 18:23:39 UTC (rev 145)
@@ -0,0 +1,334 @@
+/* visudesign_pure.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+
+/**
+ * This class defines all the building blocks for a Visu in the "Pure" design
+ */
+function VisuDesign() {
+ this.creators = {};
+
+ this.addCreator = function (name, object) {
+ this.creators[name] = object;
+ }
+
+ this.getCreator = function(name) {
+ if (typeof this.creators[name] == undefined) {
+ return this.creators.unknown;
+ }
+ return this.creators[name];
+ }
+
+ /**
+ * The creators object contians all widgets creators and their mappin to the
+ * XML config file tags
+ */
+ this.addCreator("page", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ var style = ( '0' != path ) ? 'display:none' : '';
+ var name = $(page).attr('name'); //path += '_' + name;
+ var type = $(page).attr('type'); //text, 2d or 3d
+ ret_val.addClass( 'link' ).addClass("pagelink");
+ ret_val.append( '<a href="javascript:scrollToPage(\''+path+'\')">' + name + '</a>' );
+ var childs = $(page).children();
+ var container = $( '<div class="clearfix"/>' );
+
+ container.append( '<h1>' + name + '</h1>' );
+ $( childs ).each( function(i){
+ container.append( create_pages(childs[i], path + '_' + i ) );
+ } );
+ $('#pages').prepend( $( '<div class="page" id="' + path + '" style="'+style+';"/>' ).append(container) );
+ return ret_val;
+ },
+ attributes: {
+ name: {type: "string", required: true}
+ },
+ content: true
+ });
+
+ this.addCreator("line", {
+ create: function( page, path ) {
+ return $( '<hr />' );
+ },
+ attributes: {
+ },
+ content: false
+ });
+
+ this.addCreator("break", {
+ create: function( page, path ) {
+ return $( '<br />' );
+ },
+ attributes: {
+ },
+ content: false
+ });
+
+
+ this.addCreator("text", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'text' );
+ var style = '';
+ if( $(page).attr('align') ) style += 'text-align:' + $(page).attr('align') + ';';
+ if( style != '' ) style = 'style="' + style + '"';
+ ret_val.append( '<div ' + style + '>' + page.textContent + '</div>' );
+ return ret_val;
+ },
+ attributes: {
+ align: {type: "string", required: false}
+ },
+ content: {type: "string", required: true}
+ });
+
+ this.addCreator("info", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'info' );
+ var label = '<div class="label">' + page.textContent + '</div>';
+ ga_list.push( $(page).attr('address') );
+ var actor = '<div class="actor GA' + $(page).attr('address').split('/').join('_') + '">';
+ if( $(page).attr('pre') ) actor += '<div>' + $(page).attr('pre') + '</div>';
+ actor += '<div class="value">-</div>';
+ if( $(page).attr('post') ) actor += '<div>' + $(page).attr('post') + '</div>';
+ actor += '</div>';
+ ret_val.append( label ).append( $(actor).data( {
+ 'GA': $(page).attr('address'),
+ 'datatype': $(page).attr('datatype'),
+ 'mapping' : $(page).attr('mapping'),
+ 'styling' : $(page).attr('styling')
+ } ) );
+ return ret_val;
+ },
+ attributes: {
+ address: {type: "address", required: true},
+ datatype: {type: "datatype", required: true},
+ pre: {type: "string", required: false},
+ post: {type: "string", required: false},
+ mapping: {type: "mapping", required: false},
+ styling: {type: "styling", required: false}
+ },
+ content: {type: "string", required: true}
+ });
+
+ this.addCreator("shade", this.getCreator("info"));
+
+
+ this.addCreator("dim", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'dim' );
+ var label = '<div class="label">' + page.textContent + '</div>';
+ ga_list.push( $(page).attr('address') );
+ var actor = $('<div class="actor GA' + $(page).attr('address').split('/').join('_') + '" />');
+ ret_val.append( label ).append( actor );
+ var min = parseFloat( $(page).attr('min') || 0 );
+ var max = parseFloat( $(page).attr('max') || 100 );
+ var step = parseFloat( $(page).attr('step') || 0.5 );
+ ret_val.find('.actor').data( {
+ 'events': $(actor).data( 'events' ),
+ 'GA': $(page).attr('address'),
+ 'datatype': $(page).attr('datatype'),
+ 'mapping' : $(page).attr('mapping'),
+ 'styling' : $(page).attr('styling'),
+ 'min' : min,
+ 'max' : max,
+ 'step' : step,
+ 'type' : 'dim'
+ }).slider({step:step,min:min,max:max, animate: true,start:slideStart,change:slideChange});//slide:slideAction});
+
+ return ret_val;
+ },
+ attributes: {
+ address: {type: "address", required: true},
+ datatype: {type: "datatype", required: true},
+ response_address: {type: "address", required: true},
+ response_datatype: {type: "datatype", required: true},
+ min: {type: "numeric", required: false},
+ max: {type: "numeric", required: false},
+ step: {type: "numeric", required: false},
+ mapping: {type: "mapping", required: false},
+ styling: {type: "styling", required: false}
+ },
+ content: {type: "string", required: true}
+ });
+
+ this.addCreator("slide", this.getCreator("dim"));
+
+ this.addCreator("switch", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'switch' );
+ var label = '<div class="label">' + page.textContent + '</div>';
+ var response_address = $(page).attr('response_address');
+ ga_list.push( response_address );
+ var actor = '<div class="actor GA' + response_address.split('/').join('_') + ' switchUnpressed">';
+ if( $(page).attr('pre') ) actor += $(page).attr('pre');
+ actor += '<div class="value">-</div>';
+ if( $(page).attr('post') ) actor += $(page).attr('post');
+ actor += '</div>';
+ ret_val.append( label ).append( $(actor).data( {
+ 'GA': $(page).attr('address'),
+ 'datatype': $(page).attr('datatype'),
+ 'mapping' : $(page).attr('mapping'),
+ 'styling' : $(page).attr('styling'),
+ 'type' : 'toggle'
+ } ).bind('click',switchAction) );
+ return ret_val;
+ },
+ attributes: {
+ address: {type: "address", required: true},
+ datatype: {type: "datatype", required: true},
+ response_address: {type: "address", required: true},
+ response_datatype: {type: "datatype", required: true},
+ pre: {type: "string", required: false},
+ post: {type: "string", required: false},
+ mapping: {type: "mapping", required: false},
+ styling: {type: "styling", required: false}
+ },
+ content: {type: "string", required: true}
+ });
+
+ this.addCreator("toggle", this.getCreator("switch"));
+
+ this.addCreator("trigger", {
+ create: function( page, path ) {
+ var value = $(page).attr('value') ? $(page).attr('value') : 0;
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'switch' );
+ var label = '<div class="label">' + page.textContent + '</div>';
+ var address = $(page).attr('address');
+ var actor = '<div class="actor switchUnpressed">';
+ if( $(page).attr('pre') ) actor += $(page).attr('pre');
+ var map = $(page).attr('mapping');
+ if( mappings[map] && mappings[map][value] )
+ actor += '<div class="value">' + mappings[map][value] + '</div>';
+ else
+ actor += '<div class="value">' + value + '</div>';
+ if( $(page).attr('post') ) actor += $(page).attr('post');
+ actor += '</div>';
+ ret_val.append( label ).append( $(actor).data( {
+ 'GA' : $(page).attr('address'),
+ 'datatype': $(page).attr('datatype'),
+ 'mapping' : $(page).attr('mapping'),
+ 'styling' : $(page).attr('styling'),
+ 'type' : 'trigger',
+ 'sendValue': value
+ } ).bind('click',triggerAction) );
+
+ return ret_val;
+ },
+ attributes: {
+ address: {type: "address", required: true},
+ datatype: {type: "datatype", required: true},
+ value: {type: "string", required: true},
+ pre: {type: "string", required: false},
+ post: {type: "string", required: false},
+ mapping: {type: "mapping", required: false},
+ styling: {type: "styling", required: false}
+ },
+ content: {type: "string", required: true}
+ });
+
+ this.addCreator("image", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'image' );
+ ret_val.append( '<div class="label">' + page.textContent + '</div>' );
+ var style = '';
+ if( $(page).attr('width') ) style += 'width:' + $(page).attr('width') + ';';
+ if( $(page).attr('height') ) style += 'height:' + $(page).attr('height') + ';';
+ if( style != '' ) style = 'style="' + style + '"';
+ var actor = '<div class="actor"><img src="' +$(page).attr('src') + '" ' + style + ' /></div>';
+ var refresh = $(page).attr('refresh') ? $(page).attr('refresh')*1000 : 0;
+ ret_val.append( $(actor).data( {
+ 'refresh': refresh
+ } ).each(setupRefreshAction) ); // abuse "each" to call in context...
+ return ret_val;
+ },
+ attributes: {
+ src: {type: "uri", required: true},
+ width: {type: "string", required: false},
+ height: {type: "string", required: false},
+ refresh: {type: "numeric", required: false}
+ },
+ content: {type: "string", required: false}
+ });
+
+ this.addCreator("video", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'video' );
+ ret_val.append( '<div class="label">' + page.textContent + '</div>' );
+ var style = '';
+ if( $(page).attr('width') ) style += 'width:' + $(page).attr('width') + ';';
+ if( $(page).attr('height') ) style += 'height:' + $(page).attr('height') + ';';
+ if( style != '' ) style = 'style="' + style + '"';
+ var actor = '<div class="actor"><video src="' +$(page).attr('src') + '" ' + style + ' controls="controls" /></div>';
+ var refresh = $(page).attr('refresh') ? $(page).attr('refresh')*1000 : 0;
+ ret_val.append( $(actor).data( {
+ 'refresh': refresh
+ } ).each(setupRefreshAction) ); // abuse "each" to call in context...
+ return ret_val;
+ },
+ attributes: {
+ src: {type: "uri", required: true},
+ width: {type: "string", required: false},
+ height: {type: "string", required: false},
+ refresh: {type: "numeric", required: false}
+ },
+ content: {type: "string", required: true}
+ });
+
+ this.addCreator("unknown", {
+ create: function( page, path ) {
+ var ret_val = $('<div class="widget" />');
+ ret_val.append( '<pre>' + page.textContent + '</pre>' );
+ return ret_val;
+ },
+ attributes: {
+ },
+ content: {type: "string", required: true}
+ });
+
+ this.switchAction = function() {
+ var data = $(this).data();
+ // alert( data.GA + ' = ' + data.value );
+ visu.write( data.GA, data.value=='1' ? '0' : '1', data.datatype );
+ }
+
+ this.slideAction = function(event,ui) {
+ //alert(ui.value);
+ var now = new Date().getTime();
+ var data = $( '.actor', $(this).parent() ).data();
+ if( data.last && (now - data.last) < 1000 ) return; // too fast => early exit
+ $( '.actor', $(this).parent() ).data( 'last', now );
+ //$(this).parent().data();
+ // alert( data.GA + ' = ' + data.value );
+ //visu.write( data.GA, data.value=='1' ? '0' : '1', data.datatype );
+ //FIXME eigentlich richtig... visu.write( data.GA, ui.value, data.datatype );
+ }
+
+ /**
+ * Setup a refresh interval in seconds if the 'refresh' in the .data()
+ * ist bigger than 0
+ */
+ this.refreshAction = function(that) {
+ var data = $(this).data();
+ alert('this.refreshAction');
+ }
+};
Modified: CometVisu/trunk/visu/edit_config.html
===================================================================
--- CometVisu/trunk/visu/edit_config.html 2010-11-20 11:38:10 UTC (rev 144)
+++ CometVisu/trunk/visu/edit_config.html 2010-11-20 18:23:39 UTC (rev 145)
@@ -10,10 +10,10 @@
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="lib/jquery-ui.js" type="text/javascript"></script>
<script src="lib/scrollable.js" type="text/javascript"></script>
- <script src="lib/visuclient.js" type="text/javascript"></script>
+ <script src="lib/cometvisu-client.js" type="text/javascript"></script>
<script src="lib/knx_decode.js" type="text/javascript"></script>
- <script src="lib/visudesign_pure.js" type="text/javascript"></script>
- <script src="lib/visudesign_custom.js" type="text/javascript"></script>
+ <script src="designs/structure_pure.js" type="text/javascript"></script>
+ <script src="designs/structure_custom.js" type="text/javascript"></script>
<script src="lib/templateengine.js" type="text/javascript"></script>
<script src="edit/visuconfig_edit.js" type="text/javascript"></script>
<script src="edit/json2.js" type="text/javascript"></script>
Modified: CometVisu/trunk/visu/index.html
===================================================================
--- CometVisu/trunk/visu/index.html 2010-11-20 11:38:10 UTC (rev 144)
+++ CometVisu/trunk/visu/index.html 2010-11-20 18:23:39 UTC (rev 145)
@@ -8,10 +8,10 @@
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="lib/jquery-ui.js" type="text/javascript"></script>
<script src="lib/scrollable.js" type="text/javascript"></script>
- <script src="lib/visuclient.js" type="text/javascript"></script>
+ <script src="lib/cometvisu-client.js" type="text/javascript"></script>
<script src="lib/knx_decode.js" type="text/javascript"></script>
- <script src="lib/visudesign_pure.js" type="text/javascript"></script>
- <script src="lib/visudesign_custom.js" type="text/javascript"></script>
+ <script src="designs/structure_pure.js" type="text/javascript"></script>
+ <script src="designs/structure_custom.js" type="text/javascript"></script>
<script src="lib/templateengine.js" type="text/javascript"></script>
</head>
<body>
Copied: CometVisu/trunk/visu/lib/cometvisu-client.js (from rev 144, CometVisu/trunk/visu/lib/visuclient.js)
===================================================================
--- CometVisu/trunk/visu/lib/cometvisu-client.js (rev 0)
+++ CometVisu/trunk/visu/lib/cometvisu-client.js 2010-11-20 18:23:39 UTC (rev 145)
@@ -0,0 +1,145 @@
+/* cometvisu.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+
+/**
+ * Class that handles the communicaton of the client
+ */
+function CometVisu( urlPrefix )
+{
+ this.urlPrefix = (null == urlPrefix) ? '' : urlPrefix; // the address of the service
+ this.addresses = []; // the subscribed addresses
+ this.filters = []; // the subscribed filters
+ this.user = ''; // the current user
+ this.pass = ''; // the current password
+ this.device = ''; // the current device ID
+ this.running = false; // is the communication running at the moment?
+
+ /**
+ * This function gets called once the communication is established and session information is available
+ */
+ this.handleSession = function( json )
+ {
+ this.session = json.s;
+ this.version = json.v.split( '.', 3 );
+
+ if( 0 < parseInt(this.version[0]) || 1 < parseInt(this.version[1]) )
+ alert( 'ERROR CometVisu Client: too new protocoll version (' + json.v + ') used!' );
+
+ // send first request
+ this.running = true;
+ $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ };
+
+ /**
+ * This function gets called once the communication is established and session information is available
+ */
+ this.handleRead = function( json )
+ {
+ if( !json )
+ {
+ if( this.running )
+ { // retry initial request
+ $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ }
+ return;
+ }
+
+ var lastIndex = json.i;
+ var data = json.d;
+ this.update( data );
+
+ if( this.running )
+ { // keep the requests going
+ $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&i='+lastIndex, success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ }
+ };
+
+ /**
+ * This function gets called on an error
+ * FIXME: this should be a prototype, so that the application developer can override it
+ */
+ this.handleError=function(xhr,str,excptObj)
+ {
+ alert('Error! "'+str+'"');
+ }
+ this.handleComplete=function(xhr,str)
+ {
+ // alert('Complete:"'+str+'"');
+ }
+
+ /**
+ * Build the URL part that contains the addresses and filters
+ */
+ this.buildRequest = function()
+ {
+ var requestAddresses = (this.addresses.length)?'a=' + this.addresses.join( '&a=' ):'';
+ var requestFilters = (this.filters.length )?'f=' + this.filters.join( '&f=' ):'';
+ return requestAddresses + ( (this.addresses.length&&this.filters.length)?'&':'' ) + requestFilters;
+ }
+
+ /**
+ * Subscribe to the addresses in the parameter
+ * The second parameter (filter) is optional
+ */
+ this.subscribe = function( addresses, filters )
+ {
+ var startCommunication = !this.addresses.length; // start when addresses were empty
+ this.addresses = addresses;
+ this.filters = filters ? filters : [] ;
+
+ if( !addresses.length ) this.stop(); // stop when new addresses are empty
+ else if( startCommunication ) this.login();
+ }
+
+ /**
+ * This function starts the communication by a login and then runs the
+ * ongoing communication task
+ */
+ this.login = function()
+ {
+ var request = {};
+ if( '' != this.user ) request.u = this.user;
+ if( '' != this.pass ) request.p = this.pass;
+ if( '' != this.device ) request.d = this.device;
+ $.ajax( {url:this.urlPrefix + 'l',dataType: 'json',context:this,data:request, success:this.handleSession} );
+ };
+
+ /**
+ * This function stops an ongoing connection
+ */
+ this.stop = function()
+ {
+ this.running = false;
+ };
+
+ /**
+ * This function sends a value
+ */
+ this.write = function( address, value, datatype ) // FIXME datatype not in spec!!!
+ {
+ //var request = {};
+ //request.a = address; // FIXME the spec allows multiple addresses
+ //request.v = value;
+var request = 'a=' + address + '&v=' + value;
+datatype = datatype.split('.');
+request += '&d=' + datatype[0]; // FIXME datatype not in spec!!!
+ $.ajax( {url:this.urlPrefix + 'w',dataType: 'json',context:this,data:request} );
+//alert( 'write to "' + address + '" value "' + value + '"' );
+ }
+};
+
+CometVisu.prototype.update = function( json ) {}
Deleted: CometVisu/trunk/visu/lib/visuclient.js
===================================================================
--- CometVisu/trunk/visu/lib/visuclient.js 2010-11-20 11:38:10 UTC (rev 144)
+++ CometVisu/trunk/visu/lib/visuclient.js 2010-11-20 18:23:39 UTC (rev 145)
@@ -1,145 +0,0 @@
-/* cometvisu.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-*/
-
-/**
- * Class that handles the communicaton of the client
- */
-function CometVisu( urlPrefix )
-{
- this.urlPrefix = (null == urlPrefix) ? '' : urlPrefix; // the address of the service
- this.addresses = []; // the subscribed addresses
- this.filters = []; // the subscribed filters
- this.user = ''; // the current user
- this.pass = ''; // the current password
- this.device = ''; // the current device ID
- this.running = false; // is the communication running at the moment?
-
- /**
- * This function gets called once the communication is established and session information is available
- */
- this.handleSession = function( json )
- {
- this.session = json.s;
- this.version = json.v.split( '.', 3 );
-
- if( 0 < parseInt(this.version[0]) || 1 < parseInt(this.version[1]) )
- alert( 'ERROR CometVisu Client: too new protocoll version (' + json.v + ') used!' );
-
- // send first request
- this.running = true;
- $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
- };
-
- /**
- * This function gets called once the communication is established and session information is available
- */
- this.handleRead = function( json )
- {
- if( !json )
- {
- if( this.running )
- { // retry initial request
- $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
- }
- return;
- }
-
- var lastIndex = json.i;
- var data = json.d;
- this.update( data );
-
- if( this.running )
- { // keep the requests going
- $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&i='+lastIndex, success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
- }
- };
-
- /**
- * This function gets called on an error
- * FIXME: this should be a prototype, so that the application developer can override it
- */
- this.handleError=function(xhr,str,excptObj)
- {
- alert('Error! "'+str+'"');
- }
- this.handleComplete=function(xhr,str)
- {
- // alert('Complete:"'+str+'"');
- }
-
- /**
- * Build the URL part that contains the addresses and filters
- */
- this.buildRequest = function()
- {
- var requestAddresses = (this.addresses.length)?'a=' + this.addresses.join( '&a=' ):'';
- var requestFilters = (this.filters.length )?'f=' + this.filters.join( '&f=' ):'';
- return requestAddresses + ( (this.addresses.length&&this.filters.length)?'&':'' ) + requestFilters;
- }
-
- /**
- * Subscribe to the addresses in the parameter
- * The second parameter (filter) is optional
- */
- this.subscribe = function( addresses, filters )
- {
- var startCommunication = !this.addresses.length; // start when addresses were empty
- this.addresses = addresses;
- this.filters = filters ? filters : [] ;
-
- if( !addresses.length ) this.stop(); // stop when new addresses are empty
- else if( startCommunication ) this.login();
- }
-
- /**
- * This function starts the communication by a login and then runs the
- * ongoing communication task
- */
- this.login = function()
- {
- var request = {};
- if( '' != this.user ) request.u = this.user;
- if( '' != this.pass ) request.p = this.pass;
- if( '' != this.device ) request.d = this.device;
- $.ajax( {url:this.urlPrefix + 'l',dataType: 'json',context:this,data:request, success:this.handleSession} );
- };
-
- /**
- * This function stops an ongoing connection
- */
- this.stop = function()
- {
- this.running = false;
- };
-
- /**
- * This function sends a value
- */
- this.write = function( address, value, datatype ) // FIXME datatype not in spec!!!
- {
- //var request = {};
- //request.a = address; // FIXME the spec allows multiple addresses
- //request.v = value;
-var request = 'a=' + address + '&v=' + value;
-datatype = datatype.split('.');
-request += '&d=' + datatype[0]; // FIXME datatype not in spec!!!
- $.ajax( {url:this.urlPrefix + 'w',dataType: 'json',context:this,data:request} );
-//alert( 'write to "' + address + '" value "' + value + '"' );
- }
-};
-
-CometVisu.prototype.update = function( json ) {}
Deleted: CometVisu/trunk/visu/lib/visudesign_custom.js
===================================================================
--- CometVisu/trunk/visu/lib/visudesign_custom.js 2010-11-20 11:38:10 UTC (rev 144)
+++ CometVisu/trunk/visu/lib/visudesign_custom.js 2010-11-20 18:23:39 UTC (rev 145)
@@ -1,75 +0,0 @@
-/* visudesign_custom.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-*/
-
-/**
- * This class defines all the custom changes to the visu
- */
-function VisuDesign_Custom() {}; // do NOT change here
-VisuDesign_Custom.prototype = new VisuDesign(); // do NOT chagen here
-
-/**
- * Custom changes could go here and look e.g. like
-****************************************
-VisuDesign_Custom.prototype.addCreator("line", {
- create: function( page, path ) {
- return $( '<hr />' );
- },
- attributes: {
- },
- content: false
-});
-****************************************
- */
-
-/**
- * This is a custom function that extends the available widgets.
- * It's purpose is to change the design of the visu during runtime
- * to demonstrate all available
- */
-VisuDesign_Custom.prototype.addCreator("designtoggle", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'switch' );
- var label = '<div class="label">' + page.textContent + '</div>';
- var actor = '<div class="actor switchUnpressed">';
- var value = $('link[href*="designs"]').attr('href').split('/')[1];
- actor += '<div class="value">' + value + '</div>';
- actor += '</div>';
- ret_val.append(label).append($(actor)
- .data({
- 'mapping' : $(page).attr('mapping'),
- 'styling' : $(page).attr('styling'),
- 'value' : value,
- 'type' : 'toggle'
- })
- .bind('click', function() {
- var designs = [ 'pure', 'discreet' ];
- var oldDesign = $('.value',this).text();
- var newDesign = designs[ (designs.indexOf(oldDesign) + 1) % designs.length ];
- $('.value',this).text(newDesign);
- $('link[href*="designs"]').each(function(){
- this.href = this.href.replace( oldDesign, newDesign );
- });
- })
- );
- return ret_val;
- },
- attributes: {
- },
- content: {type: "string", required: true}
-});
-
Deleted: CometVisu/trunk/visu/lib/visudesign_pure.js
===================================================================
--- CometVisu/trunk/visu/lib/visudesign_pure.js 2010-11-20 11:38:10 UTC (rev 144)
+++ CometVisu/trunk/visu/lib/visudesign_pure.js 2010-11-20 18:23:39 UTC (rev 145)
@@ -1,334 +0,0 @@
-/* visudesign_pure.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-*/
-
-/**
- * This class defines all the building blocks for a Visu in the "Pure" design
- */
-function VisuDesign() {
- this.creators = {};
-
- this.addCreator = function (name, object) {
- this.creators[name] = object;
- }
-
- this.getCreator = function(name) {
- if (typeof this.creators[name] == undefined) {
- return this.creators.unknown;
- }
- return this.creators[name];
- }
-
- /**
- * The creators object contians all widgets creators and their mappin to the
- * XML config file tags
- */
- this.addCreator("page", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- var style = ( '0' != path ) ? 'display:none' : '';
- var name = $(page).attr('name'); //path += '_' + name;
- var type = $(page).attr('type'); //text, 2d or 3d
- ret_val.addClass( 'link' ).addClass("pagelink");
- ret_val.append( '<a href="javascript:scrollToPage(\''+path+'\')">' + name + '</a>' );
- var childs = $(page).children();
- var container = $( '<div class="clearfix"/>' );
-
- container.append( '<h1>' + name + '</h1>' );
- $( childs ).each( function(i){
- container.append( create_pages(childs[i], path + '_' + i ) );
- } );
- $('#pages').prepend( $( '<div class="page" id="' + path + '" style="'+style+';"/>' ).append(container) );
- return ret_val;
- },
- attributes: {
- name: {type: "string", required: true}
- },
- content: true
- });
-
- this.addCreator("line", {
- create: function( page, path ) {
- return $( '<hr />' );
- },
- attributes: {
- },
- content: false
- });
-
- this.addCreator("break", {
- create: function( page, path ) {
- return $( '<br />' );
- },
- attributes: {
- },
- content: false
- });
-
-
- this.addCreator("text", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'text' );
- var style = '';
- if( $(page).attr('align') ) style += 'text-align:' + $(page).attr('align') + ';';
- if( style != '' ) style = 'style="' + style + '"';
- ret_val.append( '<div ' + style + '>' + page.textContent + '</div>' );
- return ret_val;
- },
- attributes: {
- align: {type: "string", required: false}
- },
- content: {type: "string", required: true}
- });
-
- this.addCreator("info", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'info' );
- var label = '<div class="label">' + page.textContent + '</div>';
- ga_list.push( $(page).attr('address') );
- var actor = '<div class="actor GA' + $(page).attr('address').split('/').join('_') + '">';
- if( $(page).attr('pre') ) actor += '<div>' + $(page).attr('pre') + '</div>';
- actor += '<div class="value">-</div>';
- if( $(page).attr('post') ) actor += '<div>' + $(page).attr('post') + '</div>';
- actor += '</div>';
- ret_val.append( label ).append( $(actor).data( {
- 'GA': $(page).attr('address'),
- 'datatype': $(page).attr('datatype'),
- 'mapping' : $(page).attr('mapping'),
- 'styling' : $(page).attr('styling')
- } ) );
- return ret_val;
- },
- attributes: {
- address: {type: "address", required: true},
- datatype: {type: "datatype", required: true},
- pre: {type: "string", required: false},
- post: {type: "string", required: false},
- mapping: {type: "mapping", required: false},
- styling: {type: "styling", required: false}
- },
- content: {type: "string", required: true}
- });
-
- this.addCreator("shade", this.getCreator("info"));
-
-
- this.addCreator("dim", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'dim' );
- var label = '<div class="label">' + page.textContent + '</div>';
- ga_list.push( $(page).attr('address') );
- var actor = $('<div class="actor GA' + $(page).attr('address').split('/').join('_') + '" />');
- ret_val.append( label ).append( actor );
- var min = parseFloat( $(page).attr('min') || 0 );
- var max = parseFloat( $(page).attr('max') || 100 );
- var step = parseFloat( $(page).attr('step') || 0.5 );
- ret_val.find('.actor').data( {
- 'events': $(actor).data( 'events' ),
- 'GA': $(page).attr('address'),
- 'datatype': $(page).attr('datatype'),
- 'mapping' : $(page).attr('mapping'),
- 'styling' : $(page).attr('styling'),
- 'min' : min,
- 'max' : max,
- 'step' : step,
- 'type' : 'dim'
- }).slider({step:step,min:min,max:max, animate: true,start:slideStart,change:slideChange});//slide:slideAction});
-
- return ret_val;
- },
- attributes: {
- address: {type: "address", required: true},
- datatype: {type: "datatype", required: true},
- response_address: {type: "address", required: true},
- response_datatype: {type: "datatype", required: true},
- min: {type: "numeric", required: false},
- max: {type: "numeric", required: false},
- step: {type: "numeric", required: false},
- mapping: {type: "mapping", required: false},
- styling: {type: "styling", required: false}
- },
- content: {type: "string", required: true}
- });
-
- this.addCreator("slide", this.getCreator("dim"));
-
- this.addCreator("switch", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'switch' );
- var label = '<div class="label">' + page.textContent + '</div>';
- var response_address = $(page).attr('response_address');
- ga_list.push( response_address );
- var actor = '<div class="actor GA' + response_address.split('/').join('_') + ' switchUnpressed">';
- if( $(page).attr('pre') ) actor += $(page).attr('pre');
- actor += '<div class="value">-</div>';
- if( $(page).attr('post') ) actor += $(page).attr('post');
- actor += '</div>';
- ret_val.append( label ).append( $(actor).data( {
- 'GA': $(page).attr('address'),
- 'datatype': $(page).attr('datatype'),
- 'mapping' : $(page).attr('mapping'),
- 'styling' : $(page).attr('styling'),
- 'type' : 'toggle'
- } ).bind('click',switchAction) );
- return ret_val;
- },
- attributes: {
- address: {type: "address", required: true},
- datatype: {type: "datatype", required: true},
- response_address: {type: "address", required: true},
- response_datatype: {type: "datatype", required: true},
- pre: {type: "string", required: false},
- post: {type: "string", required: false},
- mapping: {type: "mapping", required: false},
- styling: {type: "styling", required: false}
- },
- content: {type: "string", required: true}
- });
-
- this.addCreator("toggle", this.getCreator("switch"));
-
- this.addCreator("trigger", {
- create: function( page, path ) {
- var value = $(page).attr('value') ? $(page).attr('value') : 0;
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'switch' );
- var label = '<div class="label">' + page.textContent + '</div>';
- var address = $(page).attr('address');
- var actor = '<div class="actor switchUnpressed">';
- if( $(page).attr('pre') ) actor += $(page).attr('pre');
- var map = $(page).attr('mapping');
- if( mappings[map] && mappings[map][value] )
- actor += '<div class="value">' + mappings[map][value] + '</div>';
- else
- actor += '<div class="value">' + value + '</div>';
- if( $(page).attr('post') ) actor += $(page).attr('post');
- actor += '</div>';
- ret_val.append( label ).append( $(actor).data( {
- 'GA' : $(page).attr('address'),
- 'datatype': $(page).attr('datatype'),
- 'mapping' : $(page).attr('mapping'),
- 'styling' : $(page).attr('styling'),
- 'type' : 'trigger',
- 'sendValue': value
- } ).bind('click',triggerAction) );
-
- return ret_val;
- },
- attributes: {
- address: {type: "address", required: true},
- datatype: {type: "datatype", required: true},
- value: {type: "string", required: true},
- pre: {type: "string", required: false},
- post: {type: "string", required: false},
- mapping: {type: "mapping", required: false},
- styling: {type: "styling", required: false}
- },
- content: {type: "string", required: true}
- });
-
- this.addCreator("image", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'image' );
- ret_val.append( '<div class="label">' + page.textContent + '</div>' );
- var style = '';
- if( $(page).attr('width') ) style += 'width:' + $(page).attr('width') + ';';
- if( $(page).attr('height') ) style += 'height:' + $(page).attr('height') + ';';
- if( style != '' ) style = 'style="' + style + '"';
- var actor = '<div class="actor"><img src="' +$(page).attr('src') + '" ' + style + ' /></div>';
- var refresh = $(page).attr('refresh') ? $(page).attr('refresh')*1000 : 0;
- ret_val.append( $(actor).data( {
- 'refresh': refresh
- } ).each(setupRefreshAction) ); // abuse "each" to call in context...
- return ret_val;
- },
- attributes: {
- src: {type: "uri", required: true},
- width: {type: "string", required: false},
- height: {type: "string", required: false},
- refresh: {type: "numeric", required: false}
- },
- content: {type: "string", required: false}
- });
-
- this.addCreator("video", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.addClass( 'video' );
- ret_val.append( '<div class="label">' + page.textContent + '</div>' );
- var style = '';
- if( $(page).attr('width') ) style += 'width:' + $(page).attr('width') + ';';
- if( $(page).attr('height') ) style += 'height:' + $(page).attr('height') + ';';
- if( style != '' ) style = 'style="' + style + '"';
- var actor = '<div class="actor"><video src="' +$(page).attr('src') + '" ' + style + ' controls="controls" /></div>';
- var refresh = $(page).attr('refresh') ? $(page).attr('refresh')*1000 : 0;
- ret_val.append( $(actor).data( {
- 'refresh': refresh
- } ).each(setupRefreshAction) ); // abuse "each" to call in context...
- return ret_val;
- },
- attributes: {
- src: {type: "uri", required: true},
- width: {type: "string", required: false},
- height: {type: "string", required: false},
- refresh: {type: "numeric", required: false}
- },
- content: {type: "string", required: true}
- });
-
- this.addCreator("unknown", {
- create: function( page, path ) {
- var ret_val = $('<div class="widget" />');
- ret_val.append( '<pre>' + page.textContent + '</pre>' );
- return ret_val;
- },
- attributes: {
- },
- content: {type: "string", required: true}
- });
-
- this.switchAction = function() {
- var data = $(this).data();
- // alert( data.GA + ' = ' + data.value );
- visu.write( data.GA, data.value=='1' ? '0' : '1', data.datatype );
- }
-
- this.slideAction = function(event,ui) {
- //alert(ui.value);
- var now = new Date().getTime();
- var data = $( '.actor', $(this).parent() ).data();
- if( data.last && (now - data.last) < 1000 ) return; // too fast => early exit
- $( '.actor', $(this).parent() ).data( 'last', now );
- //$(this).parent().data();
- // alert( data.GA + ' = ' + data.value );
- //visu.write( data.GA, data.value=='1' ? '0' : '1', data.datatype );
- //FIXME eigentlich richtig... visu.write( data.GA, ui.value, data.datatype );
- }
-
- /**
- * Setup a refresh interval in seconds if the 'refresh' in the .data()
- * ist bigger than 0
- */
- this.refreshAction = function(that) {
- var data = $(this).data();
- alert('this.refreshAction');
- }
-};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|