<commit_before>/**
 * Author: Olaolu Olawuyi

 * Date Created: 20/08/2015

 * Last Modified: 06/04/2016

 * Twitter: @whizkydee, @webtwic

 * Github: https://github.com/webtwic/webtwic-site

*/

var Webtwic = Webtwic || {};

var browser = bowser;

var test_canvas = document.createElement( 'canvas' );
var canvascheck = ( test_canvas.getContext ) ? true : false;

Webtwic = {
	// Basic Information about Webtwic
	name: 'Webtwic',
	description: 'A community focused on code tweaks, articles and tutorials for newbie and professional developers.',
	repo: 'https://github.com/webtwic/webtwic-site',
	author: 'Olaolu Olawuyi',
	version: '1.0.0',

	// Start main functions for the object

	// Function to add browser name and version to body class
	showBrowser: function( b ) {
		b = (typeof b == 'undefined') ? browser.name.toLowerCase() : b.toLowerCase();
		$( 'body' ).addClass( b + ' ' + b + parseInt( browser.version ) );
	},

	// Function to set attributes and values to elements
	setAttr: function( elem, name, val ) {
		$( elem, this ).attr( name, val );
	},

	// Function to push down .site-content
	adjustSiteContent: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).addClass( 'adjustedMargin' );
			$( '#header .logo' ).addClass( 'adjustedTop' );
			$( '.main-menu' ).addClass( 'adjustedMargin' );
			$( '#header' ).addClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.site-content' ).addClass( 'adjustSiteContent' );
			$( '.secondary-header' ).addClass( 'adjustedMargin' );
		}
	},

	// Function to push up .site-content to default state
	undoSiteAdjust: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).removeClass( 'adjustedMargin' );
			$( '#header .logo' ).removeClass( 'adjustedTop' );
			$( '.main-menu' ).removeClass( 'adjustedMargin' );
			$( '#header' ).removeClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.secondary-header' ).removeClass( 'adjustedMargin' );
		}
	},

	// Function to show Notifications before header
	showNotif: function( text ) {
		text = ( typeof text == 'undefined' ) ? notif_text : text;
		Webtwic.adjustSiteContent();
		$( 'body' ).prepend(
			'
"+text+""+close_button+"
'
		);

		$( '.close-button' ).on( 'click', function( e ) {
			e.preventDefault();
			Webtwic.undoReset();
		});
	},

	// Function to hide Notifications
	hideNotif: function() {
		$( '#notifBanner' ).removeClass( 'notif_vis' );
	},

	resetSite: function() {
		Webtwic.showNotif();
		Webtwic.adjustSiteContent();
	},

	undoReset: function() {
		Webtwic.hideNotif();
		Webtwic.undoSiteAdjust();
	},
};

var WBT = Webtwic,

	 $$ = Webtwic,

	 close_button = '',

	 browser_link = ' ' + 'browser.' + ' ',

	 notif_text = 'Some features which affect the functionality of webtwic are disabled in your browser. Please try refreshing the page or get a better' +browser_link;

// Detect when the DOM is ready

jQuery( document ).ready( function() {
	// Test for HTML5 support
	if ( window.Modernizr ) {
		if ( !Modernizr.canvas ) {
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		} else {
			// Do nothing.
		}
	} else if ( !window.Modernizr ) {
		if ( canvascheck === false ) {
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		} else {
			// Do nothing.
		}
	} else {
		// Do nothing.
	}

	// Define Variables
	var $scroll_top = $( 'a.scroll_top' ),
	is_toggle_active = $( '.hamburger' ).hasClass( 'is_active' ),
	height = 200;

	// Performance Fixes

	// Start browser detection

	browser.ie = browser.msie;

	if ( browser.chrome ) {
		Webtwic.showBrowser();
	}
	else if ( browser.msedge ) {
		Webtwic.showBrowser();
	}
	else if ( browser.firefox ) {
		Webtwic.showBrowser();
	}
	else if ( browser.msie ) {
		Webtwic.showBrowser();
	}
	else if ( browser.safari ) {
		Webtwic.showBrowser();
	}
	else if ( browser.opera ) {
		Webtwic.showBrowser();
	} else {
		// Do nothing.
	}

	/*
		TODO: Rebuild Performance fixes for attributes
		See history of Performance fixes.
		Also, check StackOverflow.
		See Issue #12
	*/

	if ( window.Modernizr ) {
		if ( !Modernizr.flexbox || !Modernizr.inlinesvg || !Modernizr.svg || !Modernizr.svgclippaths || !Modernizr.fontface || !Modernizr.boxshadow || !Modernizr.borderradius || !Modernizr.csstransforms ) {
			Webtwic.showNotif();
		} else {
			// Do nothing.
		}
	} else {
		// Do nothing.
	}

	// Start Main Page

	$( 'nav li ul.drop-nav' )
	.hide()
	.removeClass( 'dropNavFallback' );

	if ( $( window ).width() > 768 ) {
		$( 'nav li.dropdown' ).hover(function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideDown( 'fast' );
		}, function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideUp( 'fast' );
		});
	}

	$( '.active-item' ).append(
		'<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M 16.682,19.674c 0.010-0.012, 0.014-0.028, 0.024-0.040l 6.982-7.714c 0.39-0.434, 0.39-1.138,0-1.572 c-0.004-0.004-0.008-0.006-0.012-0.008C 23.496,10.13, 23.244,10, 22.964,10L 8.998,10 c-0.286,0-0.54,0.138-0.722,0.352L 8.272,10.348 c-0.39,0.434-0.39,1.138,0,1.572l 6.998,7.754C 15.66,20.108, 16.292,20.108, 16.682,19.674z"></path></svg>'
	);

	$( 'a.hamburger' ).click(function( e ) {
		$( this ).toggleClass( 'is_active' );

		e.preventDefault();
	});
	$( '.mobile-header .mobile-nav' ).hide();

	$( window ).scroll(function() {
		( $( this ).scrollTop() > height ) ? $scroll_top.addClass( 'topVisible' ): $scroll_top.removeClass( 'topVisible' );
	});

	// Styles for homepage article-social

	$( '.article .article-social a' ).hover(function() {
		$( 'span', this )
		.eq(1)
		.fadeIn(400);
	}, function() {
		$( 'span', this )
		.eq(1)
		.fadeOut(250);
	});

	// Functions for search-icon and ui-overlay-search

	$( '.header-follow-search .search-wrap' ).on( 'click', function() {
		openUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).on( 'click', function( e ) {
		e.preventDefault();
		closeUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).hover(
		function() {
			$( this ).addClass( 'spin' );
		}, function() {
			$( this ).removeClass( 'spin' );
	});

	function openUiOverlay() {
		$( '.ui-overlay-search' )
		.fadeIn(400)
		.addClass( 'is_open' );
	}

	function closeUiOverlay() {
		$( '.ui-overlay-search' )
		.fadeOut(400)
		.removeClass( 'is_open' );
	}

	$( '.ui-overlay-search .search-input input' ).focus(function() {
		$( '.search-input' ).data( 'focused', 'true' );
		$( '.search-input input' ).addClass( '_is-focused' );
		$( '#__expand' ).addClass( 'visible' );
	});

	$( '.ui-overlay-search .search-input input' ).blur(function() {
		$( '.search-input' ).data( 'focused', 'false' );
		$( '.search-input input' ).removeClass( '_is-focused' );
		$( '#__expand' ).removeClass( 'visible' );
	});

	$( '.post-meta .post-meta-inner .cta-btns a.is_inactive' ).on( 'click', function( e ) {
		e.preventDefault();
	});

	$( document ).keydown(function( e ) {
		if ( e.keyCode == 27 ) {
			closeUiOverlay();
		} else {
			// Do nothing.
		}
 	});

	$( '.mobile-nav' ).hide();

	// Functions for more-posts button click

	var loadMoreBtn = '.secondary-category-section .category-posts-column [data-clicked="false"]';

	function addLoader() {
		$( loadMoreBtn ).data( 'clicked', 'true' ).append( '' );
	}

	$( loadMoreBtn ).on( 'click', function( e ) {
		$( this ).css({
			'background': '#50ABF1',
			'color': '#fff'
		});
		addLoader();
		e.preventDefault();
	});

	$scroll_top.on( 'click', function( e ) {
		$( 'body, html' ).animate({
			scrollTop: 0
		}, 1000);

		e.preventDefault();
	});

});
<commit_msg>Fix conflicts<commit_after>/**
 * Author: Olaolu Olawuyi

 * Date Created: 20/08/2015

 * Last Modified: 06/04/2016

 * Twitter: @whizkydee, @webtwic

 * Github: https://github.com/webtwic/webtwic-site

*/

var Webtwic = Webtwic || {};

var browser = bowser;

var test_canvas = document.createElement( 'canvas' );
var canvascheck = ( test_canvas.getContext ) ? true : false;

Webtwic = {
	// Basic Information about Webtwic
	name: 'Webtwic',
	description: 'A community focused on code tweaks, articles and tutorials for newbie and professional developers.',
	repo: 'https://github.com/webtwic/webtwic-site',
	author: 'Olaolu Olawuyi',
	version: '1.0.0',

	// Start main functions for the object

	// Function to add browser name and version to body class
	showBrowser: function( b ) {
		b = (typeof b == 'undefined') ? browser.name.toLowerCase() : b.toLowerCase();
		$( 'body' ).addClass( b + ' ' + b + parseInt( browser.version ) );
	},

	// Function to set attributes and values to elements
	setAttr: function( elem, name, val ) {
		$( elem, this ).attr( name, val );
	},

	// Function to push down .site-content
	adjustSiteContent: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).addClass( 'adjustedMargin' );
			$( '#header .logo' ).addClass( 'adjustedTop' );
			$( '.main-menu' ).addClass( 'adjustedMargin' );
			$( '#header' ).addClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.site-content' ).addClass( 'adjustSiteContent' );
			$( '.secondary-header' ).addClass( 'adjustedMargin' );
		}
	},

	// Function to push up .site-content to default state
	undoSiteAdjust: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).removeClass( 'adjustedMargin' );
			$( '#header .logo' ).removeClass( 'adjustedTop' );
			$( '.main-menu' ).removeClass( 'adjustedMargin' );
			$( '#header' ).removeClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.secondary-header' ).removeClass( 'adjustedMargin' );
		}
	},

	// Function to show Notifications before header
	showNotif: function( text ) {
		text = ( typeof text == 'undefined' ) ? notif_text : text;
		Webtwic.adjustSiteContent();
		$( 'body' ).prepend(
			'
"+text+""+close_button+"
'
		);

		$( '.close-button' ).on( 'click', function( e ) {
			e.preventDefault();
			Webtwic.undoReset();
		});
	},

	// Function to hide Notifications
	hideNotif: function() {
		$( '#notifBanner' ).removeClass( 'notif_vis' );
	},

	resetSite: function() {
		Webtwic.showNotif();
		Webtwic.adjustSiteContent();
	},

	undoReset: function() {
		Webtwic.hideNotif();
		Webtwic.undoSiteAdjust();
	},
};

var WBT = Webtwic,

	 $$ = Webtwic,

	 close_button = '',

	 browser_link = ' ' + 'browser.' + ' ',

	 notif_text = 'Some features which affect the functionality of webtwic are disabled in your browser. Please try refreshing the page or get a better' +browser_link;

// Detect when the DOM is ready

jQuery( document ).ready( function() {
	// Test for HTML5 support
	if ( window.Modernizr ) {
		if ( !Modernizr.canvas ) {
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		} else {
			// Do nothing.
		}
	} else if ( !window.Modernizr ) {
		if ( canvascheck === false ) {
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		} else {
			// Do nothing.
		}
	} else {
		// Do nothing.
	}

	// Define Variables
	var $scroll_top = $( 'a.scroll_top' ),
	is_toggle_active = $( '.hamburger' ).hasClass( 'is_active' ),
	height = 200;

	// Performance Fixes

	// Start browser detection

	browser.ie = browser.msie;

	if ( browser.chrome ) {
		Webtwic.showBrowser();
	}
	else if ( browser.msedge ) {
		Webtwic.showBrowser();
	}
	else if ( browser.firefox ) {
		Webtwic.showBrowser();
	}
	else if ( browser.msie ) {
		Webtwic.showBrowser();
	}
	else if ( browser.safari ) {
		Webtwic.showBrowser();
	}
	else if ( browser.opera ) {
		Webtwic.showBrowser();
	} else {
		// Do nothing.
	}

	/*
		TODO: Rebuild Performance fixes for attributes
		See history of Performance fixes.
		Also, check StackOverflow.
		See Issue #12
	*/

	if ( window.Modernizr ) {
		if ( !Modernizr.flexbox || !Modernizr.inlinesvg || !Modernizr.svg || !Modernizr.svgclippaths || !Modernizr.fontface || !Modernizr.boxshadow || !Modernizr.borderradius || !Modernizr.csstransforms ) {
			Webtwic.showNotif();
		} else {
			// Do nothing.
		}
	} else {
		// Do nothing.
	}

	// Start Main Page

	$( 'nav li ul.drop-nav' )
	.hide()
	.removeClass( 'dropNavFallback' );

	if ( $( window ).width() > 768 ) {
		$( 'nav li.dropdown' ).hover(function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideDown( 'fast' );
		}, function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideUp( 'fast' );
		});
	}

	$( '.active-item' ).append(
		'<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M 16.682,19.674c 0.010-0.012, 0.014-0.028, 0.024-0.040l 6.982-7.714c 0.39-0.434, 0.39-1.138,0-1.572 c-0.004-0.004-0.008-0.006-0.012-0.008C 23.496,10.13, 23.244,10, 22.964,10L 8.998,10 c-0.286,0-0.54,0.138-0.722,0.352L 8.272,10.348 c-0.39,0.434-0.39,1.138,0,1.572l 6.998,7.754C 15.66,20.108, 16.292,20.108, 16.682,19.674z"></path></svg>'
	);

	$( 'a.hamburger' ).click(function( e ) {
		$( this ).toggleClass( 'is_active' );

		e.preventDefault();
	});
	$( '.mobile-header .mobile-nav' ).hide();

	$( window ).scroll(function() {
		( $( this ).scrollTop() > height ) ? $scroll_top.addClass( 'topVisible' ): $scroll_top.removeClass( 'topVisible' );
	});

	// Styles for homepage article-social

	$( '.article .article-social a' ).hover(function() {
		$( 'span', this )
		.eq(1)
		.fadeIn(400);
	}, function() {
		$( 'span', this )
		.eq(1)
		.fadeOut(250);
	});

	// Functions for search-icon and ui-overlay-search

	$( '.header-follow-search .search-wrap' ).on( 'click', function() {
		openUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).on( 'click', function( e ) {
		e.preventDefault();
		closeUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).hover(
		function() {
			$( this ).addClass( 'spin' );
		}, function() {
			$( this ).removeClass( 'spin' );
	});

	function openUiOverlay() {
		$( '.ui-overlay-search' )
		.fadeIn(400)
		.addClass( 'is_open' );
	}

	function closeUiOverlay() {
		$( '.ui-overlay-search' )
		.fadeOut(400)
		.removeClass( 'is_open' );
	}

	$( '.ui-overlay-search .search-input input' ).focus(function() {
		$( '.search-input' ).attr( 'data-focused', 'true' );
		$( '.search-input input' ).addClass( '_is-focused' );
		$( '#__expand' ).addClass( 'visible' );
	});

	$( '.ui-overlay-search .search-input input' ).blur(function() {
		$( '.search-input' ).attr( 'data-focused', 'false' );
		$( '.search-input input' ).removeClass( '_is-focused' );
		$( '#__expand' ).removeClass( 'visible' );
	});

	$( '.post-meta .post-meta-inner .cta-btns a.is_inactive' ).on( 'click', function( e ) {
		e.preventDefault();
	});

	$( document ).keydown(function( e ) {
		if ( e.keyCode == 27 ) {
			closeUiOverlay();
		} else {
			// Do nothing.
		}
 	});

	$( '.mobile-nav' ).hide();

	// Functions for more-posts button click

	var loadMoreBtn = '.secondary-category-section .category-posts-column [data-clicked="false"]';

	function addLoader() {
		$( loadMoreBtn ).data( 'clicked', 'true' ).append( '' );
	}

	$( loadMoreBtn ).on( 'click', function( e ) {
		$( this ).css({
			'background': '#50ABF1',
			'color': '#fff'
		});
		addLoader();
		e.preventDefault();
	});

	$scroll_top.on( 'click', function( e ) {
		$( 'body, html' ).animate({
			scrollTop: 0
		}, 1000);

		e.preventDefault();
	});

});
<|endoftext|>


<commit_before>ig.module('game.entities.zombie')
.requires(
  'impact.impact',
  'impact.entity',
  'game.entities.particle-spawner',
  'game.effects.zombie-giblet',
  'game.effects.blood-giblet',
  'game.entities.dead-zombie'
)
.defines(function() {
  EntityZombie = ig.Entity.extend({
    // don't allow the editor to scale our object
    _wmScalable: false,

    // always draw a box around us
    _wmDrawBox: true,
    _wmBoxColor: 'rgba(255, 170, 66, 0.7)',

    pointValue: 100,

    animSheet: new ig.AnimationSheet( 'media/zombie.png', 32, 32 ),
    zIndex: 9,

    // the size of our collider
    size: { x: 8, y: 32 },

    health: 9,
    maxHealth: 9,

    deathEntity: EntityDeadZombie,

    // the offset of collider
    offset: { x: 12, y: 0 },

    // movement variables
    maxVel: { x: 6, y: 100 },
    friction: { x: 2000, y: 0 },
    accel: { x: 0, y: 0 },
    gravityFactor: 10,

    speed: 6000,

    // collision settings, collide against player
    type: ig.Entity.TYPE.B,
    checkAgainst: ig.Entity.TYPE.A,
    collides: ig.Entity.COLLIDES.PASSIVE,

    init: function( x, y, settings ) {
      this.parent( x, y, settings );

      // setup animations
      // true means do not repeat
      // idle is a system animation, called by default
      this.addAnim( 'idle', 3, [0], true);
      this.addAnim( 'walk', 0.15, [1,2,3,4,5,6,7,8]);

      this.flip = settings.flip || false;

      this.health = this.maxHealth = ig._.rndRange(4, 15);
    },

    kill: function() {
      // when the zombie dies, spawn a bunch of "giblets"
      var pos = {
        x: this.pos.x + this.size.x / 2,
        y: this.pos.y + this.size.y / 2
      };
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectZombieGiblet,
        particles: 5
      });
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectBloodGiblet,
        particles: 3
      });
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectZombieGibletSmall,
        particles: 30
      });
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectBloodGibletSmall,
        particles: 10
      });

      ig.game.spawnEntity( this.deathEntity, this.pos.x, this.pos.y, {
        flip: this.flip
      });

      // increase the players score
      if(this.lastDamageAmount < this.maxHealth) {
        // player shot too far away from the zombie
        // so they won't get as many points
        this.pointValue /= 2;
      }
      ig.game.hud.addPoints(this.pointValue);
      ig.game.waveDirector.remainingEnemies--;

      this.parent();
    },

    receiveDamage: function(amt, other) {
      this.parent(amt, other);
      this.lastDamageAmount = amt;

      ig.game.spawnEntity( EntityParticleSpawner, other.pos.x, other.pos.y, {
        Particle: EffectZombieGibletSmall,
        particles: ig._.rndRange(3, 7)
      });
    },

    check: function(other) {
      // when a zombie hits the player
      // the player should take damage
      other.receiveDamage(10, this);
    },

    update: function() {
      if ( this.vel.x != 0 ) {
        this.currentAnim = this.anims.walk;
      }

      this.accel.x = this.speed * (this.flip ? -1 : 1);
      this.currentAnim.flip.x = this.flip;

      this.parent();
    },

    handleMovementTrace: function( res ) {
      this.parent(res);

      // check the collision map, see if we're colliding with
      // a collision tile, if so then we need to turn around
      if( res.collision.x ) {
        this.flip = !this.flip;
      }
    }
  });
});
<commit_msg>zombie doesn crash weltmeister<commit_after>ig.module('game.entities.zombie')
.requires(
  'impact.impact',
  'impact.entity',
  'game.entities.particle-spawner',
  'game.effects.zombie-giblet',
  'game.effects.blood-giblet',
  'game.entities.dead-zombie'
)
.defines(function() {
  EntityZombie = ig.Entity.extend({
    // don't allow the editor to scale our object
    _wmScalable: false,

    // always draw a box around us
    _wmDrawBox: true,
    _wmBoxColor: 'rgba(255, 170, 66, 0.7)',

    pointValue: 100,

    animSheet: new ig.AnimationSheet( 'media/zombie.png', 32, 32 ),
    zIndex: 9,

    // the size of our collider
    size: { x: 8, y: 32 },

    health: 9,
    maxHealth: 9,

    deathEntity: EntityDeadZombie,

    // the offset of collider
    offset: { x: 12, y: 0 },

    // movement variables
    maxVel: { x: 6, y: 100 },
    friction: { x: 2000, y: 0 },
    accel: { x: 0, y: 0 },
    gravityFactor: 10,

    speed: 6000,

    // collision settings, collide against player
    type: ig.Entity.TYPE.B,
    checkAgainst: ig.Entity.TYPE.A,
    collides: ig.Entity.COLLIDES.PASSIVE,

    init: function( x, y, settings ) {
      this.parent( x, y, settings );

      // setup animations
      // true means do not repeat
      // idle is a system animation, called by default
      this.addAnim( 'idle', 3, [0], true);
      this.addAnim( 'walk', 0.15, [1,2,3,4,5,6,7,8]);

      this.flip = settings.flip || false;

      if(!ig.global.wm) {
        this.health = this.maxHealth = ig._.rndRange(4, 15);
      }
    },

    kill: function() {
      // when the zombie dies, spawn a bunch of "giblets"
      var pos = {
        x: this.pos.x + this.size.x / 2,
        y: this.pos.y + this.size.y / 2
      };
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectZombieGiblet,
        particles: 5
      });
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectBloodGiblet,
        particles: 3
      });
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectZombieGibletSmall,
        particles: 30
      });
      ig.game.spawnEntity( EntityParticleSpawner, pos.x, pos.y, {
        Particle: EffectBloodGibletSmall,
        particles: 10
      });

      ig.game.spawnEntity( this.deathEntity, this.pos.x, this.pos.y, {
        flip: this.flip
      });

      // increase the players score
      if(this.lastDamageAmount < this.maxHealth) {
        // player shot too far away from the zombie
        // so they won't get as many points
        this.pointValue /= 2;
      }
      ig.game.hud.addPoints(this.pointValue);
      ig.game.waveDirector.remainingEnemies--;

      this.parent();
    },

    receiveDamage: function(amt, other) {
      this.parent(amt, other);
      this.lastDamageAmount = amt;

      ig.game.spawnEntity( EntityParticleSpawner, other.pos.x, other.pos.y, {
        Particle: EffectZombieGibletSmall,
        particles: ig._.rndRange(3, 7)
      });
    },

    check: function(other) {
      // when a zombie hits the player
      // the player should take damage
      other.receiveDamage(10, this);
    },

    update: function() {
      if ( this.vel.x != 0 ) {
        this.currentAnim = this.anims.walk;
      }

      this.accel.x = this.speed * (this.flip ? -1 : 1);
      this.currentAnim.flip.x = this.flip;

      this.parent();
    },

    handleMovementTrace: function( res ) {
      this.parent(res);

      // check the collision map, see if we're colliding with
      // a collision tile, if so then we need to turn around
      if( res.collision.x ) {
        this.flip = !this.flip;
      }
    }
  });
});
<|endoftext|>


<commit_before>/**
 * core/modules data store: module info.
 *
 * Site Kit by Google, Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import merge from 'lodash/merge';
import invariant from 'invariant';

/**
 * WordPress dependencies
 */
import { WPElement } from '@wordpress/element';

/**
 * Internal dependencies
 */
import API from 'googlesitekit-api';
import Data from 'googlesitekit-data';
import { STORE_NAME } from './constants';
import { STORE_NAME as CORE_USER } from '../../datastore/user/constants';
import { createFetchStore } from '../../data/create-fetch-store';
import DefaultModuleSettings from '../components/DefaultModuleSettings';

const { createRegistrySelector, createRegistryControl } = Data;

// Actions.
const REFETCH_AUTHENTICATION = 'REFETCH_AUTHENTICATION';
const REGISTER_MODULE = 'REGISTER_MODULE';

const moduleDefaults = {
	name: '',
	description: '',
	icon: null,
	order: 10,
	homepage: null,
	active: false,
	connected: false,
	settingsComponent: DefaultModuleSettings,
};

const fetchGetModulesStore = createFetchStore( {
	baseName: 'getModules',
	controlCallback: () => {
		return API.get( 'core', 'modules', 'list', null, {
			useCache: false,
		} );
	},
	reducerCallback: ( state, modules ) => {
		return {
			...state,
			isAwaitingModulesRefresh: false,
			serverDefinitions: modules.reduce( ( acc, module ) => {
				return { ...acc, [ module.slug ]: module };
			}, {} ),
		};
	},
} );

const fetchSetModuleActivationStore = createFetchStore( {
	baseName: 'setModuleActivation',
	controlCallback: ( { slug, active } ) => {
		return API.set( 'core', 'modules', 'activation', {
			slug,
			active,
		} );
	},
	reducerCallback: ( state ) => {
		// Updated module activation state is handled by re-fetching module
		// data instead, so this reducer just sets the below flag.
		return {
			...state,
			isAwaitingModulesRefresh: true,
		};
	},
	argsToParams: ( slug, active ) => {
		return {
			slug,
			active,
		};
	},
	validateParams: ( { slug, active } = {} ) => {
		invariant( slug, 'slug is required.' );
		invariant( active !== undefined, 'active is required.' );
	},
} );

const BASE_INITIAL_STATE = {
	clientDefinitions: {},
	serverDefinitions: undefined,
	// This value is to indicate that modules data needs to be refreshed after
	// a module activation update, since the activation is technically complete
	// before this data has been refreshed.
	isAwaitingModulesRefresh: false,
};

const baseActions = {
	/**
	 * Activates a module on the server.
	 *
	 * Activate a module (based on the slug provided).
	 *
	 * @since 1.8.0
	 *
	 * @param {string} slug Slug of the module to activate.
	 * @return {Object}      Object with {response, error}
	 */
	*activateModule( slug ) {
		const { response, error } = yield baseActions.setModuleActivation( slug, true );

		return { response, error };
	},

	/**
	 * Deactivates a module on the server.
	 *
	 * Deactivate a module (based on the slug provided).
	 *
	 * @since 1.8.0
	 *
	 * @param {string} slug Slug of the module to activate.
	 * @return {Object}      Object with {response, error}
	 */
	*deactivateModule( slug ) {
		const { response, error } = yield baseActions.setModuleActivation( slug, false );

		return { response, error };
	},

	/**
	 * (De)activates a module on the server.
	 *
	 * POSTs to the `core/modules/activation` endpoint to set the `active` status
	 * supplied for the give `slug`.
	 *
	 * @since 1.8.0
	 * @private
	 *
	 * @param {string}  slug   Slug of the module to activate/deactivate.
	 * @param {boolean} active `true` to activate; `false` to deactivate.
	 * @return {Object}         Object with {response, error}
	 */
	*setModuleActivation( slug, active ) {
		invariant( slug, 'slug is required.' );
		invariant( active !== undefined, 'active is required.' );

		const { response, error } = yield fetchSetModuleActivationStore.actions.fetchSetModuleActivation( slug, active );
		if ( response?.success === true ) {
			// Fetch (or re-fetch) all modules, with their updated status.
			yield fetchGetModulesStore.actions.fetchGetModules();
			yield {
				payload: {},
				type: REFETCH_AUTHENTICATION,
			};
		}

		return { response, error };
	},

	/**
	 * Registers a module.
	 *
	 * @since 1.13.0
	 *
	 * @param {string}    slug                         Module slug.
	 * @param {Object}    [settings]                   Optional. Module settings.
	 * @param {string}    [settings.name]              Optional. Module name. Default is the slug.
	 * @param {string}    [settings.description]       Optional. Module description. Default empty string.
	 * @param {string}    [settings.icon]              Optional. Module icon. Default empty string.
	 * @param {number}    [settings.order]             Optional. Numeric indicator for module order. Default 10.
	 * @param {string}    [settings.homepage]          Optional. Module homepage URL. Default empty string.
	 * @param {WPElement} [settings.settingsComponent] React component to render the settings panel. Default is the DefaultModuleSettings component.
	 * @return {Object} Redux-style action.
	 */
	registerModule( slug, {
		name,
		description,
		icon,
		order,
		homepage,
		settingsComponent = DefaultModuleSettings,
	} = {} ) {
		invariant( slug, 'module slug is required' );

		const settings = {
			name,
			description,
			icon,
			order,
			homepage,
			settingsComponent,
		};

		return {
			payload: {
				settings,
				slug,
			},
			type: REGISTER_MODULE,
		};
	},
};

export const baseControls = {
	[ REFETCH_AUTHENTICATION ]: createRegistryControl( ( { dispatch } ) => () => {
		return dispatch( CORE_USER ).fetchGetAuthentication();
	} ),
};

const baseReducer = ( state, { type, payload } ) => {
	switch ( type ) {
		case REGISTER_MODULE: {
			const { slug, settings } = payload;

			return {
				...state,
				clientDefinitions: {
					...state.clientDefinitions,
					[ slug ]: {
						...( state.clientDefinitions[ slug ] || {} ),
						...settings,
					},
				},
			};
		}

		default: {
			return { ...state };
		}
	}
};

const baseResolvers = {
	*getModules() {
		const registry = yield Data.commonActions.getRegistry();

		const existingModules = registry.select( STORE_NAME ).getModules();

		if ( ! existingModules ) {
			yield fetchGetModulesStore.actions.fetchGetModules();
		}
	},
};

const baseSelectors = {
	/**
	 * Gets the list of modules registered for use with Site Kit.
	 *
	 * A module is a section of Site Kit that relates to a particular service,
	 * like Google Analytics or Google PageSpeed modules. They can provide
	 * admin-only features (like PageSpeed Insights), frontend-only features,
	 * or both (eg. Analytics, which can install Analytics <script> tags in the
	 * frontend, and show dashboards in the WordPress Admin).
	 *
	 * Returns an Object/map of objects, keyed by slug, with the following shape when successful:
	 * ```
	 * slug: {
	 *   "slug": "tagmanager",
	 *   "name": "Tag Manager",
	 *   "description": "Tag Manager creates an easy to manage way to create tags on your site without updating code.",
	 *   "homepage": "https://tagmanager.google.com/",
	 *   "internal": false,
	 *   "active": false,
	 *   "connected": false,
	 *   "dependencies": [
	 *     "analytics"
	 *   ],
	 *   "dependents": []
	 * }
	 * ```
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @return {(Object|undefined)} Modules available on the site.
	 */
	getModules( state ) {
		const { clientDefinitions, serverDefinitions } = state;

		// Return `undefined` if modules haven't been loaded yet.
		if ( serverDefinitions === undefined ) {
			return undefined;
		}

		// Module properties in `clientDefinitions` will overwrite `serverDefinitions`
		// but only for keys whose values are not `undefined`.
		const modules = merge( {}, serverDefinitions, clientDefinitions );

		return Object.keys( modules )
			.map( ( slug ) => {
				return {
					...moduleDefaults,
					name: slug, // Ensure `name` is not empty.
					...modules[ slug ],
					slug,
				};
			} )
			.sort( ( a, b ) => a.order - b.order )
			.reduce( ( acc, module ) => {
				return { ...acc, [ module.slug ]: module };
			}, {} )
		;
	},

	/**
	 * Gets a specific module by slug.
	 *
	 * Returns a specific module by its slug.
	 * Returns `undefined` if state is still loading or if said module doesn't exist.
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(Object|undefined)} A specific module object; `undefined` if state is still loading or if said module doesn't exist.
	 */
	getModule: createRegistrySelector( ( select ) => ( state, slug ) => {
		const modules = select( STORE_NAME ).getModules();

		// Return `undefined` if modules haven't been loaded yet.
		if ( modules === undefined ) {
			return undefined;
		}

		// A module with this slug couldn't be found; return `null` to signify the
		// "not found" state.
		if ( modules[ slug ] === undefined ) {
			return null;
		}

		// This module exists, so let's return it.
		return modules[ slug ];
	} ),

	/**
	 * Checks a module's activation status.
	 *
	 * Returns `true` if the module exists and is active.
	 * Returns `false` if the module exists but is not active.
	 * Returns `undefined` if state is still loading or if no module with that slug exists.
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(boolean|null|undefined)} TRUE when the module exists and is active; `undefined` if state is still loading or `null` if said module doesn't exist.
	 */
	isModuleActive: createRegistrySelector( ( select ) => ( state, slug ) => {
		const module = select( STORE_NAME ).getModule( slug );

		// Return `undefined` if modules haven't been loaded yet.
		if ( module === undefined ) {
			return undefined;
		}

		// A module with this slug couldn't be found; return `null` to signify the
		// "not found" state.
		if ( module === null ) {
			return null;
		}

		return module.active;
	} ),

	/**
	 * Checks whether a module is connected or not.
	 *
	 * Returns `true` if the module exists, is active and connected.
	 * Returns `false` if the module exists but is either not active or not connected.
	 * Returns `undefined` if state is still loading or if no module with that slug exists.
	 *
	 * @since 1.16.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(boolean|null|undefined)} TRUE when the module exists, is active and connected, otherwise FALSE; `undefined` if state is still loading or `null` if said module doesn't exist.
	 */
	isModuleConnected: createRegistrySelector( ( select ) => ( state, slug ) => {
		const module = select( STORE_NAME ).getModule( slug );

		// Return `undefined` if modules haven't been loaded yet.
		if ( module === undefined ) {
			return undefined;
		}

		// A module with this slug couldn't be found; return `null` to signify the
		// "not found" state.
		if ( module === null ) {
			return null;
		}

		return module.active && module.connected;
	} ),

	/**
	 * Checks if a module's status is changing.
	 *
	 * Returns `true` if the module exists and is changing its `active` flag.
	 * Returns `false` if the module exists but is not changing its `active` flag.
	 * Returns `undefined` if state is still loading or if no module with that slug exists.
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(boolean|undefined)} Activation change status; `undefined` if state is still loading or if no module with that slug exists.
	 */
	isDoingSetModuleActivation: createRegistrySelector( ( select ) => ( state, slug ) => {
		// Return undefined if modules not loaded or invalid slug.
		if ( ! select( STORE_NAME ).getModule( slug ) ) {
			return undefined;
		}

		// Check if the module is being activated.
		if ( select( STORE_NAME ).isFetchingSetModuleActivation( slug, true ) ) {
			return true;
		}

		// Check if the module is being deactivated.
		if ( select( STORE_NAME ).isFetchingSetModuleActivation( slug, false ) ) {
			return true;
		}

		// Check if modules data still needs to be refreshed after activation
		// update.
		return state.isAwaitingModulesRefresh;
	} ),
};

const store = Data.combineStores(
	fetchGetModulesStore,
	fetchSetModuleActivationStore,
	{
		INITIAL_STATE: BASE_INITIAL_STATE,
		actions: baseActions,
		controls: baseControls,
		reducer: baseReducer,
		resolvers: baseResolvers,
		selectors: baseSelectors,
	}
);

export const INITIAL_STATE = store.INITIAL_STATE;
export const actions = store.actions;
export const controls = store.controls;
export const reducer = store.reducer;
export const resolvers = store.resolvers;
export const selectors = store.selectors;

export default store;
<commit_msg>Extract modules normalization to memoized helper.<commit_after>/**
 * core/modules data store: module info.
 *
 * Site Kit by Google, Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import memize from 'memize';
import merge from 'lodash/merge';
import invariant from 'invariant';

/**
 * WordPress dependencies
 */
import { WPElement } from '@wordpress/element';

/**
 * Internal dependencies
 */
import API from 'googlesitekit-api';
import Data from 'googlesitekit-data';
import { STORE_NAME } from './constants';
import { STORE_NAME as CORE_USER } from '../../datastore/user/constants';
import { createFetchStore } from '../../data/create-fetch-store';
import DefaultModuleSettings from '../components/DefaultModuleSettings';

const { createRegistrySelector, createRegistryControl } = Data;

// Actions.
const REFETCH_AUTHENTICATION = 'REFETCH_AUTHENTICATION';
const REGISTER_MODULE = 'REGISTER_MODULE';

const moduleDefaults = {
	name: '',
	description: '',
	icon: null,
	order: 10,
	homepage: null,
	active: false,
	connected: false,
	settingsComponent: DefaultModuleSettings,
};

const normalizeModules = memize(
	( modules ) => Object.keys( modules )
		.map( ( slug ) => {
			return {
				...moduleDefaults,
				name: slug, // Ensure `name` is not empty.
				...modules[ slug ],
				slug,
			};
		} )
		.sort( ( a, b ) => a.order - b.order )
		.reduce( ( acc, module ) => {
			return { ...acc, [ module.slug ]: module };
		}, {} )
);

const fetchGetModulesStore = createFetchStore( {
	baseName: 'getModules',
	controlCallback: () => {
		return API.get( 'core', 'modules', 'list', null, {
			useCache: false,
		} );
	},
	reducerCallback: ( state, modules ) => {
		return {
			...state,
			isAwaitingModulesRefresh: false,
			serverDefinitions: modules.reduce( ( acc, module ) => {
				return { ...acc, [ module.slug ]: module };
			}, {} ),
		};
	},
} );

const fetchSetModuleActivationStore = createFetchStore( {
	baseName: 'setModuleActivation',
	controlCallback: ( { slug, active } ) => {
		return API.set( 'core', 'modules', 'activation', {
			slug,
			active,
		} );
	},
	reducerCallback: ( state ) => {
		// Updated module activation state is handled by re-fetching module
		// data instead, so this reducer just sets the below flag.
		return {
			...state,
			isAwaitingModulesRefresh: true,
		};
	},
	argsToParams: ( slug, active ) => {
		return {
			slug,
			active,
		};
	},
	validateParams: ( { slug, active } = {} ) => {
		invariant( slug, 'slug is required.' );
		invariant( active !== undefined, 'active is required.' );
	},
} );

const BASE_INITIAL_STATE = {
	clientDefinitions: {},
	serverDefinitions: undefined,
	// This value is to indicate that modules data needs to be refreshed after
	// a module activation update, since the activation is technically complete
	// before this data has been refreshed.
	isAwaitingModulesRefresh: false,
};

const baseActions = {
	/**
	 * Activates a module on the server.
	 *
	 * Activate a module (based on the slug provided).
	 *
	 * @since 1.8.0
	 *
	 * @param {string} slug Slug of the module to activate.
	 * @return {Object}      Object with {response, error}
	 */
	*activateModule( slug ) {
		const { response, error } = yield baseActions.setModuleActivation( slug, true );

		return { response, error };
	},

	/**
	 * Deactivates a module on the server.
	 *
	 * Deactivate a module (based on the slug provided).
	 *
	 * @since 1.8.0
	 *
	 * @param {string} slug Slug of the module to activate.
	 * @return {Object}      Object with {response, error}
	 */
	*deactivateModule( slug ) {
		const { response, error } = yield baseActions.setModuleActivation( slug, false );

		return { response, error };
	},

	/**
	 * (De)activates a module on the server.
	 *
	 * POSTs to the `core/modules/activation` endpoint to set the `active` status
	 * supplied for the give `slug`.
	 *
	 * @since 1.8.0
	 * @private
	 *
	 * @param {string}  slug   Slug of the module to activate/deactivate.
	 * @param {boolean} active `true` to activate; `false` to deactivate.
	 * @return {Object}         Object with {response, error}
	 */
	*setModuleActivation( slug, active ) {
		invariant( slug, 'slug is required.' );
		invariant( active !== undefined, 'active is required.' );

		const { response, error } = yield fetchSetModuleActivationStore.actions.fetchSetModuleActivation( slug, active );
		if ( response?.success === true ) {
			// Fetch (or re-fetch) all modules, with their updated status.
			yield fetchGetModulesStore.actions.fetchGetModules();
			yield {
				payload: {},
				type: REFETCH_AUTHENTICATION,
			};
		}

		return { response, error };
	},

	/**
	 * Registers a module.
	 *
	 * @since 1.13.0
	 *
	 * @param {string}    slug                         Module slug.
	 * @param {Object}    [settings]                   Optional. Module settings.
	 * @param {string}    [settings.name]              Optional. Module name. Default is the slug.
	 * @param {string}    [settings.description]       Optional. Module description. Default empty string.
	 * @param {string}    [settings.icon]              Optional. Module icon. Default empty string.
	 * @param {number}    [settings.order]             Optional. Numeric indicator for module order. Default 10.
	 * @param {string}    [settings.homepage]          Optional. Module homepage URL. Default empty string.
	 * @param {WPElement} [settings.settingsComponent] React component to render the settings panel. Default is the DefaultModuleSettings component.
	 * @return {Object} Redux-style action.
	 */
	registerModule( slug, {
		name,
		description,
		icon,
		order,
		homepage,
		settingsComponent = DefaultModuleSettings,
	} = {} ) {
		invariant( slug, 'module slug is required' );

		const settings = {
			name,
			description,
			icon,
			order,
			homepage,
			settingsComponent,
		};

		return {
			payload: {
				settings,
				slug,
			},
			type: REGISTER_MODULE,
		};
	},
};

export const baseControls = {
	[ REFETCH_AUTHENTICATION ]: createRegistryControl( ( { dispatch } ) => () => {
		return dispatch( CORE_USER ).fetchGetAuthentication();
	} ),
};

const baseReducer = ( state, { type, payload } ) => {
	switch ( type ) {
		case REGISTER_MODULE: {
			const { slug, settings } = payload;

			return {
				...state,
				clientDefinitions: {
					...state.clientDefinitions,
					[ slug ]: {
						...( state.clientDefinitions[ slug ] || {} ),
						...settings,
					},
				},
			};
		}

		default: {
			return { ...state };
		}
	}
};

const baseResolvers = {
	*getModules() {
		const registry = yield Data.commonActions.getRegistry();

		const existingModules = registry.select( STORE_NAME ).getModules();

		if ( ! existingModules ) {
			yield fetchGetModulesStore.actions.fetchGetModules();
		}
	},
};

const baseSelectors = {
	/**
	 * Gets the list of modules registered for use with Site Kit.
	 *
	 * A module is a section of Site Kit that relates to a particular service,
	 * like Google Analytics or Google PageSpeed modules. They can provide
	 * admin-only features (like PageSpeed Insights), frontend-only features,
	 * or both (eg. Analytics, which can install Analytics <script> tags in the
	 * frontend, and show dashboards in the WordPress Admin).
	 *
	 * Returns an Object/map of objects, keyed by slug, with the following shape when successful:
	 * ```
	 * slug: {
	 *   "slug": "tagmanager",
	 *   "name": "Tag Manager",
	 *   "description": "Tag Manager creates an easy to manage way to create tags on your site without updating code.",
	 *   "homepage": "https://tagmanager.google.com/",
	 *   "internal": false,
	 *   "active": false,
	 *   "connected": false,
	 *   "dependencies": [
	 *     "analytics"
	 *   ],
	 *   "dependents": []
	 * }
	 * ```
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @return {(Object|undefined)} Modules available on the site.
	 */
	getModules( state ) {
		const { clientDefinitions, serverDefinitions } = state;

		// Return `undefined` if modules haven't been loaded yet.
		if ( serverDefinitions === undefined ) {
			return undefined;
		}

		// Module properties in `clientDefinitions` will overwrite `serverDefinitions`
		// but only for keys whose values are not `undefined`.
		const modules = merge( {}, serverDefinitions, clientDefinitions );

		return normalizeModules( modules );
	},

	/**
	 * Gets a specific module by slug.
	 *
	 * Returns a specific module by its slug.
	 * Returns `undefined` if state is still loading or if said module doesn't exist.
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(Object|undefined)} A specific module object; `undefined` if state is still loading or if said module doesn't exist.
	 */
	getModule: createRegistrySelector( ( select ) => ( state, slug ) => {
		const modules = select( STORE_NAME ).getModules();

		// Return `undefined` if modules haven't been loaded yet.
		if ( modules === undefined ) {
			return undefined;
		}

		// A module with this slug couldn't be found; return `null` to signify the
		// "not found" state.
		if ( modules[ slug ] === undefined ) {
			return null;
		}

		// This module exists, so let's return it.
		return modules[ slug ];
	} ),

	/**
	 * Checks a module's activation status.
	 *
	 * Returns `true` if the module exists and is active.
	 * Returns `false` if the module exists but is not active.
	 * Returns `undefined` if state is still loading or if no module with that slug exists.
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(boolean|null|undefined)} TRUE when the module exists and is active; `undefined` if state is still loading or `null` if said module doesn't exist.
	 */
	isModuleActive: createRegistrySelector( ( select ) => ( state, slug ) => {
		const module = select( STORE_NAME ).getModule( slug );

		// Return `undefined` if modules haven't been loaded yet.
		if ( module === undefined ) {
			return undefined;
		}

		// A module with this slug couldn't be found; return `null` to signify the
		// "not found" state.
		if ( module === null ) {
			return null;
		}

		return module.active;
	} ),

	/**
	 * Checks whether a module is connected or not.
	 *
	 * Returns `true` if the module exists, is active and connected.
	 * Returns `false` if the module exists but is either not active or not connected.
	 * Returns `undefined` if state is still loading or if no module with that slug exists.
	 *
	 * @since 1.16.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(boolean|null|undefined)} TRUE when the module exists, is active and connected, otherwise FALSE; `undefined` if state is still loading or `null` if said module doesn't exist.
	 */
	isModuleConnected: createRegistrySelector( ( select ) => ( state, slug ) => {
		const module = select( STORE_NAME ).getModule( slug );

		// Return `undefined` if modules haven't been loaded yet.
		if ( module === undefined ) {
			return undefined;
		}

		// A module with this slug couldn't be found; return `null` to signify the
		// "not found" state.
		if ( module === null ) {
			return null;
		}

		return module.active && module.connected;
	} ),

	/**
	 * Checks if a module's status is changing.
	 *
	 * Returns `true` if the module exists and is changing its `active` flag.
	 * Returns `false` if the module exists but is not changing its `active` flag.
	 * Returns `undefined` if state is still loading or if no module with that slug exists.
	 *
	 * @since 1.8.0
	 *
	 * @param {Object} state Data store's state.
	 * @param {string} slug  Module slug.
	 * @return {(boolean|undefined)} Activation change status; `undefined` if state is still loading or if no module with that slug exists.
	 */
	isDoingSetModuleActivation: createRegistrySelector( ( select ) => ( state, slug ) => {
		// Return undefined if modules not loaded or invalid slug.
		if ( ! select( STORE_NAME ).getModule( slug ) ) {
			return undefined;
		}

		// Check if the module is being activated.
		if ( select( STORE_NAME ).isFetchingSetModuleActivation( slug, true ) ) {
			return true;
		}

		// Check if the module is being deactivated.
		if ( select( STORE_NAME ).isFetchingSetModuleActivation( slug, false ) ) {
			return true;
		}

		// Check if modules data still needs to be refreshed after activation
		// update.
		return state.isAwaitingModulesRefresh;
	} ),
};

const store = Data.combineStores(
	fetchGetModulesStore,
	fetchSetModuleActivationStore,
	{
		INITIAL_STATE: BASE_INITIAL_STATE,
		actions: baseActions,
		controls: baseControls,
		reducer: baseReducer,
		resolvers: baseResolvers,
		selectors: baseSelectors,
	}
);

export const INITIAL_STATE = store.INITIAL_STATE;
export const actions = store.actions;
export const controls = store.controls;
export const reducer = store.reducer;
export const resolvers = store.resolvers;
export const selectors = store.selectors;

export default store;
<|endoftext|>


<commit_before>// settings.js
// Settings for Toyz
// Copyright 2015 by Fred Moolekamp
// License: LGPLv3

Toyz.namespace('Toyz.Console.Settings');

Toyz.Console.Settings.getModuleSettings = function(params){
    var modules = {
        type: 'div',
        legend: params.legend,
        css: {
            'width': 600
        },
        params:{}
    };
    modules.params[params.param_name] = {
        type: 'list',
        format: 'list',
        newItem: {}
    };
    return modules;
}

Toyz.Console.Settings.getToyzSettings = function(params){
    var toyz = {
        type: 'div',
        legend: params.legend,
        css: {
            'width': 900
        },
        params: {}
    };
    toyz.params[params.param_name] = {
        type: 'list',
        format: 'dict',
        newItem: {
            type:'div',
            params:{
                key: {
                    lbl:'toy name'
                },
                value:{
                    lbl:'path',
                    file_dialog: true
                }
            }
        }
    };
    return toyz;
};

Toyz.Console.Settings.getThirdParty = function(params){
    var third_party = {
        type: 'div',
        legend: 'Third Party Libraries',
        params: {
            third_party: {
                type: 'list',
                format: 'dict',
                newItem: {
                    type:'div',
                    params:{
                        key: {
                            lbl:'Library name'
                        },
                        value:{
                            type: 'div',
                            params: {
                                version: {lbl: 'version'},
                                path: {
                                    lbl: 'path',
                                    file_dialog: true
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    return third_party;
};
Toyz.Console.Settings.UserSettings = function(params){
    this.type = 'div';
    this.legend = 'Users';
    this.params = {
        user_id: {
            type: 'select',
            options: params.users,
            func: {
                change: function(websocket){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'load_user_info',
                            parameters: {
                                user_id: this.params.user_id.$input.val(),
                                user_attr: ['groups', 'modules', 'toyz', 'paths'],
                            }
                        },
                        callback: function(result){
                            this.gui.set_params({
                                values: result,
                                change: true,
                                set_all: true
                            });
                        }.bind(this)
                    })
                }.bind(this, params.websocket)
            }
        },
        groups_div: {
            type: 'div',
            legend: 'Groups',
            css: {
                'width': 300
            },
            params: {
                groups: {
                    type: 'list',
                    format: 'list',
                    newItem: {
                        type: 'select',
                        options: params.groups
                    }
                }
            }
        },
        paths_div: {
            type: 'div',
            legend: 'Paths',
            css: {
                'width': 900
            },
            params: {
                paths: {
                    type: 'list',
                    format: 'dict',
                    newItem: {
                        type:'div',
                        params: {
                            value: {
                                lbl: 'path permissions'
                            },
                            key: {
                                lbl: 'path',
                                file_dialog: true
                            }
                        }
                    }
                }
            }
        },
        modules: new Toyz.Console.Settings.getModuleSettings({
            legend:'Toyz Modules',
            param_name: 'modules'
        }),
        toyz: new Toyz.Console.Settings.getToyzSettings({
            legend: 'Toyz Paths',
            param_name: 'toyz',
            file_dialog: true
        }),
        reset_pwd: {
            type: 'button',
            prop: {
                innerHTML: 'reset password'
            },
            func: {
                click: function(websocket){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'reset_pwd',
                            parameters: {
                                user_id: this.gui.get().user_id
                            }
                        }
                    })
                }.bind(this, params.websocket)
            }
        },
        delete_user: {
            type: 'button',
            prop: {
                innerHTML: 'delete user'
            },
            func: {
                click: function(){
                    // TODO: Implement delete user
                }
            }
        },
        new_user: {
            type: 'button',
            prop: {
                innerHTML: 'new user'
            },
            func: {
                click: function(new_user_gui){
                    new_user_gui.root.$div.dialog('open');
                }.bind(this, params.new_user_gui)
            }
        },
        save_user: {
            type: 'button',
            prop: {
                innerHTML: 'save user'
            },
            func: {
                click: function(websocket){
                    var params = this.gui.get();
                    delete params.conditions;
                    console.log('params before save', params);
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'save_user_info',
                            parameters: params
                        }
                    });
                }.bind(this, params.websocket)
            }
        }
    };
}
Toyz.Console.Settings.getUserSettings = function(params, $user_div){
    var user_settings = new Toyz.Console.Settings.UserSettings(params);
    var gui = new Toyz.Gui.Gui({
        params: user_settings,
        $parent: $user_div,
        default: {
            values:{
                user_id: params.user_settings['user_id']
            }
        }
    });
    return gui;
};

Toyz.Console.Settings.GroupSettings = function(params){
    this.type = 'div',
    this.legend = 'Groups',
    this.params = {
        group_id: {
            type: 'select',
            options: params.groups,
            func: {
                change: function(websocket){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'load_user_info',
                            parameters: {
                                group_id: this.params.group_id.$input.val(),
                                user_attr: ['users', 'modules', 'toyz', 'paths'],
                            }
                        },
                        callback: function(result){
                            this.gui.set_params({
                                values: result,
                                change: true,
                                set_all: true
                            });
                        }.bind(this)
                    });
                }.bind(this, params.websocket)
            }
        },
        users_div: {
            type: 'div',
            legend: 'Users',
            css: {
                'width': 300
            },
            params: {
                users: {
                    type: 'list',
                    format: 'list',
                    newItem: {
                        type: 'select',
                        options: params.users
                    }
                }
            }
        },
        paths_div: {
            type: 'div',
            legend: 'Paths',
            css: {
                'width': 900
            },
            params: {
                paths: {
                    type: 'list',
                    format: 'dict',
                    newItem: {
                        type:'div',
                        params: {
                            value: {
                                lbl: 'path permissions'
                            },
                            key: {
                                lbl: 'path',
                                file_dialog: true
                            }
                        }
                    }
                }
            }
        },
        modules: new Toyz.Console.Settings.getModuleSettings({
            legend:'Toyz Modules',
            param_name: 'modules'
        }),
        toyz: new Toyz.Console.Settings.getToyzSettings({
            legend: 'Toyz Paths',
            param_name: 'toyz',
            file_dialog: true
        }),
        delete_group: {
            type: 'button',
            prop: {
                innerHTML: 'delete group'
            },
            func: {
                click: function(){
                    // TODO: add delete group functionality
                }
            }
        },
        new_group: {
            type: 'button',
            prop: {
                innerHTML: 'new group'
            },
            func: {
                click: function(new_group){
                    new_group.root.$div.dialog('open');
                }.bind(this, params.new_group)
            }
        },
        save_group: {
            type: 'button',
            prop: {
                innerHTML: 'save'
            },
            func: {
                click: function(){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'save_user_info',
                            parameters: this.gui.get()
                        }
                    })
                }.bind(this, params.websocket)
            }
        }
    };
};

Toyz.Console.Settings.getGroupSettings = function(params, $group_div){
    var group_settings = new Toyz.Console.Settings.GroupSettings(params);
    var gui = new Toyz.Gui.Gui({
        params: group_settings,
        $parent: $group_div,
        default: {
            values:{
                group_id: params.group_settings['group_id']
            }
        }
    });
    return gui;
};

Toyz.Console.Settings.getAdminSettings = function(params, $admin_div){
    // unpack the congfiguration settings
    var admin_default = {};
    /*var settings = ['config', 'db', 'web', 'security'];//
    for(var i=0; i<settings.length; i++){
        for(var key in params[settings[i]]){
            if(params[settings[i]].hasOwnProperty(key)){
                admin_default[key] = params[settings[i]][key];
            }
        }
    };*/

    var config_params = {
        type: 'div',
        legend: 'Toyz Configuration',
        params: {
            root_path: {
                lbl: 'toyz root path',
                prop: {
                    disabled: true
                }
            },
            config_path: {
                lbl: 'config file path',
                prop: {
                    disabled: true
                }
            }
        }
    };

    var db_params = {
        type: 'div',
        legend: 'Database',
        params: {
            db_type: {
                lbl:'database type',
                type:'select',
                options: {
                    sqlite: 'sqlite'
                }
            },
            db_path: {
                lbl:'db location (relative to root path)',
                file_dialog: true
            }
        }
    };

    var web_params = {
        type: 'div',
        legend: 'Web',
        params: {
            port: {
                lbl: 'default port',
                prop: {
                    type: 'Number'
                }
            },
            third_party: Toyz.Console.Settings.getThirdParty(params)
        }
    };

    var security_params = {
        type: 'div',
        legend: 'Security',
        params: {
            encrypt_db: {
                lbl: 'encrypt database (' +
                    'requires SQLCipher install on server,' +
                    ' not yet supported)',
                prop: {
                    type: 'checkbox',
                    checked: true,
                    disabled: true
                },
            },
            user_login: {
                lbl: 'enable multiple users',
                prop: {
                    type: 'checkbox',
                    checked: false,
                }
            }
        }
    };

    var admin_settings = {
        config: new Toyz.Gui.Gui({
            $parent:$admin_div,
            params:config_params,
            default: params.config
        }),
        db: new Toyz.Gui.Gui({
            $parent: $admin_div,
            params: db_params,
            default: params.db
        }),
        web: new Toyz.Gui.Gui({
            $parent: $admin_div,
            params: web_params,
            default: params.web
        }),
        security: new Toyz.Gui.Gui({
            $parent: $admin_div,
            params: security_params,
            default: params.security
        })
    };

    // submit button for admin div
    var $submit = $('<button/>')
        .html("Submit")
        .click(function(websocket){
            var settings = {
                config: this.config.get(),
                db: this.db.get(),
                web: this.web.get(),
                security: this.security.get()
            };
            for(var setting in settings){
                delete settings[setting].conditions
            };
            websocket.send_task({
                task: {
                    module: 'toyz.web.tasks',
                    task: 'update_toyz_settings',
                    parameters: settings
                }
            });
        }.bind(admin_settings, params.websocket));
    $admin_div.append($submit);

    return admin_settings;
};

Toyz.Console.Settings.getAccountSettings = function(params){
    var account_settings = {
        type: 'div',
        params: {
            account: {
                type: 'label',
                prop: {
                    innerHTML: 'You are Logged in as '+params.user_id+''
                }
            },
            logout: {
                type: 'a',
                prop: {
                    href: '/auth/logout/',
                    innerHTML:'logout'
                },
            },
            change_pwd_btn: {
                type: 'button',
                prop: {
                    innerHTML:'change password'
                },
                func:{
                    click: function(){
                        this.root.$div.dialog('open');
                    }.bind(params.pwd_gui)
                }
            },
            shortcuts_div: {
                type: 'div',
                legend: 'Shortcuts',
                css: {
                    'width': 900
                },
                params: {
                    shortcuts: {
                        type: 'list',
                        format: 'dict',
                        newItem: {
                            type:'div',
                            params: {
                                key: {
                                    lbl: 'directory label'
                                },
                                value: {
                                    lbl: 'path',
                                    file_dialog: true
                                }
                            }
                        }
                    }
                }
            },
        }
    };
    return account_settings;
};

console.log('settings.js loaded');<commit_msg>bug fix<commit_after>// settings.js
// Settings for Toyz
// Copyright 2015 by Fred Moolekamp
// License: LGPLv3

Toyz.namespace('Toyz.Console.Settings');

Toyz.Console.Settings.getModuleSettings = function(params){
    var modules = {
        type: 'div',
        legend: params.legend,
        css: {
            'width': 600
        },
        params:{}
    };
    modules.params[params.param_name] = {
        type: 'list',
        format: 'list',
        new_item: {}
    };
    return modules;
}

Toyz.Console.Settings.getToyzSettings = function(params){
    var toyz = {
        type: 'div',
        legend: params.legend,
        css: {
            'width': 900
        },
        params: {}
    };
    toyz.params[params.param_name] = {
        type: 'list',
        format: 'dict',
        new_item: {
            type:'div',
            params:{
                key: {
                    lbl:'toy name'
                },
                value:{
                    lbl:'path',
                    file_dialog: true
                }
            }
        }
    };
    return toyz;
};

Toyz.Console.Settings.getThirdParty = function(params){
    var third_party = {
        type: 'div',
        legend: 'Third Party Libraries',
        params: {
            third_party: {
                type: 'list',
                format: 'dict',
                new_item: {
                    type:'div',
                    params:{
                        key: {
                            lbl:'Library name'
                        },
                        value:{
                            type: 'div',
                            params: {
                                version: {lbl: 'version'},
                                path: {
                                    lbl: 'path',
                                    file_dialog: true
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    return third_party;
};
Toyz.Console.Settings.UserSettings = function(params){
    this.type = 'div';
    this.legend = 'Users';
    this.params = {
        user_id: {
            type: 'select',
            options: params.users,
            func: {
                change: function(websocket){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'load_user_info',
                            parameters: {
                                user_id: this.params.user_id.$input.val(),
                                user_attr: ['groups', 'modules', 'toyz', 'paths'],
                            }
                        },
                        callback: function(result){
                            this.gui.set_params({
                                values: result,
                                change: true,
                                set_all: true
                            });
                        }.bind(this)
                    })
                }.bind(this, params.websocket)
            }
        },
        groups_div: {
            type: 'div',
            legend: 'Groups',
            css: {
                'width': 300
            },
            params: {
                groups: {
                    type: 'list',
                    format: 'list',
                    new_item: {
                        type: 'select',
                        options: params.groups
                    }
                }
            }
        },
        paths_div: {
            type: 'div',
            legend: 'Paths',
            css: {
                'width': 900
            },
            params: {
                paths: {
                    type: 'list',
                    format: 'dict',
                    new_item: {
                        type:'div',
                        params: {
                            value: {
                                lbl: 'path permissions'
                            },
                            key: {
                                lbl: 'path',
                                file_dialog: true
                            }
                        }
                    }
                }
            }
        },
        modules: new Toyz.Console.Settings.getModuleSettings({
            legend:'Toyz Modules',
            param_name: 'modules'
        }),
        toyz: new Toyz.Console.Settings.getToyzSettings({
            legend: 'Toyz Paths',
            param_name: 'toyz',
            file_dialog: true
        }),
        reset_pwd: {
            type: 'button',
            prop: {
                innerHTML: 'reset password'
            },
            func: {
                click: function(websocket){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'reset_pwd',
                            parameters: {
                                user_id: this.gui.get().user_id
                            }
                        }
                    })
                }.bind(this, params.websocket)
            }
        },
        delete_user: {
            type: 'button',
            prop: {
                innerHTML: 'delete user'
            },
            func: {
                click: function(){
                    // TODO: Implement delete user
                }
            }
        },
        new_user: {
            type: 'button',
            prop: {
                innerHTML: 'new user'
            },
            func: {
                click: function(new_user_gui){
                    new_user_gui.root.$div.dialog('open');
                }.bind(this, params.new_user_gui)
            }
        },
        save_user: {
            type: 'button',
            prop: {
                innerHTML: 'save user'
            },
            func: {
                click: function(websocket){
                    var params = this.gui.get();
                    delete params.conditions;
                    console.log('params before save', params);
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'save_user_info',
                            parameters: params
                        }
                    });
                }.bind(this, params.websocket)
            }
        }
    };
}
Toyz.Console.Settings.getUserSettings = function(params, $user_div){
    var user_settings = new Toyz.Console.Settings.UserSettings(params);
    var gui = new Toyz.Gui.Gui({
        params: user_settings,
        $parent: $user_div,
        default: {
            values:{
                user_id: params.user_settings['user_id']
            }
        }
    });
    return gui;
};

Toyz.Console.Settings.GroupSettings = function(params){
    this.type = 'div',
    this.legend = 'Groups',
    this.params = {
        group_id: {
            type: 'select',
            options: params.groups,
            func: {
                change: function(websocket){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'load_user_info',
                            parameters: {
                                group_id: this.params.group_id.$input.val(),
                                user_attr: ['users', 'modules', 'toyz', 'paths'],
                            }
                        },
                        callback: function(result){
                            this.gui.set_params({
                                values: result,
                                change: true,
                                set_all: true
                            });
                        }.bind(this)
                    });
                }.bind(this, params.websocket)
            }
        },
        users_div: {
            type: 'div',
            legend: 'Users',
            css: {
                'width': 300
            },
            params: {
                users: {
                    type: 'list',
                    format: 'list',
                    new_item: {
                        type: 'select',
                        options: params.users
                    }
                }
            }
        },
        paths_div: {
            type: 'div',
            legend: 'Paths',
            css: {
                'width': 900
            },
            params: {
                paths: {
                    type: 'list',
                    format: 'dict',
                    new_item: {
                        type:'div',
                        params: {
                            value: {
                                lbl: 'path permissions'
                            },
                            key: {
                                lbl: 'path',
                                file_dialog: true
                            }
                        }
                    }
                }
            }
        },
        modules: new Toyz.Console.Settings.getModuleSettings({
            legend:'Toyz Modules',
            param_name: 'modules'
        }),
        toyz: new Toyz.Console.Settings.getToyzSettings({
            legend: 'Toyz Paths',
            param_name: 'toyz',
            file_dialog: true
        }),
        delete_group: {
            type: 'button',
            prop: {
                innerHTML: 'delete group'
            },
            func: {
                click: function(){
                    // TODO: add delete group functionality
                }
            }
        },
        new_group: {
            type: 'button',
            prop: {
                innerHTML: 'new group'
            },
            func: {
                click: function(new_group){
                    new_group.root.$div.dialog('open');
                }.bind(this, params.new_group)
            }
        },
        save_group: {
            type: 'button',
            prop: {
                innerHTML: 'save'
            },
            func: {
                click: function(){
                    websocket.send_task({
                        task: {
                            module: 'toyz.web.tasks',
                            task: 'save_user_info',
                            parameters: this.gui.get()
                        }
                    })
                }.bind(this, params.websocket)
            }
        }
    };
};

Toyz.Console.Settings.getGroupSettings = function(params, $group_div){
    var group_settings = new Toyz.Console.Settings.GroupSettings(params);
    var gui = new Toyz.Gui.Gui({
        params: group_settings,
        $parent: $group_div,
        default: {
            values:{
                group_id: params.group_settings['group_id']
            }
        }
    });
    return gui;
};

Toyz.Console.Settings.getAdminSettings = function(params, $admin_div){
    // unpack the congfiguration settings
    var admin_default = {};
    /*var settings = ['config', 'db', 'web', 'security'];//
    for(var i=0; i<settings.length; i++){
        for(var key in params[settings[i]]){
            if(params[settings[i]].hasOwnProperty(key)){
                admin_default[key] = params[settings[i]][key];
            }
        }
    };*/

    var config_params = {
        type: 'div',
        legend: 'Toyz Configuration',
        params: {
            root_path: {
                lbl: 'toyz root path',
                prop: {
                    disabled: true
                }
            },
            config_path: {
                lbl: 'config file path',
                prop: {
                    disabled: true
                }
            }
        }
    };

    var db_params = {
        type: 'div',
        legend: 'Database',
        params: {
            db_type: {
                lbl:'database type',
                type:'select',
                options: {
                    sqlite: 'sqlite'
                }
            },
            db_path: {
                lbl:'db location (relative to root path)',
                file_dialog: true
            }
        }
    };

    var web_params = {
        type: 'div',
        legend: 'Web',
        params: {
            port: {
                lbl: 'default port',
                prop: {
                    type: 'Number'
                }
            },
            third_party: Toyz.Console.Settings.getThirdParty(params)
        }
    };

    var security_params = {
        type: 'div',
        legend: 'Security',
        params: {
            encrypt_db: {
                lbl: 'encrypt database (' +
                    'requires SQLCipher install on server,' +
                    ' not yet supported)',
                prop: {
                    type: 'checkbox',
                    checked: true,
                    disabled: true
                },
            },
            user_login: {
                lbl: 'enable multiple users',
                prop: {
                    type: 'checkbox',
                    checked: false,
                }
            }
        }
    };

    var admin_settings = {
        config: new Toyz.Gui.Gui({
            $parent:$admin_div,
            params:config_params,
            default: params.config
        }),
        db: new Toyz.Gui.Gui({
            $parent: $admin_div,
            params: db_params,
            default: params.db
        }),
        web: new Toyz.Gui.Gui({
            $parent: $admin_div,
            params: web_params,
            default: params.web
        }),
        security: new Toyz.Gui.Gui({
            $parent: $admin_div,
            params: security_params,
            default: params.security
        })
    };

    // submit button for admin div
    var $submit = $('<button/>')
        .html("Submit")
        .click(function(websocket){
            var settings = {
                config: this.config.get(),
                db: this.db.get(),
                web: this.web.get(),
                security: this.security.get()
            };
            for(var setting in settings){
                delete settings[setting].conditions
            };
            websocket.send_task({
                task: {
                    module: 'toyz.web.tasks',
                    task: 'update_toyz_settings',
                    parameters: settings
                }
            });
        }.bind(admin_settings, params.websocket));
    $admin_div.append($submit);

    return admin_settings;
};

Toyz.Console.Settings.getAccountSettings = function(params){
    var account_settings = {
        type: 'div',
        params: {
            account: {
                type: 'label',
                prop: {
                    innerHTML: 'You are Logged in as '+params.user_id+''
                }
            },
            logout: {
                type: 'a',
                prop: {
                    href: '/auth/logout/',
                    innerHTML:'logout'
                },
            },
            change_pwd_btn: {
                type: 'button',
                prop: {
                    innerHTML:'change password'
                },
                func:{
                    click: function(){
                        this.root.$div.dialog('open');
                    }.bind(params.pwd_gui)
                }
            },
            shortcuts_div: {
                type: 'div',
                legend: 'Shortcuts',
                css: {
                    'width': 900
                },
                params: {
                    shortcuts: {
                        type: 'list',
                        format: 'dict',
                        new_item: {
                            type:'div',
                            params: {
                                key: {
                                    lbl: 'directory label'
                                },
                                value: {
                                    lbl: 'path',
                                    file_dialog: true
                                }
                            }
                        }
                    }
                }
            },
        }
    };
    return account_settings;
};

console.log('settings.js loaded');<|endoftext|>


<commit_before>/**
 * Future.js - 2015
 * @author Bertrand Chevrier <chevrier.bertrand@gmail.com>
 * @license MIT
 */

/**
 * Future.js entry point.
 * @module future
 */

//load the ES6 polyfill
import 'babel/polyfill';

//re-export Future libraries
export { fwc as fwc } from './fwc.js';
export { router as router } from './router.js';

<commit_msg>fix way to export module<commit_after>/**
 * Future.js - 2015
 * @author Bertrand Chevrier <chevrier.bertrand@gmail.com>
 * @license MIT
 */

/**
 * Future.js entry point.
 * @module future
 */

//load the ES6 polyfill
import 'babel/polyfill';

//re-export Future libraries
import fwc from './fwc.js';
import router from './router.js';

export default {
    fwc,
    router
};

<|endoftext|>