lib/controllers/wirings.js
function run_wiring(wiring, req, res, format) {
	
	 var filteredParams = req.query;
	// TODO
    /*filteredParams = params.dup
    filteredParams.delete("id")
    filteredParams.delete("action")
    filteredParams.delete("controller")
    filteredParams.delete("callback")
    filteredParams.delete("format")*/
	
	
	mySimpleflowRunWithActivity(wiring, req.current_user._id, format, "web", 
			filteredParams, false, req.wiring_collection, function(results) {
		
				if(format == "html") {
					// Reder the template
					if( !!wiring.template && !req.param("notemplate") ) {
						res.header('Content-Type', wiring.template_content_type);
						var output;
						try {
							output = ejs.render(wiring.template, {
								locals: {
									results: results,
									params: filteredParams
								}
							});
						} catch(ex) {
							output = "Error in your template: "+ex.message;
						}
						res.send(output);

					} 
					// Render the result of the "outputField" variable as a html document
					else if( req.param('outputField') ) {
						res.header('Content-Type', "text/html");
						if(results.hasOwnProperty(req.param('outputField'))) {
							res.send( results[req.param('outputField')] );
						}
						else {
							res.send( "No field called "+req.param('outputField') );
						}
			       }
				    else {
						// render run.ejs
						res.render('wirings/run', {
					        locals: {
									title: "Wiring "+wiring.name,
									action: "wirings",
									wiring: wiring,
									params: filteredParams,
									results: results
					        }
					    });
					}
				}
				/*else if(format == "xml") {
				}*/
				else if(format == "json") {
					
					if(req.param("callback")) {
						res.header('Content-Type', 'text/javascript');
						
						res.send("if(typeof "+req.param("callback")+" == 'function') {"+
									req.param("callback")+"("+JSON.stringify(results)+");} else {\n"+
									"if (typeof console!== 'undefined' && typeof console.log !== 'undefined'){\n"+
									"console.log('Error: Callback method not defined');}	}");
					}
					else {
						res.header('Content-Type', 'application/json');
						res.send(JSON.stringify(results));
					}
				}
				/*else if(format == "txt") {
					if results.keys.size == 1
						if results.values[0].is_a?(String)
							render :text => results.values[0]
							return
						end
					else
						# TODO: check if param outputField
					end

					render :text => "blabla"
				}*/		
				
	});
		
}
function run_wiring(wiring, req, res, format) {
	
	 var filteredParams = req.query;
	// TODO
    /*filteredParams = params.dup
    filteredParams.delete("id")
    filteredParams.delete("action")
    filteredParams.delete("controller")
    filteredParams.delete("callback")
    filteredParams.delete("format")*/
	
	
	mySimpleflowRunWithActivity(wiring, req.current_user._id, format, "web", 
			filteredParams, false, req.wiring_collection, function(results) {
		
				if(format == "html") {
					// Reder the template
					if( !!wiring.template && !req.param("notemplate") ) {
						res.header('Content-Type', wiring.template_content_type);
						var output;
						try {
							output = ejs.render(wiring.template, {
								locals: {
									results: results,
									params: filteredParams
								}
							});
						} catch(ex) {
							output = "Error in your template: "+ex.message;
						}
						res.send(output);

					} 
					// Render the result of the "outputField" variable as a html document
					else if( req.param('outputField') ) {
						res.header('Content-Type', "text/html");
						if(results.hasOwnProperty(req.param('outputField'))) {
							res.send( results[req.param('outputField')] );
						}
						else {
							res.send( "No field called "+req.param('outputField') );
						}
			       }
				    else {
						// render run.ejs
						res.render('wirings/run', {
					        locals: {
									title: "Wiring "+wiring.name,
									action: "wirings",
									wiring: wiring,
									params: filteredParams,
									results: results
					        }
					    });
					}
				}
				/*else if(format == "xml") {
				}*/
				else if(format == "json") {
					
					if(req.param("callback")) {
						res.header('Content-Type', 'text/javascript');
						
						res.send("if(typeof "+req.param("callback")+" == 'function') {"+
									req.param("callback")+"("+JSON.stringify(results)+");} else {\n"+
									"if (typeof console!== 'undefined' && typeof console.log !== 'undefined'){\n"+
									"console.log('Error: Callback method not defined');}	}");
					}
					else {
						res.header('Content-Type', 'application/json');
						res.send(JSON.stringify(results));
					}
				}
				/*else if(format == "txt") {
					if results.keys.size == 1
						if results.values[0].is_a?(String)
							render :text => results.values[0]
							return
						end
					else
						# TODO: check if param outputField
					end

					render :text => "blabla"
				}*/		
				
	});
		
}
function run_wiring ( wiring , req , res , format ) { var filteredParams = req . query ; // TODO /*filteredParams = params.dup
    filteredParams.delete("id")
    filteredParams.delete("action")
    filteredParams.delete("controller")
    filteredParams.delete("callback")
    filteredParams.delete("format")*/ mySimpleflowRunWithActivity ( wiring , req . current_user . _id , format , "web" , filteredParams , false , req . wiring_collection , function ( results ) { if ( format == "html" ) { // Reder the template if ( ! ! wiring . template && ! req . param ( "notemplate" ) ) { res . header ( 'Content-Type' , wiring . template_content_type ) ; var output ; try { output = ejs . render ( wiring . template , { locals : { results : results , params : filteredParams } } ) ; } catch ( ex ) { output = "Error in your template: " + ex . message ; } res . send ( output ) ; } // Render the result of the "outputField" variable as a html document else if ( req . param ( 'outputField' ) ) { res . header ( 'Content-Type' , "text/html" ) ; if ( results . hasOwnProperty ( req . param ( 'outputField' ) ) ) { res . send ( results [ req . param ( 'outputField' ) ] ) ; } else { res . send ( "No field called " + req . param ( 'outputField' ) ) ; } } else { // render run.ejs res . render ( 'wirings/run' , { locals : { title : "Wiring " + wiring . name , action : "wirings" , wiring : wiring , params : filteredParams , results : results } } ) ; } } /*else if(format == "xml") {
				}*/ else if ( format == "json" ) { if ( req . param ( "callback" ) ) { res . header ( 'Content-Type' , 'text/javascript' ) ; res . send ( "if(typeof " + req . param ( "callback" ) + " == 'function') {" + req . param ( "callback" ) + "(" + JSON . stringify ( results ) + ");} else {\n" + "if (typeof console!== 'undefined' && typeof console.log !== 'undefined'){\n" + "console.log('Error: Callback method not defined');}	}" ) ; } else { res . header ( 'Content-Type' , 'application/json' ) ; res . send ( JSON . stringify ( results ) ) ; } } /*else if(format == "txt") {
					if results.keys.size == 1
						if results.values[0].is_a?(String)
							render :text => results.values[0]
							return
						end
					else
						# TODO: check if param outputField
					end

					render :text => "blabla"
				}*/ } ) ; }
Run the wiring !
Run the wiring !