Initial commit
This commit is contained in:
		
							
								
								
									
										43
									
								
								chain.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								chain.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const Dragonfly = global.Dragonfly;
 | 
				
			||||||
 | 
					const cl = global.botanLoader;
 | 
				
			||||||
 | 
					const doT = require("dot");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const OChain = cl.load( "botansx.mvc.model.chain" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Chain extends OChain
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						HFC( viewData, hfData, handler )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							var _self = this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							viewData.modules.push(
 | 
				
			||||||
 | 
								"Astro.Starfall.Element.Header"
 | 
				
			||||||
 | 
								, "Astro.Starfall.Layout.MainFrame"
 | 
				
			||||||
 | 
								, "Astro.Starfall.Element.Footer"
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var options = hfData.templating || {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var chainHandler = function( def, data, _class )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								var view = doT.template( data, options[ _class ], _self.utils );
 | 
				
			||||||
 | 
								viewData["footer"] = view( hfData );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								handler();
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var chainFooter = function( def, data, _class )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								var view = doT.template( data, options[ _class ], _self.utils );
 | 
				
			||||||
 | 
								viewData["header"] = view( hfData );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								_self.Template( "Element.Footer", chainHandler );
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							this.Template( "Element.Header", chainFooter );
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = Chain;
 | 
				
			||||||
							
								
								
									
										143
									
								
								vflow.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								vflow.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,143 @@
 | 
				
			|||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const cl = global.botanLoader;
 | 
				
			||||||
 | 
					const Dragonfly = global.Dragonfly;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const doT = require("dot");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const Chain = require( "./chain" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var VFlow = function( controller )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						var _self = this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return function( so, ro )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							Dragonfly.Debug( "Using Flow: Chain" );
 | 
				
			||||||
 | 
							// Retain the scope of caller
 | 
				
			||||||
 | 
							_self.scope = this;
 | 
				
			||||||
 | 
							_self.chains = new Chain( _self.Render.bind( _self ) );
 | 
				
			||||||
 | 
							_self.chains.onError = _self.onError.bind( _self );
 | 
				
			||||||
 | 
							_self.init( so, ro );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							new controller( _self, _self.viewData );
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VFlow.prototype.endFlow = function( layout, ext )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						var _self = this;
 | 
				
			||||||
 | 
						var viewData = this.viewData;
 | 
				
			||||||
 | 
						var options = viewData.templating || {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Layout Chain: Two Column
 | 
				
			||||||
 | 
						var twoColHandle = function( def, data, _class )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							var view = doT.template( data, options[ _class ], def );
 | 
				
			||||||
 | 
							viewData.context = view( viewData );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ElemHandle();
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Element Header / Footer
 | 
				
			||||||
 | 
						var ElemHandle = function ()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							_self.chains.HFC( viewData, viewData, HCFHandle );
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Layout Chain: Header - Content - Footer
 | 
				
			||||||
 | 
						var HCFHandle = function ()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							_self.chains.Template( "Layout.HCF", BackboneHandle );
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Html Backbone
 | 
				
			||||||
 | 
						var BackboneHandle = function ( def, data, _class )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if( data )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								var view = doT.template( data, options[ _class ], def );
 | 
				
			||||||
 | 
								viewData.body = view( viewData );
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var jc = _self.chains.Multi(
 | 
				
			||||||
 | 
								"BotanJs"
 | 
				
			||||||
 | 
								, () => _self.chains.Template( "Layout.HTML", FinalHandle )
 | 
				
			||||||
 | 
							, 2 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							viewData.modules.addListener( "error", function( e, b )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								throw new Error( e + "\n" + b );
 | 
				
			||||||
 | 
							} );
 | 
				
			||||||
 | 
							viewData.modules.addListener( "complete", jc );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							viewData.modules.compile( "js" );
 | 
				
			||||||
 | 
							viewData.modules.compile( "css" );
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var FinalHandle = function( def, data, _class )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							var view = doT.template( data, options[ _class ], def );
 | 
				
			||||||
 | 
							_self.Render( view( viewData ) );
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if( layout === undefined ) layout = "Elem";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var chainLayouts = (
 | 
				
			||||||
 | 
							({ // Defined layout chains
 | 
				
			||||||
 | 
								"TwoCol": function()
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									viewData.modules.push( "Astro.Starfall.Layout.TwoColumn" );
 | 
				
			||||||
 | 
									_self.chains.Template( "Layout.TwoColumn", twoColHandle ); 
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								, "PureCol": function()
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									viewData.modules.push( "Astro.Starfall.Layout.PureColumn" );
 | 
				
			||||||
 | 
									_self.chains.Template( "Layout.PureColumn", BackboneHandle );
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								, "Elem": ElemHandle
 | 
				
			||||||
 | 
								, "Backbone": BackboneHandle
 | 
				
			||||||
 | 
							}) [ layout ]
 | 
				
			||||||
 | 
							// Fallback to try out undefined template chains
 | 
				
			||||||
 | 
							|| function() { _self.chains.Template( layout, FinalHandle, ext ); }
 | 
				
			||||||
 | 
						)();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VFlow.prototype.init = function( so, ro )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						this.so = so;
 | 
				
			||||||
 | 
						this.routeObj = ro;
 | 
				
			||||||
 | 
						this.viewData = {};
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VFlow.prototype.onError = function( err )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if( err )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							Dragonfly.Error( err );
 | 
				
			||||||
 | 
							this.routeObj.reRoute( "500", true );
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VFlow.prototype.Render = function( r )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						Dragonfly.Info( "Render" );
 | 
				
			||||||
 | 
						this.scope.result = r;
 | 
				
			||||||
 | 
						this.scope.plantResult();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VFlow.create = function( c )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// Proxy the controller
 | 
				
			||||||
 | 
						//    Do not use arrow function
 | 
				
			||||||
 | 
						//    Because the scope will be binded here
 | 
				
			||||||
 | 
						//    We don't wanna do that
 | 
				
			||||||
 | 
						return function( a, b )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							var cf = new VFlow( c );
 | 
				
			||||||
 | 
							return cf.bind( this )( a, b );
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = VFlow;
 | 
				
			||||||
		Reference in New Issue
	
	Block a user