<commit_before>/*jslint nomen: true, vars: true, white: true */
/*jshint scripturl: true */
/*global interstate,esprima,able,uid,console,window,jQuery,Raphael */

(function (ist, $) {
	"use strict";
	var cjs = ist.cjs,
		_ = ist._;

	var UNSET_RADIUS = 7;

	var on_cell_key_down = function(event) {
		var keyCode = event.keyCode;
		var prev, next, next_focusable, prev_focusable;
		if(this.element.is(event.target)) {
			if(keyCode === 79 || keyCode === 13) { // o or ENTER
				event.preventDefault();
				event.stopPropagation();
				if(this.element.hasClass("unset")) {
					this.element.trigger("click");
				} else {
					this.begin_editing();
				}
			} else if(keyCode === 39 || keyCode === 76) { // Right or o or k
				next_focusable = this.element.next(":focusable");
				if(next_focusable.length>0) {
					next_focusable.focus();
				} else {
					var prop = this.element.parents(":focusable").first();
					next = prop.next();
					if(next.length>0) {
						next.focus();
					} else {
						prop.focus();
					}
				}
			} else if(keyCode === 37 || keyCode === 72) { // Left
				prev_focusable = this.element.prev(":focusable");
				if(prev_focusable.length>0) {
					prev_focusable.focus();
				} else {
					this.element.parents(":focusable").first().focus();
				}
			} else if(keyCode === 40 || keyCode === 74) { //down or j
				var next_prop = this.element.parents(":focusable").first().next();
				next_focusable = $(":focusable", next_prop).eq(this.element.index());
				if(next_focusable.length>0) {
					next_focusable.focus();
				} else {
					next_prop.focus();
				}
			} else if(keyCode === 38 || keyCode === 75) { // up or k
				var prev_prop = this.element.parents(":focusable").first().prev();
				prev_focusable = $(":focusable", prev_prop).eq(this.element.index());
				if(prev_focusable.length>0) {
					prev_focusable.focus();
				} else {
					prev_prop.focus();
				}
			} else if(keyCode === 8) { //backspace
				if(this.element.hasClass("cell")) {
					this.unset();
				}
			}
		}
	};
	var func_regex = new RegExp("^\\s*function\\s*\\((\\s*[a-zA-Z$][\\w\\$]*\\s*,)*\\s*([a-zA-Z$][\\w\\$]*\\s*)?\\)\\s*{.*}\\s*$");

	$.widget("interstate.prop_cell", {
		options: {
			value: false,
			left: 0,
			width: 0,
			edit_width: 150,
			active: false,
			parent: false
		},
		_create: function() {
			var client = this.option("value");
			client.signal_interest();

			this.update_position();
			this.update_active();

			this.text = $("<span />")	.addClass("txt")
										.appendTo(this.element);
			this.element.on("keydown.prop_cell", _.bind(on_cell_key_down, this))
						.on("click.prop_cell", _.bind(this.on_click, this))
						.addClass("cell")
						.attr("tabindex", 1);
			this.element.tooltip({
				position: {
					my: "center bottom-1",
					at: "center top"
				},
				tooltipClass: "error",
				show: false,
				hide: false
			});
			this.create_live_text_fn();
		},
		_destroy: function() {
			this._super();

			this.element.off("keydown.prop_cell click.prop_cell")
						.removeClass("cell");

			if(this.textbox) {
				this.textbox.off("keydown.prop_cell blur.prop_cell")
							.remove();
			}

			this.text.remove();
			this.destroy_live_text_fn();
			this.element.tooltip("destroy");

			var client = this.option("value");

			client.signal_destroy();
			delete this.options;
		},
		on_click: function(event) {
			if(this.is_editing()) {
				event.stopPropagation();
			} else {
				this.begin_editing();
				event.stopPropagation();
			}
		},
		create_live_text_fn: function() {
			var value = this.option("value");
			var is_err = false;
			if(value.type() === "raw_cell") {
				var $str = value.get_$("get_str");
				var $syntax_errors = value.get_$("get_syntax_errors");
				this.live_text_fn = cjs.liven(function() {
					var str = $str.get();
					this.str = str;
					if(str === "") {
						this.text.html(" ");
					} else {
						this.text.text(this.str);
					}

					var syntax_errors = $syntax_errors.get();
					if(syntax_errors && syntax_errors.length > 0) {
						this.element.addClass("error");
						var syntax_error_text = syntax_errors[0];
						this.element.attr("title", syntax_error_text);
						this.element.tooltip("option", {
							tooltipClass: "error",
							content: syntax_error_text
						});
					} else {
						this.element.removeClass("error");
						this.element.attr("title", this.str);
						//this.element.attr("title", "");
						this.element.tooltip("option", {
							tooltipClass: "cell_text",
							content: this.str
						});
					}
				}, {
					context: this,
					on_destroy: function() {
						$str.signal_destroy();
						$syntax_errors.signal_destroy();
					}
				});
			}
		},
		destroy_live_text_fn: function() {
			if(this.live_text_fn) {
				this.live_text_fn.destroy();
				delete this.live_text_fn;
			}
		},
		update_position: function() {
			var left = this.option("left"),
				width = this.is_editing() ? this.option("edit_width") : this.option("width");
			this.element.css({
				left: (left - width/2) + "px",
				width: width + "px"
			});
		},
		update_active: function() {
			if(this.option("active")) {
				this.element.addClass("active");
			} else {
				this.element.removeClass("active");
			}
		},
		is_editing: function() {
			return this.element.hasClass("editing");
		},
		begin_editing: function() {
			this.element.addClass("editing");
			this.element.off("click.prop_cell");
			this.text.hide();

			if(this.textbox) {
				this.textbox.show();
			} else {
				this.textbox = $("<textarea />")	.attr("type", "text")
													.appendTo(this.element)
													.on("keydown.prop_cell", _.bind(function(event) {
														if(event.keyCode === 27) {
															event.preventDefault();
															event.stopPropagation();
															this.end_edit(true);
														} else if(event.keyCode === 13 && !event.shiftKey && !event.ctrlKey && !event.metaKey) {
															event.preventDefault();
															event.stopPropagation();
															this.end_edit();
														}
													}, this));
			}
			this.textbox.on("blur.prop_cell", _.bind(this.end_edit, this));

			var width = this.option("edit_width"),
				left = this.option("left");
			this.element.css({
				left: (left - width/2) + "px",
				width: width + "px"
			});

			if(this.str) {
				this.textbox.val(this.str);
			}
			this.focus();
			this.select();
			this.element.tooltip("disable");
		},
		unset: function() {
			var event = new $.Event("command");
			event.command_type = "unset_stateful_prop_for_state";
			event.prop = this.option("prop");
			event.state = this.option("state");

			this.element.trigger(event);
		},
		end_edit: function(cancel) {
			if(!this.is_editing()) {
				return;
			}
			this.element.on("click.prop_cell", _.bind(this.on_click, this));
			this.textbox.off("blur.prop_cell");
			if(cancel !== true) {
				var val = this.textbox.val();
				if(val.trim() === "" && this.option("prop") && this.option("state")) {
					this.unset();
				} else {
					var event = new $.Event("command");
					event.command_type = "set_str";
					event.str = val;
					event.client = this.option("value");

					this.element.trigger(event);
				}
			}
			this.text.show();
			this.textbox.hide();
			this.element.focus();
			this.element.removeClass("editing");

			var width = this.option("width"),
				left = this.option("left");
			this.element.css({
				left: (left - width/2) + "px",
				width: width + "px"
			});
			this.element.tooltip("enable");
		},
		focus: function() {
			if(this.textbox) {
				this.textbox.focus();
			}
		},
		select: function() {
			if(this.textbox) {
				this.textbox.select();
			}
		},
		_setOption: function(key, value) {
			this._super(key, value);
			if(key === "left" || key === "width") {
				this.update_position();
			} else if(key === "active") {
				this.update_active();
			}
		}
	});

	$.widget("interstate.unset_prop", {
		options: {
			left: 0,
			radius: 7,
			state: null
		},
		_create: function() {
			this.element.addClass("unset")
						.attr("tabindex", 1)
						.on("keydown.unset", _.bind(on_cell_key_down, this));
			this.update_left();
		},
		_destroy: function() {
			this.element.removeClass("unset")
						.off("keydown.unset");
			delete this.options.state;
		},
		update_left: function() {
			this.element.css("left", (this.option("left") - this.option("radius")) + "px");
		},
		_setOption: function(key, value) {
			this._super(key, value);
			if(key === "left" || key === "radius") {
				this.update_left();
			}
		}
	});
}(interstate, jQuery));
<commit_msg>Fixed bug where clicking in textbox would stop editing the cell<commit_after>/*jslint nomen: true, vars: true, white: true */
/*jshint scripturl: true */
/*global interstate,esprima,able,uid,console,window,jQuery,Raphael */

(function (ist, $) {
	"use strict";
	var cjs = ist.cjs,
		_ = ist._;

	var UNSET_RADIUS = 7;

	var on_cell_key_down = function(event) {
		var keyCode = event.keyCode;
		var prev, next, next_focusable, prev_focusable;
		if(this.element.is(event.target)) {
			if(keyCode === 79 || keyCode === 13) { // o or ENTER
				event.preventDefault();
				event.stopPropagation();
				if(this.element.hasClass("unset")) {
					this.element.trigger("click");
				} else {
					this.begin_editing();
				}
			} else if(keyCode === 39 || keyCode === 76) { // Right or o or k
				next_focusable = this.element.next(":focusable");
				if(next_focusable.length>0) {
					next_focusable.focus();
				} else {
					var prop = this.element.parents(":focusable").first();
					next = prop.next();
					if(next.length>0) {
						next.focus();
					} else {
						prop.focus();
					}
				}
			} else if(keyCode === 37 || keyCode === 72) { // Left
				prev_focusable = this.element.prev(":focusable");
				if(prev_focusable.length>0) {
					prev_focusable.focus();
				} else {
					this.element.parents(":focusable").first().focus();
				}
			} else if(keyCode === 40 || keyCode === 74) { //down or j
				var next_prop = this.element.parents(":focusable").first().next();
				next_focusable = $(":focusable", next_prop).eq(this.element.index());
				if(next_focusable.length>0) {
					next_focusable.focus();
				} else {
					next_prop.focus();
				}
			} else if(keyCode === 38 || keyCode === 75) { // up or k
				var prev_prop = this.element.parents(":focusable").first().prev();
				prev_focusable = $(":focusable", prev_prop).eq(this.element.index());
				if(prev_focusable.length>0) {
					prev_focusable.focus();
				} else {
					prev_prop.focus();
				}
			} else if(keyCode === 8) { //backspace
				if(this.element.hasClass("cell")) {
					this.unset();
				}
			}
		}
	};
	var func_regex = new RegExp("^\\s*function\\s*\\((\\s*[a-zA-Z$][\\w\\$]*\\s*,)*\\s*([a-zA-Z$][\\w\\$]*\\s*)?\\)\\s*{.*}\\s*$");

	$.widget("interstate.prop_cell", {
		options: {
			value: false,
			left: 0,
			width: 0,
			edit_width: 150,
			active: false,
			parent: false
		},
		_create: function() {
			var client = this.option("value");
			client.signal_interest();

			this.update_position();
			this.update_active();

			this.text = $("<span />")	.addClass("txt")
										.appendTo(this.element);
			this.element.on("keydown.prop_cell", _.bind(on_cell_key_down, this))
						.on("click.prop_cell", _.bind(this.on_click, this))
						.addClass("cell")
						.attr("tabindex", 1);
			this.element.tooltip({
				position: {
					my: "center bottom-1",
					at: "center top"
				},
				tooltipClass: "error",
				show: false,
				hide: false
			});
			this.create_live_text_fn();
		},
		_destroy: function() {
			this._super();

			this.element.off("keydown.prop_cell click.prop_cell")
						.removeClass("cell");

			if(this.textbox) {
				this.textbox.off("keydown.prop_cell blur.prop_cell")
							.remove();
			}

			this.text.remove();
			this.destroy_live_text_fn();
			this.element.tooltip("destroy");

			var client = this.option("value");

			client.signal_destroy();
			delete this.options;
		},
		on_click: function(event) {
			if(this.is_editing()) {
				event.stopPropagation();
			} else {
				this.begin_editing();
				event.stopPropagation();
			}
		},
		create_live_text_fn: function() {
			var value = this.option("value");
			var is_err = false;
			if(value.type() === "raw_cell") {
				var $str = value.get_$("get_str");
				var $syntax_errors = value.get_$("get_syntax_errors");
				this.live_text_fn = cjs.liven(function() {
					var str = $str.get();
					this.str = str;
					if(str === "") {
						this.text.html(" ");
					} else {
						this.text.text(this.str);
					}

					var syntax_errors = $syntax_errors.get();
					if(syntax_errors && syntax_errors.length > 0) {
						this.element.addClass("error");
						var syntax_error_text = syntax_errors[0];
						this.element.attr("title", syntax_error_text);
						this.element.tooltip("option", {
							tooltipClass: "error",
							content: syntax_error_text
						});
					} else {
						this.element.removeClass("error");
						this.element.attr("title", this.str);
						//this.element.attr("title", "");
						this.element.tooltip("option", {
							tooltipClass: "cell_text",
							content: this.str
						});
					}
				}, {
					context: this,
					on_destroy: function() {
						$str.signal_destroy();
						$syntax_errors.signal_destroy();
					}
				});
			}
		},
		destroy_live_text_fn: function() {
			if(this.live_text_fn) {
				this.live_text_fn.destroy();
				delete this.live_text_fn;
			}
		},
		update_position: function() {
			var left = this.option("left"),
				width = this.is_editing() ? this.option("edit_width") : this.option("width");
			this.element.css({
				left: (left - width/2) + "px",
				width: width + "px"
			});
		},
		update_active: function() {
			if(this.option("active")) {
				this.element.addClass("active");
			} else {
				this.element.removeClass("active");
			}
		},
		is_editing: function() {
			return this.element.hasClass("editing");
		},
		begin_editing: function() {
			this.element.addClass("editing");
			this.element.off("click.prop_cell");
			this.text.hide();

			if(this.textbox) {
				this.textbox.show();
			} else {
				this.textbox = $("<textarea />")	.attr("type", "text")
													.appendTo(this.element)
													.on("keydown.prop_cell", _.bind(function(event) {
														if(event.keyCode === 27) {
															event.preventDefault();
															event.stopPropagation();
															this.end_edit(true);
														} else if(event.keyCode === 13 && !event.shiftKey && !event.ctrlKey && !event.metaKey) {
															event.preventDefault();
															event.stopPropagation();
															this.end_edit();
														}
													}, this))
													.on("click", function(event) {
														event.stopPropagation();
													});
			}
			this.textbox.on("blur.prop_cell", _.bind(this.end_edit, this));

			var width = this.option("edit_width"),
				left = this.option("left");
			this.element.css({
				left: (left - width/2) + "px",
				width: width + "px"
			});

			if(this.str) {
				this.textbox.val(this.str);
			}
			this.focus();
			this.select();
			this.element.tooltip("disable");
		},
		unset: function() {
			var event = new $.Event("command");
			event.command_type = "unset_stateful_prop_for_state";
			event.prop = this.option("prop");
			event.state = this.option("state");

			this.element.trigger(event);
		},
		end_edit: function(cancel) {
			if(!this.is_editing()) {
				return;
			}
			this.element.on("click.prop_cell", _.bind(this.on_click, this));
			this.textbox.off("blur.prop_cell");
			if(cancel !== true) {
				var val = this.textbox.val();
				if(val.trim() === "" && this.option("prop") && this.option("state")) {
					this.unset();
				} else {
					var event = new $.Event("command");
					event.command_type = "set_str";
					event.str = val;
					event.client = this.option("value");

					this.element.trigger(event);
				}
			}
			this.text.show();
			this.textbox.hide();
			this.element.focus();
			this.element.removeClass("editing");

			var width = this.option("width"),
				left = this.option("left");
			this.element.css({
				left: (left - width/2) + "px",
				width: width + "px"
			});
			this.element.tooltip("enable");
		},
		focus: function() {
			if(this.textbox) {
				this.textbox.focus();
			}
		},
		select: function() {
			if(this.textbox) {
				this.textbox.select();
			}
		},
		_setOption: function(key, value) {
			this._super(key, value);
			if(key === "left" || key === "width") {
				this.update_position();
			} else if(key === "active") {
				this.update_active();
			}
		}
	});

	$.widget("interstate.unset_prop", {
		options: {
			left: 0,
			radius: 7,
			state: null
		},
		_create: function() {
			this.element.addClass("unset")
						.attr("tabindex", 1)
						.on("keydown.unset", _.bind(on_cell_key_down, this));
			this.update_left();
		},
		_destroy: function() {
			this.element.removeClass("unset")
						.off("keydown.unset");
			delete this.options.state;
		},
		update_left: function() {
			this.element.css("left", (this.option("left") - this.option("radius")) + "px");
		},
		_setOption: function(key, value) {
			this._super(key, value);
			if(key === "left" || key === "radius") {
				this.update_left();
			}
		}
	});
}(interstate, jQuery));
<|endoftext|>


<commit_before>import ui.View as View;
import ui.ImageView as ImageView;
import src.constants.gameConstants as gameConstants;
import ui.TextView as TextView;
import ui.widget.ButtonView as ButtonView;
import src.lib.parseUtil as ParseUtil;
import ui.TextEditView as TextEditView;
import src.models.Donor as Donor;
import src.models.Donation as Donation;

exports = Class(View, function (supr) {

	this.init = function(opts) {

		opts = merge(opts, {
			x: 0,
			y: 0,
			width: gameConstants.GAME_WIDTH,
			height: gameConstants.GAME_HEIGHT,
			backgroundColor: '#ef6e07'
		});

		supr(this, 'init', [opts]);

		this.buildView();
	};

	this.buildView = function() {

		this.background = new ImageView({
			parent: this,
			x: 0,
			y: 0,
			width: gameConstants.GAME_WIDTH,
			height: 960,
			image: "resources/images/backgrounds/donation_bg.png",
			opacity: 1
		});

		/*this.TitleText = new TextView({
			parent: this,
			x: gameConstants.GAME_WIDTH / 2 - 180,
			y: 100,
			width: 350,
			height: 150,
			text: "Donate",
			fontFamily: gameConstants.MAIN_FONT,
			color: 'white',
			size: 50,
			canHandleEvents: false
		});*/

    	this.BackButton = new ButtonView({
		    superview: this,
		    width: 80,
		    height: 80,
		    x: 480,
		    y: 10,
		    images: {
		      up: "resources/images/buttons/close_button.png"
		      //down: "resources/images/buttons/brown_button_down.png"
		    },
		    on: {
		      up: bind(this, function () {
		      		this.emit('Back');
				})
		    }
    	});

    	this.selectOneView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 35,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedTwoDollarView.hide();
		      		this.selectedFiveDollarView.hide();
		      		this.selectedTenDollarView.hide();
		      		this.selectedOneDollarView.show();
				})
		    }
    	});

    	this.selectTwoView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 159,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedOneDollarView.hide();
		      		this.selectedFiveDollarView.hide();
		      		this.selectedTenDollarView.hide();
		      		this.selectedTwoDollarView.show();
				})
		    }
    	});

    	this.selectFiveView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 293,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedOneDollarView.hide();
		      		this.selectedTwoDollarView.hide();
		      		this.selectedTenDollarView.hide();
		      		this.selectedFiveDollarView.show();
				})
		    }
    	});

    	this.selectTenView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 417,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedOneDollarView.hide();
		      		this.selectedTwoDollarView.hide();
		      		this.selectedFiveDollarView.hide();
		      		this.selectedTenDollarView.show();
				})
		    }
    	});

    	this.selectedOneDollarView = new ImageView({
    		parent: this,
			x: 35,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/one_selected.png",
			opacity: 1
    	});

    	this.selectedTwoDollarView = new ImageView({
    		parent: this,
			x: 159,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/two_selected.png",
			opacity: 1
    	});

    	this.selectedFiveDollarView = new ImageView({
    		parent: this,
			x: 293,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/five_selected.png",
			opacity: 1
    	});

		this.selectedTenDollarView = new ImageView({
    		parent: this,
			x: 417,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/ten_selected.png",
			opacity: 1
    	});

		this.customAmountEditView = new TextEditView({
			superview: this,
			x: 30,
			y: 425,
			//backgroundColor: "#ffffff",
			width: 456,
			height: 80,
			fontWeight: "bold",
			//horizontalAlign: "center",
			color: "#ffffff",
			hintColor: "#ffffff",
			hint: "Enter Custom Amount"
		});

		this.emailEditView = new TextEditView({
			superview: this,
			x: 30,
			y: 530,
			//backgroundColor: "#ffffff",
			width: 456,
			height: 80,
			fontWeight: "bold",
			//horizontalAlign: "center",
			color: "#ef7c21",
			hintColor: "#ef7c21",
			hint: "Enter Email"
		});

    	this.donateButton = new ButtonView({
			superview: this,
			width: 190,
			height: 125,
			x: gameConstants.GAME_WIDTH / 2 - 100,
			y: 670,
			images: {
				up: "resources/images/buttons/donate_button.png"
				//down: "resources/images/buttons/brown_button_down.png"
			},
			on: {
				up: bind(this, function () {
					var email = this.emailEditView.getText(),
						donor = GLOBAL.gameData.donorCollection.modelWithId(email);
					function saveDonation() {
						GLOBAL.gameData.donationCollection.add(new Donation({
							amount: 7,
							time: (new Date()).toString(),
							student: GLOBAL.gameData.student.get('id'),
							donor: email
						}));
						GLOBAL.gameData.donationCollection.save(function () {
							this.emit('Back');
						}.bind(this));
					}
					if (!donor) {
						GLOBAL.gameData.donorCollection.add(donor = new Donor({
							id: email,
							name: email.substring(0, email.indexOf('@'))
						}));
						GLOBAL.gameData.donorCollection.save(function () {
							saveDonation.call(this);
						}.bind(this));
					} else {
						saveDonation.call(this);
					}
				})
			}
		});
	};
});
<commit_msg>Changed the donation amount<commit_after>import ui.View as View;
import ui.ImageView as ImageView;
import src.constants.gameConstants as gameConstants;
import ui.TextView as TextView;
import ui.widget.ButtonView as ButtonView;
import src.lib.parseUtil as ParseUtil;
import ui.TextEditView as TextEditView;
import src.models.Donor as Donor;
import src.models.Donation as Donation;

exports = Class(View, function (supr) {

	this.init = function(opts) {

		opts = merge(opts, {
			x: 0,
			y: 0,
			width: gameConstants.GAME_WIDTH,
			height: gameConstants.GAME_HEIGHT,
			backgroundColor: '#ef6e07'
		});

		supr(this, 'init', [opts]);

		this.buildView();
	};

	this.buildView = function() {

		this.background = new ImageView({
			parent: this,
			x: 0,
			y: 0,
			width: gameConstants.GAME_WIDTH,
			height: 960,
			image: "resources/images/backgrounds/donation_bg.png",
			opacity: 1
		});

		/*this.TitleText = new TextView({
			parent: this,
			x: gameConstants.GAME_WIDTH / 2 - 180,
			y: 100,
			width: 350,
			height: 150,
			text: "Donate",
			fontFamily: gameConstants.MAIN_FONT,
			color: 'white',
			size: 50,
			canHandleEvents: false
		});*/

    	this.BackButton = new ButtonView({
		    superview: this,
		    width: 80,
		    height: 80,
		    x: 480,
		    y: 10,
		    images: {
		      up: "resources/images/buttons/close_button.png"
		      //down: "resources/images/buttons/brown_button_down.png"
		    },
		    on: {
		      up: bind(this, function () {
		      		this.emit('Back');
				})
		    }
    	});

    	this.selectOneView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 35,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedTwoDollarView.hide();
		      		this.selectedFiveDollarView.hide();
		      		this.selectedTenDollarView.hide();
		      		this.selectedOneDollarView.show();
				})
		    }
    	});

    	this.selectTwoView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 159,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedOneDollarView.hide();
		      		this.selectedFiveDollarView.hide();
		      		this.selectedTenDollarView.hide();
		      		this.selectedTwoDollarView.show();
				})
		    }
    	});

    	this.selectFiveView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 293,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedOneDollarView.hide();
		      		this.selectedTwoDollarView.hide();
		      		this.selectedTenDollarView.hide();
		      		this.selectedFiveDollarView.show();
				})
		    }
    	});

    	this.selectTenView = new ButtonView({
    		superview: this,
    		width: 124,
    		height: 139,
    		x: 417,
    		y: 240,
		    on: {
		      up: bind(this, function () {
		      		this.selectedOneDollarView.hide();
		      		this.selectedTwoDollarView.hide();
		      		this.selectedFiveDollarView.hide();
		      		this.selectedTenDollarView.show();
				})
		    }
    	});

    	this.selectedOneDollarView = new ImageView({
    		parent: this,
			x: 35,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/one_selected.png",
			opacity: 1
    	});

    	this.selectedTwoDollarView = new ImageView({
    		parent: this,
			x: 159,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/two_selected.png",
			opacity: 1
    	});

    	this.selectedFiveDollarView = new ImageView({
    		parent: this,
			x: 293,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/five_selected.png",
			opacity: 1
    	});

		this.selectedTenDollarView = new ImageView({
    		parent: this,
			x: 417,
			y: 240,
			width: 124,
			height: 139,
			visible: false,
			image: "resources/images/donation/ten_selected.png",
			opacity: 1
    	});

		this.customAmountEditView = new TextEditView({
			superview: this,
			x: 30,
			y: 425,
			//backgroundColor: "#ffffff",
			width: 456,
			height: 80,
			fontWeight: "bold",
			//horizontalAlign: "center",
			color: "#ffffff",
			hintColor: "#ffffff",
			hint: "Enter Custom Amount"
		});

		this.emailEditView = new TextEditView({
			superview: this,
			x: 30,
			y: 530,
			//backgroundColor: "#ffffff",
			width: 456,
			height: 80,
			fontWeight: "bold",
			//horizontalAlign: "center",
			color: "#ef7c21",
			hintColor: "#ef7c21",
			hint: "Enter Email"
		});

    	this.donateButton = new ButtonView({
			superview: this,
			width: 190,
			height: 125,
			x: gameConstants.GAME_WIDTH / 2 - 100,
			y: 670,
			images: {
				up: "resources/images/buttons/donate_button.png"
				//down: "resources/images/buttons/brown_button_down.png"
			},
			on: {
				up: bind(this, function () {
					var email = this.emailEditView.getText(),
						donor = GLOBAL.gameData.donorCollection.modelWithId(email);
					function saveDonation() {
						GLOBAL.gameData.donationCollection.add(new Donation({
							amount: 2,
							time: (new Date()).toString(),
							student: GLOBAL.gameData.student.get('id'),
							donor: email
						}));
						GLOBAL.gameData.donationCollection.save(function () {
							this.emit('Back');
						}.bind(this));
					}
					if (!donor) {
						GLOBAL.gameData.donorCollection.add(donor = new Donor({
							id: email,
							name: email.substring(0, email.indexOf('@'))
						}));
						GLOBAL.gameData.donorCollection.save(function () {
							saveDonation.call(this);
						}.bind(this));
					} else {
						saveDonation.call(this);
					}
				})
			}
		});
	};
});
<|endoftext|>


<commit_before>import _ from 'lodash';
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import customPropTypes from '../../utils/customPropTypes';
import META from 'src/utils/Meta';

export default class Item extends Component {
  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    contentClass: PropTypes.string,
    description: customPropTypes.mutuallyExclusive(['children']),
    extra: PropTypes.node,
    header: PropTypes.node,
    image: PropTypes.node,
    meta: PropTypes.node,
  };

  static defaultProps = {
    contentClass: 'middle aligned',
  };

  static _meta = {
    library: META.library.semanticUI,
    name: 'Item',
    type: META.type.view,
  };

  render() {
    const description =
{this.props.children || this.props.description}
;
    const extra =
{this.props.extra}
;
    const header =
{this.props.header}
;

    const imageClasses = classNames(
      'sd-item-image',
      'ui',
      this.props.image.props.className,
      'image',
    );
    const image = (

    );
    const meta =
{this.props.meta}
;

    const contentClass = classNames('sd-item-content', this.props.contentClass, 'content');
    const content = (

        {this.props.header && header}
        {this.props.meta && meta}
        {(this.props.children || this.props.description) && description}
        {this.props.extra && extra}

    );
    const hasContent = !!this.props.header || !!this.props.meta || !!this.props.extra || !!this.props.children
    || !!this.props.description;

    const classes = classNames(
      'sd-item',
      this.props.className,
      'item',
    );
    const props = _.clone(this.props);
    // Delete all static PropTypes props in cloned porps object before spreading of props onto rendered component
    delete props.children;
    delete props.className;
    delete props.description;
    delete props.extra;
    delete props.header;
    delete props.image;
    delete props.meta;

    return (

        {this.props.image && image}
        {hasContent && content}

    );
  }
}
<commit_msg>gracefully handle missing Item image prop<commit_after>import _ from 'lodash';
import React, {Component, PropTypes} from 'react';
import classNames from 'classnames';
import customPropTypes from '../../utils/customPropTypes';
import META from 'src/utils/Meta';

export default class Item extends Component {
  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    contentClass: PropTypes.string,
    description: customPropTypes.mutuallyExclusive(['children']),
    extra: PropTypes.node,
    header: PropTypes.node,
    image: PropTypes.node,
    meta: PropTypes.node,
  };

  static defaultProps = {
    contentClass: 'middle aligned',
  };

  static _meta = {
    library: META.library.semanticUI,
    name: 'Item',
    type: META.type.view,
  };

  render() {
    const description =
{this.props.children || this.props.description}
;
    const extra =
{this.props.extra}
;
    const header =
{this.props.header}
;

    const imageClasses = classNames(
      'sd-item-image',
      'ui',
      _.get(this.props, 'image.props.className'),
      'image',
    );
    const imageProps = _.omit(_.get(this.props, 'image.props', {}), 'className');
    const image = (

    );
    const meta =
{this.props.meta}
;

    const contentClass = classNames('sd-item-content', this.props.contentClass, 'content');
    const content = (

        {this.props.header && header}
        {this.props.meta && meta}
        {(this.props.children || this.props.description) && description}
        {this.props.extra && extra}

    );
    const hasContent = !!this.props.header || !!this.props.meta || !!this.props.extra || !!this.props.children
    || !!this.props.description;

    const classes = classNames(
      'sd-item',
      this.props.className,
      'item',
    );
    const props = _.clone(this.props);
    // Delete all static PropTypes props in cloned porps object before spreading of props onto rendered component
    delete props.children;
    delete props.className;
    delete props.description;
    delete props.extra;
    delete props.header;
    delete props.image;
    delete props.meta;

    return (

        {this.props.image && image}
        {hasContent && content}

    );
  }
}
<|endoftext|>


<commit_before>var CentsGauge = (function (containerID) {

  function CentsGauge() {

    ViewContextAndStyle.apply(this,arguments);

    var _width  = 400
      , _height = 200
      , twoPI   = 2 * Math.PI
      ;

    this.cvs.width  = 400;
    this.cvs.height = 200;

    var centerX       = this.cvs.width / 2
      , centerY       = this.cvs.height
      , radius        = 160
      , circumference = twoPI * radius
      , quadrantArc   = circumference / 4
      , dotRadius     = 3
      , zeroDotRadius = 5
      , markStep      = 50
      ;

    Object.defineProperties(this, {
        "width" : {
          enumerable   : true
        , configurable : false
        , get : function () {
            return _width;
          }
        , set : function (val) {
            _width = val;

            this.cvs.width = _width;
            centerX  = this.cvs.width / 2;

          }
        }
      , "height" : {
          enumerable   : true
        , configurable : false
        , get : function () {
            return _height;
          }
        , set : function (val) {
            _height = val;

            this.cvs.height = _height;
            centerY   = this.cvs.height;
          }
        }
      , "dotRadius" : {
           value        : dotRadius
         , configurable : false
         , enumerable   : true
         , writable     : true
        }
      , "zeroDotRadius" : {
           value        : zeroDotRadius
         , configurable : false
         , enumerable   : true
         , writable     : true
        }
      , "markStep" : {
          value        : markStep
        , configurable : false
        , enumerable   : true
        , writable     : true
        }
      , "radius" : {
          enumerable   : true
        , configurable : false
        , get          : function () {
            return radius;
          }
        , set : function (r) {
            radius = r;

            circumference = twoPI * radius;
            quadrantArc   = circumference / 4;
        }
      }
    });

    Object.defineProperties(CentsGauge.prototype, {
        "background" : {
          value : function() {

            var arc = quadrantArc - markStep
              , alfa
              , x
              , xs
              , y
              ;

            this.ctx.beginPath();
            this.ctx.arc(centerX,centerY,10,0,twoPI,false);
            this.ctx.arc(centerX,centerY - radius,zeroDotRadius,0,twoPI,true);
            this.ctx.fillStyle = this.color;
            this.ctx.fill();

            while (arc > 0) {

              alfa = arc / radius;

              x  = centerX - radius * Math.cos(alfa);
              xs = centerX + radius * Math.cos(alfa);
              y  = centerY - radius * Math.sin(alfa);

              this.ctx.beginPath();

              this.ctx.arc(x,y,dotRadius,0,twoPI,true);
              this.ctx.arc(xs,y,dotRadius,0,twoPI,true);
              this.ctx.fillStyle = this.color;

              this.ctx.fill();

              arc -= markStep;
            }
          }
        , enumerable   : false
        , configurable : false
        , writable     : false
        }
      , "run" : {
          value : function() {

            var arc  = quadrantArc - (this.peek.cents * quadrantArc / 50)
              , alfa = arc / radius
              , x = centerX + radius * Math.cos(alfa)
              , y = centerY - radius * Math.sin(alfa)
              ;

            this.ctx.clearRect(0,0,this.cvs.width,this.cvs.height);

            this.background();

            this.ctx.font      = this.noteFont;
            this.ctx.fillStyle = this.color;
            this.ctx.fillText(this.peek.note.name,20,50);

            this.ctx.font = this.freqFont;
            this.ctx.fillText(this.peek.frequency.toFixed(2) + " Hz",this.cvs.width-110,40);

            this.ctx.beginPath();
            this.ctx.moveTo(centerX,centerY);
            this.ctx.lineTo(x,y);
            this.ctx.strokeStyle = this.color;
            this.ctx.stroke();

            window.requestAnimationFrame(this.run.bind(this));
          }
        , enumerable   : false
        , configurable : false
        , writable     : false
        }
      , "update" : {
          value : function (element) {

            this.peek = element.peek;

          }
        , enumerable   : false
        , configurable : false
        , writable     : false
        }
      }
    );
  };

  if (!this.instance) {
    this.instance = new CentsGauge(containerID);
  } else {
    console.log("An instance of CentsGauge already exists.");
  }

  return this.instance;

});<commit_msg>Simplify x coordinate calculation.<commit_after>var CentsGauge = (function (containerID) {

  function CentsGauge() {

    ViewContextAndStyle.apply(this,arguments);

    var _width  = 400
      , _height = 200
      , twoPI   = 2 * Math.PI
      ;

    this.cvs.width  = 400;
    this.cvs.height = 200;

    var centerX       = this.cvs.width / 2
      , centerY       = this.cvs.height
      , radius        = 160
      , circumference = twoPI * radius
      , quadrantArc   = circumference / 4
      , dotRadius     = 3
      , zeroDotRadius = 5
      , markStep      = 50
      ;

    Object.defineProperties(this, {
        "width" : {
          enumerable   : true
        , configurable : false
        , get : function () {
            return _width;
          }
        , set : function (val) {
            _width = val;

            this.cvs.width = _width;
            centerX  = this.cvs.width / 2;
          }
        }
      , "height" : {
          enumerable   : true
        , configurable : false
        , get : function () {
            return _height;
          }
        , set : function (val) {
            _height = val;

            this.cvs.height = _height;
            centerY         = this.cvs.height;
          }
        }
      , "dotRadius" : {
           value        : dotRadius
         , configurable : false
         , enumerable   : true
         , writable     : true
        }
      , "zeroDotRadius" : {
           value        : zeroDotRadius
         , configurable : false
         , enumerable   : true
         , writable     : true
        }
      , "markStep" : {
          value        : markStep
        , configurable : false
        , enumerable   : true
        , writable     : true
        }
      , "radius" : {
          enumerable   : true
        , configurable : false
        , get          : function () {
            return radius;
          }
        , set : function (r) {
            radius = r;

            circumference = twoPI * radius;
            quadrantArc   = circumference / 4;
        }
      }
    });

    Object.defineProperties(CentsGauge.prototype, {
        "background" : {
          value : function() {

            var arc = quadrantArc - markStep
              , alfa
              , x
              , xc
              , xs
              , y
              ;

            this.ctx.beginPath();
            this.ctx.arc(centerX,centerY,10,0,twoPI,false);
            this.ctx.arc(centerX,centerY - radius,zeroDotRadius,0,twoPI,true);
            this.ctx.fillStyle = this.color;
            this.ctx.fill();

            while (arc > 0) {

              alfa = arc / radius;
              xc   = radius * Math.cos(alfa);

              x  = centerX - xc;
              xs = centerX + xc;
              y  = centerY - radius * Math.sin(alfa);

              this.ctx.beginPath();

              this.ctx.arc(x,y,dotRadius,0,twoPI,true);
              this.ctx.arc(xs,y,dotRadius,0,twoPI,true);
              this.ctx.fillStyle = this.color;

              this.ctx.fill();

              arc -= markStep;
            }
          }
        , enumerable   : false
        , configurable : false
        , writable     : false
        }
      , "run" : {
          value : function() {

            var arc  = quadrantArc - (this.peek.cents * quadrantArc / 50)
              , alfa = arc / radius
              , x = centerX + radius * Math.cos(alfa)
              , y = centerY - radius * Math.sin(alfa)
              ;

            this.ctx.clearRect(0,0,this.cvs.width,this.cvs.height);

            this.background();

            this.ctx.font      = this.noteFont;
            this.ctx.fillStyle = this.color;

            this.ctx.fillText(this.peek.note.name,20,50);

            this.ctx.font = this.freqFont;
            this.ctx.fillText(this.peek.frequency.toFixed(2) + " Hz",this.cvs.width-110,40);

            this.ctx.beginPath();
            this.ctx.moveTo(centerX,centerY);
            this.ctx.lineTo(x,y);
            this.ctx.strokeStyle = this.color;
            this.ctx.stroke();

            window.requestAnimationFrame(this.run.bind(this));
          }
        , enumerable   : false
        , configurable : false
        , writable     : false
        }
      , "update" : {
          value : function (element) {

            this.peek = element.peek;

          }
        , enumerable   : false
        , configurable : false
        , writable     : false
        }
      }
    );
  };

  if (!this.instance) {
    this.instance = new CentsGauge(containerID);
  } else {
    console.log("An instance of CentsGauge already exists.");
  }

  return this.instance;

});<|endoftext|>


<commit_before>'use strict';

module.exports = {
    parserOptions: {
        ecmaVersion: 7,
    },

    env: {
        es6: true,
    },

    rules: {
        // Rules are divided into sections from http://eslint.org/docs/rules/

        // Possible errors
        'comma-dangle': [2, 'always-multiline'],
        'no-cond-assign': 2,
        'no-console': 0,
        'no-constant-condition': 2,
        'no-control-regex': 2,
        'no-debugger': 2,
        'no-dupe-args': 2,
        'no-dupe-keys': 2,
        'no-duplicate-case': 2,
        'no-empty-character-class': 2,
        'no-empty': 2,
        'no-ex-assign': 2,
        'no-extra-boolean-cast': 2,
        'no-extra-parens': 0,
        'no-extra-semi': 2,
        'no-func-assign': 2,
        'no-inner-declarations': 2,
        'no-invalid-regexp': 2,
        'no-irregular-whitespace': 2,
        'no-negated-in-lhs': 2,
        'no-obj-calls': 2,
        'no-regex-spaces': 2,
        'no-sparse-arrays': 2,
        'no-unreachable': 2,
        'use-isnan': 2,
        'valid-jsdoc': 0, // TODO enable?
        'valid-typeof': 2,
        'no-unexpected-multiline': 2,

        // Best practices
        'accessor-pairs': 2,
        'array-callback-return': 2,
        'block-scoped-var': 0,
        complexity: [1, 10],
        'consistent-return': 2,
        curly: 2,
        'default-case': 2,
        'dot-notation': 2,
        'dot-location': [2, 'property'],
        eqeqeq: [2, 'smart'],
        'guard-for-in': 0,
        'no-alert': 2,
        'no-caller': 2,
        'no-case-declarations': 2,
        'no-div-regex': 0,
        'no-else-return': 2,
        'no-empty-function': 2,
        'no-empty-pattern': 2,
        'no-eq-null': 0,
        'no-eval': 2,
        'no-extend-native': 2,
        'no-extra-bind': 2,
        'no-extra-label': 2,
        'no-fallthrough': 2,
        'no-floating-decimal': 2,
        'no-implicit-coercion': [2, {boolean: false, number: true, string: false}],
        'no-implicit-globals': 2,
        'no-implied-eval': 2,
        'no-invalid-this': 0,
        'no-iterator': 2,
        'no-labels': [2, {allowLoop: true, allowSwitch: true}],
        'no-lone-blocks': 0,
        'no-loop-func': 0,
        'no-magic-numbers': 0,
        'no-multi-spaces': 2,
        'no-multi-str': 2,
        'no-native-reassign': 2,
        'no-new-func': 2,
        'no-new-wrappers': 2,
        'no-new': 2,
        'no-octal-escape': 2,
        'no-octal': 2,
        'no-param-reassign': 0,
        'no-process-env': 0,
        'no-proto': 2,
        'no-redeclare': 2,
        'no-return-assign': 2,
        'no-script-url': 2,
        'no-self-assign': 2,
        'no-self-compare': 2,
        'no-sequences': 2,
        'no-throw-literal': 2,
        'no-unmodified-loop-condition': 2,
        'no-unused-expressions': 2,
        'no-unused-labels': 2,
        'no-useless-call': 2,
        'no-useless-concat': 2,
        'no-useless-escape': 2,
        'no-void': 2,
        'no-warning-comments': 0,
        'no-with': 2,
        radix: 0,
        'vars-on-top': 0,
        'wrap-iife': [2, 'inside'],
        yoda: 2,

        // Strict mode
        strict: [2, 'global'], // 'global' in Node, 'function' in a browser

        // Variables
        'init-declarations': 0,
        'no-catch-shadow': 0,
        'no-delete-var': 2,
        'no-label-var': 2,
        'no-restricted-globals': [2, 'arguments', 'event'],
        'no-shadow-restricted-names': 2,
        'no-shadow': 0,
        'no-undef-init': 2,
        'no-undef': 2,
        'no-undefined': 0,
        'no-unused-vars': [2, {args: 'all', argsIgnorePattern: '^__'}],
        'no-use-before-define': 0,

        // Node.js
        'callback-return': 0,
        'global-require': 0,
        'handle-callback-err': 2,
        'no-mixed-requires': 0,
        'no-new-require': 2,
        'no-path-concat': 0,
        'no-process-exit': 2,
        'no-restricted-imports': 0,
        'no-restricted-modules': 0,
        'no-sync': 0, // in some projects this might be useful

        // Stylistic issues
        'array-bracket-spacing': [2, 'never'],
        'block-spacing': [2, 'never'],
        'brace-style': 2,
        camelcase: 0,
        'comma-spacing': 2,
        'comma-style': 2,
        'computed-property-spacing': [2, 'never'],
        'consistent-this': 0,
        'eol-last': 2,
        'func-names': 0,
        'func-style': [2, 'expression'],
        'id-length': 0,
        'id-match': 0,
        'id-blacklist': [2, 'event'],
        indent: 0, // TODO try to enable it
        'jsx-quotes': 0,
        'key-spacing': 2,
        'keyword-spacing': 2,
        // Re-enable when commented out lines * ESLint pragmas work; was:
        // [2, {beforeBlockComment: true, beforeLineComment: true, allowBlockStart: true}],
        'lines-around-comment': 0,
        'linebreak-style': 0,
        'max-nested-callbacks': 0,
        'new-cap': 0,
        'new-parens': 2,
        'newline-after-var': 0,
        'newline-before-return': 0,
        'newline-per-chained-call': [2, {ignoreChainWithDepth: 4}],
        'no-array-constructor': 2,
        'no-continue': 0,
        'no-inline-comments': 0,
        'no-lonely-if': 2,
        'no-mixed-spaces-and-tabs': 2,
        'no-multiple-empty-lines': [2, {max: 2}],
        'no-nested-ternary': 2,
        'no-negated-condition': 2,
        'no-new-object': 2,
        'no-restricted-syntax': 0, // already handled via no-with; would be: [2, 'WithStatement'],
        'no-whitespace-before-property': 2,
        'no-spaced-func': 2,
        'no-ternary': 0,
        'no-trailing-spaces': 2,
        'no-underscore-dangle': 0,
        'no-unneeded-ternary': 2,
        'object-curly-spacing': [2, 'never'],
        'one-var': [2, {initialized: 'never'}],
        'one-var-declaration-per-line': 0, // I don't use this declaration style
        'operator-assignment': 2,
        'operator-linebreak': [2, 'after'],
        'padded-blocks': 0,
        'quote-props': [2, 'as-needed'],
        quotes: [2, 'single'],
        'require-jsdoc': 0,
        'semi-spacing': 2,
        semi: 2,
        'sort-vars': 0,
        'sort-imports': 0, // It sorts by the member syntax, not by module names
        'space-before-blocks': 2,
        'space-before-function-paren': [2, {anonymous: 'always', named: 'never'}],
        'space-in-parens': [2, 'never'],
        'space-infix-ops': 2,
        'space-unary-ops': 2,
        'spaced-comment': 2,
        'wrap-regex': 0,

        // ECMAScript 6
        'arrow-body-style': [2, 'as-needed'],
        'arrow-parens': [2, 'as-needed'],
        'arrow-spacing': 2,
        'constructor-super': 2,
        'generator-star-spacing': [2, {before: true, after: false}],
        // Arrow returning a ternary is disallowed; wrapping in braces doesn't help.
        'no-class-assign': 2,
        'no-confusing-arrow': 0,
        'no-const-assign': 2,
        'no-dupe-class-members': 2,
        'no-duplicate-imports': 2,
        'no-new-symbol': 2,
        'no-this-before-super': 2,
        'no-var': 2,
        'no-useless-constructor': 2,
        'object-shorthand': 2,
        'prefer-arrow-callback': 2,
        'prefer-const': 2,
        'prefer-spread': 2,
        'prefer-reflect': 2,
        'prefer-rest-params': 2,
        'prefer-template': 2,
        'require-yield': 0,
        'template-curly-spacing': [2, 'always'],
        'yield-star-spacing': [2, 'after'],

        // Legacy
        'max-depth': 0,
        'max-len': [2, 100, 4, {ignoreUrls: true}],
        'max-params': 0,
        'max-statements': 0,
        'max-statements-per-line': [2, {max: 1}],
        'no-bitwise': 2,
        'no-plusplus': 0,
    },
};
<commit_msg>Use the new 'off'/'warn'/'error'-based configuration<commit_after>'use strict';

module.exports = {
    parserOptions: {
        ecmaVersion: 7,
    },

    env: {
        es6: true,
    },

    rules: {
        // Rules are divided into sections from http://eslint.org/docs/rules/

        // Possible errors
        'comma-dangle': ['error', 'always-multiline'],
        'no-cond-assign': 'error',
        'no-console': 'off',
        'no-constant-condition': 'error',
        'no-control-regex': 'error',
        'no-debugger': 'error',
        'no-dupe-args': 'error',
        'no-dupe-keys': 'error',
        'no-duplicate-case': 'error',
        'no-empty-character-class': 'error',
        'no-empty': 'error',
        'no-ex-assign': 'error',
        'no-extra-boolean-cast': 'error',
        'no-extra-parens': 'off',
        'no-extra-semi': 'error',
        'no-func-assign': 'error',
        'no-inner-declarations': 'error',
        'no-invalid-regexp': 'error',
        'no-irregular-whitespace': 'error',
        'no-negated-in-lhs': 'error',
        'no-obj-calls': 'error',
        'no-regex-spaces': 'error',
        'no-sparse-arrays': 'error',
        'no-unreachable': 'error',
        'use-isnan': 'error',
        'valid-jsdoc': 'off', // TODO enable?
        'valid-typeof': 'error',
        'no-unexpected-multiline': 'error',

        // Best practices
        'accessor-pairs': 'error',
        'array-callback-return': 'error',
        'block-scoped-var': 'off',
        complexity: ['warn', 10],
        'consistent-return': 'error',
        curly: 'error',
        'default-case': 'error',
        'dot-notation': 'error',
        'dot-location': ['error', 'property'],
        eqeqeq: ['error', 'smart'],
        'guard-for-in': 'off',
        'no-alert': 'error',
        'no-caller': 'error',
        'no-case-declarations': 'error',
        'no-div-regex': 'off',
        'no-else-return': 'error',
        'no-empty-function': 'error',
        'no-empty-pattern': 'error',
        'no-eq-null': 'off',
        'no-eval': 'error',
        'no-extend-native': 'error',
        'no-extra-bind': 'error',
        'no-extra-label': 'error',
        'no-fallthrough': 'error',
        'no-floating-decimal': 'error',
        'no-implicit-coercion': ['error', {boolean: false, number: true, string: false}],
        'no-implicit-globals': 'error',
        'no-implied-eval': 'error',
        'no-invalid-this': 'off',
        'no-iterator': 'error',
        'no-labels': ['error', {allowLoop: true, allowSwitch: true}],
        'no-lone-blocks': 'off',
        'no-loop-func': 'off',
        'no-magic-numbers': 'off',
        'no-multi-spaces': 'error',
        'no-multi-str': 'error',
        'no-native-reassign': 'error',
        'no-new-func': 'error',
        'no-new-wrappers': 'error',
        'no-new': 'error',
        'no-octal-escape': 'error',
        'no-octal': 'error',
        'no-param-reassign': 'off',
        'no-process-env': 'off',
        'no-proto': 'error',
        'no-redeclare': 'error',
        'no-return-assign': 'error',
        'no-script-url': 'error',
        'no-self-assign': 'error',
        'no-self-compare': 'error',
        'no-sequences': 'error',
        'no-throw-literal': 'error',
        'no-unmodified-loop-condition': 'error',
        'no-unused-expressions': 'error',
        'no-unused-labels': 'error',
        'no-useless-call': 'error',
        'no-useless-concat': 'error',
        'no-useless-escape': 'error',
        'no-void': 'error',
        'no-warning-comments': 'off',
        'no-with': 'error',
        radix: 'off',
        'vars-on-top': 'off',
        'wrap-iife': ['error', 'inside'],
        yoda: 'error',

        // Strict mode
        strict: ['error', 'global'], // 'global' in Node, 'function' in a browser

        // Variables
        'init-declarations': 'off',
        'no-catch-shadow': 'off',
        'no-delete-var': 'error',
        'no-label-var': 'error',
        'no-restricted-globals': ['error', 'arguments', 'event'],
        'no-shadow-restricted-names': 'error',
        'no-shadow': 'off',
        'no-undef-init': 'error',
        'no-undef': 'error',
        'no-undefined': 'off',
        'no-unused-vars': ['error', {args: 'all', argsIgnorePattern: '^__'}],
        'no-use-before-define': 'off',

        // Node.js
        'callback-return': 'off',
        'global-require': 'off',
        'handle-callback-err': 'error',
        'no-mixed-requires': 'off',
        'no-new-require': 'error',
        'no-path-concat': 'off',
        'no-process-exit': 'error',
        'no-restricted-imports': 'off',
        'no-restricted-modules': 'off',
        'no-sync': 'off', // in some projects this might be useful

        // Stylistic issues
        'array-bracket-spacing': ['error', 'never'],
        'block-spacing': ['error', 'never'],
        'brace-style': 'error',
        camelcase: 'off',
        'comma-spacing': 'error',
        'comma-style': 'error',
        'computed-property-spacing': ['error', 'never'],
        'consistent-this': 'off',
        'eol-last': 'error',
        'func-names': 'off',
        'func-style': ['error', 'expression'],
        'id-length': 'off',
        'id-match': 'off',
        'id-blacklist': ['error', 'event'],
        indent: 'off', // TODO try to enable it
        'jsx-quotes': 'off',
        'key-spacing': 'error',
        'keyword-spacing': 'error',
        // Re-enable when commented out lines * ESLint pragmas work; was:
        // ['error', {beforeBlockComment: true, beforeLineComment: true, allowBlockStart: true}],
        'lines-around-comment': 'off',
        'linebreak-style': 'off',
        'max-nested-callbacks': 'off',
        'new-cap': 'off',
        'new-parens': 'error',
        'newline-after-var': 'off',
        'newline-before-return': 'off',
        'newline-per-chained-call': ['error', {ignoreChainWithDepth: 4}],
        'no-array-constructor': 'error',
        'no-continue': 'off',
        'no-inline-comments': 'off',
        'no-lonely-if': 'error',
        'no-mixed-spaces-and-tabs': 'error',
        'no-multiple-empty-lines': ['error', {max: 2}],
        'no-nested-ternary': 'error',
        'no-negated-condition': 'error',
        'no-new-object': 'error',
        // Already handled via no-with; would be: ['error', 'WithStatement']:
        'no-restricted-syntax': 'off',
        'no-whitespace-before-property': 'error',
        'no-spaced-func': 'error',
        'no-ternary': 'off',
        'no-trailing-spaces': 'error',
        'no-underscore-dangle': 'off',
        'no-unneeded-ternary': 'error',
        'object-curly-spacing': ['error', 'never'],
        'one-var': ['error', {initialized: 'never'}],
        'one-var-declaration-per-line': 'off', // I don't use this declaration style
        'operator-assignment': 'error',
        'operator-linebreak': ['error', 'after'],
        'padded-blocks': 'off',
        'quote-props': ['error', 'as-needed'],
        quotes: ['error', 'single'],
        'require-jsdoc': 'off',
        'semi-spacing': 'error',
        semi: 'error',
        'sort-vars': 'off',
        'sort-imports': 'off', // It sorts by the member syntax, not by module names
        'space-before-blocks': 'error',
        'space-before-function-paren': ['error', {anonymous: 'always', named: 'never'}],
        'space-in-parens': ['error', 'never'],
        'space-infix-ops': 'error',
        'space-unary-ops': 'error',
        'spaced-comment': 'error',
        'wrap-regex': 'off',

        // ECMAScript 6
        'arrow-body-style': ['error', 'as-needed'],
        'arrow-parens': ['error', 'as-needed'],
        'arrow-spacing': 'error',
        'constructor-super': 'error',
        'generator-star-spacing': ['error', {before: true, after: false}],
        // Arrow returning a ternary is disallowed; wrapping in braces doesn't help.
        'no-class-assign': 'error',
        'no-confusing-arrow': 'off',
        'no-const-assign': 'error',
        'no-dupe-class-members': 'error',
        'no-duplicate-imports': 'error',
        'no-new-symbol': 'error',
        'no-this-before-super': 'error',
        'no-var': 'error',
        'no-useless-constructor': 'error',
        'object-shorthand': 'error',
        'prefer-arrow-callback': 'error',
        'prefer-const': 'error',
        'prefer-spread': 'error',
        'prefer-reflect': 'error',
        'prefer-rest-params': 'error',
        'prefer-template': 'error',
        'require-yield': 'off',
        'template-curly-spacing': ['error', 'always'],
        'yield-star-spacing': ['error', 'after'],

        // Legacy
        'max-depth': 'off',
        'max-len': ['error', 100, 4, {ignoreUrls: true}],
        'max-params': 'off',
        'max-statements': 'off',
        'max-statements-per-line': ['error', {max: 1}],
        'no-bitwise': 'error',
        'no-plusplus': 'off',
    },
};
<|endoftext|>


<commit_before>module.exports = {
  'rules': {
    // enforce spacing inside array brackets
    'array-bracket-spacing': ['error', 'never'],

    // disallow or enforce spaces inside of single line blocks
    'block-spacing': ['error', 'always'],

    // enforce one true brace style
    'brace-style': ['error', '1tbs', { 'allowSingleLine': true }],

    // require camel case names
    'camelcase': ['error', { properties: 'never' }],

    // enforce spacing before and after comma
    'comma-spacing': ['error', { before: false, after: true }],

    // enforce one true comma style
    'comma-style': ['error', 'last'],

    // require or disallow padding inside computed properties
    'computed-property-spacing': ['error', 'never'],

    // enforces consistent naming when capturing the current execution context
    'consistent-this': ['error', 'self'],

    // enforce newline at the end of file, with no multiple empty lines
    'eol-last': ['error', 'always'],

    // enforce spacing between functions and their invocations
    'func-call-spacing': ['error', 'always'],

    // requires function names to match the name of the variable or property to which they are assigned
    'func-name-matching': ['off', 'always', {
      includeCommonJSModuleExports: false,
    }],

    // require function expressions to have a name
    'func-names': 'off',

    // enforces use of function declarations or expressions
    'func-style': ['off', 'expression'],

    // disallow specified identifiers
    'id-blacklist': 'off',

    // enforce minimum and maximum identifier lengths
    'id-length': 'off',

    // require identifiers to match the provided regular expression
    'id-match': 'off',

    // this option sets a specific tab width for your code
    'indent': ['error', 2, { 'SwitchCase': 1 }],

    // specify whether double or single quotes should be used in JSX attributes
    'jsx-quotes': ['error', 'prefer-single'],

    // enforces spacing between keys and values in object literal properties
    'key-spacing': ['error', { 'beforeColon': false, 'afterColon': true }],

    // enforce consistent spacing before and after keywords
    'keyword-spacing': ['error', { 'before': true, 'after': true }],

    // disallow mixed 'LF' and 'CRLF' as linebreaks
    'linebreak-style': ['error', 'unix'],

    // enforce position of line comments
    'line-comment-position': ['warn', { position: 'above' }],

    // enforces empty lines around comments
    'lines-around-comment': 'off',

    // require or disallow newlines around directives
    'lines-around-directive': ['error', { 'before': 'never', 'after': 'always' }],

    // specify the maximum depth that blocks can be nested
    'max-depth': ['off', 4],

    // specify the maximum length of a line in your program
    'max-len': ['error', 120, 2, {
      'ignoreUrls': true,
      'ignoreComments': false,
      'ignoreRegExpLiterals': true,
      'ignoreStrings': true,
      'ignoreTemplateLiterals': true,
    }],

    // specify the max number of lines in a file
    'max-lines': 'off',

    // specify the maximum depth callbacks can be nested
    'max-nested-callbacks': 'off',

    // limits the number of parameters that can be used in the function declaration.
    'max-params': 'off',

    // specify the maximum number of statement allowed in a function
    'max-statements': 'off',

    // enforce a maximum number of statements allowed per line
    'max-statements-per-line': 'off',

    // require multiline ternary
    'multiline-ternary': 'off',

    // require a capital letter for constructors
    'new-cap': 'error',

    // disallow the omission of parentheses when invoking a constructor with no arguments
    'new-parens': 'error',

    // allow/disallow an empty newline after var statement
    'newline-after-var': 'off',

    // require newline before return statement
    'newline-before-return': 'off',

    // require a newline after each call in a method chain
    'newline-per-chained-call': 'off',

    // disallow use of the Array constructor
    'no-array-constructor': 'error',

    // disallow use of bitwise operators
    'no-bitwise': 'error',

    // disallow use of the continue statement
    'no-continue': 'error',

    // disallow comments inline after code
    'no-inline-comments': 'off',

    // disallow if as the only statement in an else block
    'no-lonely-if': 'error',

    // disallow un-paren'd mixes of different operators
    'no-mixed-operators': ['error', {
      groups: [
        ['+', '-', '*', '/', '%', '**'],
        ['&', '|', '^', '~', '<<', '>>', '>>>'],
        ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
        ['&&', '||'],
        ['in', 'instanceof'],
      ],
      allowSamePrecedence: false,
    }],

    // disallow mixed spaces and tabs for indentation
    'no-mixed-spaces-and-tabs': 'error',

    // disallow multiple empty lines and only one newline at the end
    'no-multiple-empty-lines': ['error', { 'max': 2, 'maxEOF': 1 }],

    // disallow negated conditions
    'no-negated-condition': 'off',

    // disallow nested ternary expressions
    'no-nested-ternary': 'error',

    // disallow use of the Object constructor
    'no-new-object': 'error',

    // disallow use of unary operators, ++ and --
    'no-plusplus': 'error',

    // disallow specified syntax
    'no-restricted-syntax': ['error', 'LabeledStatement'],

    // disallow space between function identifier and application
    'no-spaced-func': 'off',

    // disallow tab characters entirely
    'no-tabs': 'error',

    // disallow the use of ternary operators
    'no-ternary': 'off',

    // disallow trailing whitespace at the end of lines
    'no-trailing-spaces': 'error',

    // disallow dangling underscores in identifiers
    'no-underscore-dangle': 'off',

    // disallow the use of Boolean literals in conditional expressions
    'no-unneeded-ternary': 'off',

    // disallow whitespace before properties
    'no-whitespace-before-property': 'error',

    // enforce consistent spacing inside braces
    'object-curly-spacing': ['error', 'always'],

    // enforce line breaks between braces
    'object-curly-newline': 'off',

    // enforce "same line" or "multiple line" on object properties.
    'object-property-newline': ['error', {
      allowMultiplePropertiesPerLine: true,
    }],

    // allow just one var statement per function
    'one-var': ['error', 'never'],

    // require or disallow an newline around variable declarations
    'one-var-declaration-per-line': ['error', 'always'],

    // require assignment operator shorthand where possible or prohibit it entirely
    'operator-assignment': ['error', 'always'],

    // enforce operators to be placed before or after line breaks
    'operator-linebreak': 'off',

    // enforce padding within blocks
    'padded-blocks': ['error', 'never'],

    // require quotes around object literal property names
    'quote-props': 'off',

    // specify whether double or single quotes should be used
    'quotes': ['error', 'single'],

    // Require JSDoc comments
    'require-jsdoc': 'off',

    // require or disallow use of semicolons instead of ASI
    'semi': ['error', 'always'],

    // enforce spacing before and after semicolons
    'semi-spacing': ['error', { 'before': false, 'after': true }],

    // enforce sorting import declarations within module
    'sort-imports': 'off',

    // requires object keys to be sorted
    'sort-keys': 'off',

    // sort variables within the same declaration block
    'sort-vars': 'off',

    // require or disallow space before blocks
    'space-before-blocks': ['error', 'always'],

    // require or disallow space before function opening parenthesis
    'space-before-function-paren': ['error', 'always'],

    // require or disallow spaces inside parentheses
    'space-in-parens': ['error', 'never'],

    // require spaces around operators
    'space-infix-ops': 'error',

    // Require or disallow spaces before/after unary operators
    'space-unary-ops': ['error', {
      'words': true,
      'nonwords': true,
      'overrides': {
        '+': false,
        '-': false,
      },
    }],

    // require or disallow a space immediately following the // or /* in a comment
    'spaced-comment': 'off',

    // require or disallow the Unicode Byte Order Mark
    'unicode-bom': ['error', 'never'],

    // require regex literals to be wrapped in parentheses
    'wrap-regex': 'off',
  },
};
<commit_msg>update rule<commit_after>module.exports = {
  'rules': {
    // enforce spacing inside array brackets
    'array-bracket-spacing': ['error', 'never'],

    // disallow or enforce spaces inside of single line blocks
    'block-spacing': ['error', 'always'],

    // enforce one true brace style
    'brace-style': ['error', '1tbs', { 'allowSingleLine': true }],

    // require camel case names
    'camelcase': ['error', { properties: 'never' }],

    // enforce spacing before and after comma
    'comma-spacing': ['error', { before: false, after: true }],

    // enforce one true comma style
    'comma-style': ['error', 'last'],

    // require or disallow padding inside computed properties
    'computed-property-spacing': ['error', 'never'],

    // enforces consistent naming when capturing the current execution context
    'consistent-this': ['error', 'self'],

    // enforce newline at the end of file, with no multiple empty lines
    'eol-last': ['error', 'always'],

    // enforce spacing between functions and their invocations
    'func-call-spacing': ['error', 'always'],

    // requires function names to match the name of the variable or property to which they are assigned
    'func-name-matching': ['off', 'always', {
      includeCommonJSModuleExports: false,
    }],

    // require function expressions to have a name
    'func-names': 'off',

    // enforces use of function declarations or expressions
    'func-style': ['off', 'expression'],

    // disallow specified identifiers
    'id-blacklist': 'off',

    // enforce minimum and maximum identifier lengths
    'id-length': 'off',

    // require identifiers to match the provided regular expression
    'id-match': 'off',

    // this option sets a specific tab width for your code
    'indent': ['error', 2, { 'SwitchCase': 1 }],

    // specify whether double or single quotes should be used in JSX attributes
    'jsx-quotes': ['error', 'prefer-single'],

    // enforces spacing between keys and values in object literal properties
    'key-spacing': ['error', { 'beforeColon': false, 'afterColon': true }],

    // enforce consistent spacing before and after keywords
    'keyword-spacing': ['error', { 'before': true, 'after': true }],

    // disallow mixed 'LF' and 'CRLF' as linebreaks
    'linebreak-style': ['error', 'unix'],

    // enforce position of line comments
    'line-comment-position': ['warn', { position: 'above' }],

    // enforces empty lines around comments
    'lines-around-comment': 'off',

    // require or disallow newlines around directives
    'lines-around-directive': ['error', { 'before': 'never', 'after': 'always' }],

    // specify the maximum depth that blocks can be nested
    'max-depth': ['off', 4],

    // specify the maximum length of a line in your program
    'max-len': ['error', 120, 2, {
      'ignoreUrls': true,
      'ignoreComments': false,
      'ignoreRegExpLiterals': true,
      'ignoreStrings': true,
      'ignoreTemplateLiterals': true,
    }],

    // specify the max number of lines in a file
    'max-lines': 'off',

    // specify the maximum depth callbacks can be nested
    'max-nested-callbacks': 'off',

    // limits the number of parameters that can be used in the function declaration.
    'max-params': 'off',

    // specify the maximum number of statement allowed in a function
    'max-statements': 'off',

    // enforce a maximum number of statements allowed per line
    'max-statements-per-line': 'off',

    // require multiline ternary
    'multiline-ternary': 'off',

    // require a capital letter for constructors
    'new-cap': 'error',

    // disallow the omission of parentheses when invoking a constructor with no arguments
    'new-parens': 'error',

    // allow/disallow an empty newline after var statement
    'newline-after-var': 'off',

    // require newline before return statement
    'newline-before-return': 'off',

    // require a newline after each call in a method chain
    'newline-per-chained-call': 'off',

    // disallow use of the Array constructor
    'no-array-constructor': 'error',

    // disallow use of bitwise operators
    'no-bitwise': 'error',

    // disallow use of the continue statement
    'no-continue': 'error',

    // disallow comments inline after code
    'no-inline-comments': 'off',

    // disallow if as the only statement in an else block
    'no-lonely-if': 'error',

    // disallow un-paren'd mixes of different operators
    'no-mixed-operators': ['error', {
      groups: [
        ['+', '-', '*', '/', '%', '**'],
        ['&', '|', '^', '~', '<<', '>>', '>>>'],
        ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
        ['&&', '||'],
        ['in', 'instanceof'],
      ],
      allowSamePrecedence: false,
    }],

    // disallow mixed spaces and tabs for indentation
    'no-mixed-spaces-and-tabs': 'error',

    // disallow multiple empty lines and only one newline at the end
    'no-multiple-empty-lines': ['error', { 'max': 2, 'maxEOF': 1 }],

    // disallow negated conditions
    'no-negated-condition': 'off',

    // disallow nested ternary expressions
    'no-nested-ternary': 'error',

    // disallow use of the Object constructor
    'no-new-object': 'error',

    // disallow use of unary operators, ++ and --
    'no-plusplus': ['error', { 'allowForLoopAfterthoughts': true }],

    // disallow specified syntax
    'no-restricted-syntax': ['error', 'LabeledStatement'],

    // disallow space between function identifier and application
    'no-spaced-func': 'off',

    // disallow tab characters entirely
    'no-tabs': 'error',

    // disallow the use of ternary operators
    'no-ternary': 'off',

    // disallow trailing whitespace at the end of lines
    'no-trailing-spaces': 'error',

    // disallow dangling underscores in identifiers
    'no-underscore-dangle': 'off',

    // disallow the use of Boolean literals in conditional expressions
    'no-unneeded-ternary': 'off',

    // disallow whitespace before properties
    'no-whitespace-before-property': 'error',

    // enforce consistent spacing inside braces
    'object-curly-spacing': ['error', 'always'],

    // enforce line breaks between braces
    'object-curly-newline': 'off',

    // enforce "same line" or "multiple line" on object properties.
    'object-property-newline': ['error', {
      allowMultiplePropertiesPerLine: true,
    }],

    // allow just one var statement per function
    'one-var': ['error', 'never'],

    // require or disallow an newline around variable declarations
    'one-var-declaration-per-line': ['error', 'always'],

    // require assignment operator shorthand where possible or prohibit it entirely
    'operator-assignment': ['error', 'always'],

    // enforce operators to be placed before or after line breaks
    'operator-linebreak': 'off',

    // enforce padding within blocks
    'padded-blocks': ['error', 'never'],

    // require quotes around object literal property names
    'quote-props': 'off',

    // specify whether double or single quotes should be used
    'quotes': ['error', 'single'],

    // Require JSDoc comments
    'require-jsdoc': 'off',

    // require or disallow use of semicolons instead of ASI
    'semi': ['error', 'always'],

    // enforce spacing before and after semicolons
    'semi-spacing': ['error', { 'before': false, 'after': true }],

    // enforce sorting import declarations within module
    'sort-imports': 'off',

    // requires object keys to be sorted
    'sort-keys': 'off',

    // sort variables within the same declaration block
    'sort-vars': 'off',

    // require or disallow space before blocks
    'space-before-blocks': ['error', 'always'],

    // require or disallow space before function opening parenthesis
    'space-before-function-paren': ['error', 'always'],

    // require or disallow spaces inside parentheses
    'space-in-parens': ['error', 'never'],

    // require spaces around operators
    'space-infix-ops': 'error',

    // Require or disallow spaces before/after unary operators
    'space-unary-ops': ['error', {
      'words': true,
      'nonwords': true,
      'overrides': {
        '+': false,
        '-': false,
      },
    }],

    // require or disallow a space immediately following the // or /* in a comment
    'spaced-comment': 'off',

    // require or disallow the Unicode Byte Order Mark
    'unicode-bom': ['error', 'never'],

    // require regex literals to be wrapped in parentheses
    'wrap-regex': 'off',
  },
};
<|endoftext|>


<commit_before>var gRex = require('../index.js'),
  T = gRex.T,
  Contains = gRex.Contains,
  Vertex = gRex.Vertex,
  Edge = gRex.Edge;

var gRex;

before(function(done) {
  gRex.connect()
    .then(function(result) {
      gRex = result;
      done();
    })
    .fail(function(error) {
      console.error(error);
    });
});

describe('Gremlin steps', function() {
  describe('Transform-based steps', function() {
    it('should chain .V()', function() {
      var query = gRex.gremlin().g.V();
      query.gremlin.script.should.equal('g.V()');
    });

    it('should chain .V(key, value)', function() {
      var query = gRex.gremlin().g.V('name', 'marko');
      query.gremlin.script.should.equal("g.V('name','marko')");
    });

    it('should chain .E()', function() {
      var query = gRex.gremlin().g.E();
      query.gremlin.script.should.equal("g.E()");
    });

    it("should chain .v() with a numerical id", function() {
      var query = gRex.gremlin().g.v(1);
      query.gremlin.script.should.equal("g.v(1)");
    });

    it("should chain .v() with multiple numerical ids", function() {
      var query = gRex.gremlin().g.v(1, 4);
      query.gremlin.script.should.equal("g.v(1,4)");
    });

    it("should chain .id()", function() {
      var query = gRex.gremlin().g.V().id();
      query.gremlin.script.should.equal('g.V().id()');
    });

    it('should chain .transform() with a closure', function() {
      var query = gRex.gremlin().g.E().has('weight', T.gt, '0.5f').outV().transform('{[it.id,it.age]}');
      query.gremlin.script.should.equal("g.E().has('weight',T.gt,0.5f).outV().transform(){[it.id,it.age]}");
    });

    it('should chain .select()', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select();
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select()");
    });

    it('should chain .select([])', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select(["y"]);
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select([\"y\"])");
    });

    it('should chain .select([]) & 1 closure', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select(["y"],"{it.name}");
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select([\"y\"]){it.name}");
    });

    it('should chain .select() & 2 closures', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select("{it.id}{it.name}");
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select(){it.id}{it.name}");
    });

    it("should chain .orderMap()", function() {
      var query = gRex.gremlin().g.V().both().groupCount().cap().orderMap(T.decr);
      query.gremlin.script.should.equal("g.V().both().groupCount().cap().orderMap(T.decr)");
    });
  });

  describe('Filter-based steps', function() {
    it('should chain .index() as []', function() {
      var query = gRex.gremlin().g.V().index(0).property('name');
      query.gremlin.script.should.equal("g.V()[0].property('name')");
    });

    it('should chain .range() as [..]', function() {
      var query = gRex.gremlin().g.V().range('0..<2').property('name');
      query.gremlin.script.should.equal("g.V()[0..<2].property('name')");
    });

    it('should chain .and() with 2 conditions', function() {
      var gremlin = gRex.gremlin();
      var query = gremlin.g.V().and(gremlin._().both("knows"), gremlin._().both("created"));
      query.gremlin.script.should.equal("g.V().and(_().both('knows'),_().both('created'))");
    });

    it('should chain .or() with 2 conditions', function() {
      var gremlin = gRex.gremlin();
      var query = gremlin.g.v(1).outE().or(gremlin._().has('id', T.eq, 9), gremlin._().has('weight', T.lt, '0.6f'));
      query.gremlin.script.should.equal("g.v(1).outE().or(_().has('id',T.eq,9),_().has('weight',T.lt,0.6f))");
    });

    it('should chain .retain([])', function() {
      var gremlin = gRex.gremlin();

      var query = gremlin.g.V().retain([gremlin.g.v(1), gremlin.g.v(2), gremlin.g.v(3)]);

      query.gremlin.script.should.equal("g.V().retain([g.v(1),g.v(2),g.v(3),])");
    });

    it('should chain .except()', function() {
      var query = gRex.gremlin().g.V().has('age',T.lt,30).as('x').out('created').in('created').except('x');
      query.gremlin.script.should.equal("g.V().has('age',T.lt,30).as('x').out('created').in('created').except('x')");
    });
  });

  describe('SideEffect-based steps', function() {
    it("should chain .gather()", function() {
      var query = gRex.gremlin().g.v(1).out().gather("{it.size()}");
      query.gremlin.script.should.equal("g.v(1).out().gather(){it.size()}");
    });
  });

  describe('Branch-based steps', function() {
    it("should chain .ifThenElse()", function() {
      var query = gRex.gremlin().g.v(1).out().ifThenElse("{it.name=='josh'}{it.age}{it.name}");
      query.gremlin.script.should.equal("g.v(1).out().ifThenElse(){it.name=='josh'}{it.age}{it.name}");
    });

    it("should chain .copySplit()", function() {
      var gremlin = gRex.gremlin();
      var query = gremlin.g.v(1).out('knows').copySplit(gremlin._().out('created').property('name'), gremlin._().property('age')).fairMerge();
      query.gremlin.script.should.equal("g.v(1).out('knows').copySplit(_().out('created').property('name'),_().property('age')).fairMerge()");
    });
  });
});

describe('Graph methods', function() {
  describe('indexing', function() {
    it("should support g.createIndex()", function() {
      var query = gRex.gremlin().g.createIndex("my-index", 'Vertex.class');
      query.gremlin.script.should.equal("g.createIndex('my-index',Vertex.class)");
    });

    it("should support g.idx().put()", function() {
      var gremlin = gRex.gremlin();
      var query = gRex.gremlin().g.idx("my-index").put("name", "marko", gremlin.g.v(1));
      query.gremlin.script.should.equal("g.idx('my-index').put('name','marko',g.v(1))");
    });

    it("should support g.idx(name, {})", function() {
      var query = gRex.gremlin().g.idx("my-index", {'name':'marko'});
      query.gremlin.script.should.equal("g.idx('my-index')[[name:'marko']]");
    });

    it("should support g.dropIndex()", function() {
      var query = gRex.gremlin().g.dropIndex("my-index");
      query.gremlin.script.should.equal("g.dropIndex('my-index')");
    });
  });

  describe('Elements', function() {
    it("should chain .keys()", function() {
      var query = gRex.gremlin().g.v(1).keys();
      query.gremlin.script.should.equal("g.v(1).keys()");
    });

    it("should chain .values()", function() {
      var query = gRex.gremlin().g.v(1).values();
      query.gremlin.script.should.equal("g.v(1).values()");
    });
  });
});

describe('Misc', function() {
  describe('float', function() {
    it("should handle float values", function() {
      var query = gRex.gremlin().g.v(1).outE().has("weight", T.gte, "0.5f");
      query.gremlin.script.should.equal("g.v(1).outE().has('weight',T.gte,0.5f)");
    });
  });
});
<commit_msg>Update .select() tests description<commit_after>var gRex = require('../index.js'),
  T = gRex.T,
  Contains = gRex.Contains,
  Vertex = gRex.Vertex,
  Edge = gRex.Edge;

var gRex;

before(function(done) {
  gRex.connect()
    .then(function(result) {
      gRex = result;
      done();
    })
    .fail(function(error) {
      console.error(error);
    });
});

describe('Gremlin steps', function() {
  describe('Transform-based steps', function() {
    it('should chain .V()', function() {
      var query = gRex.gremlin().g.V();
      query.gremlin.script.should.equal('g.V()');
    });

    it('should chain .V(key, value)', function() {
      var query = gRex.gremlin().g.V('name', 'marko');
      query.gremlin.script.should.equal("g.V('name','marko')");
    });

    it('should chain .E()', function() {
      var query = gRex.gremlin().g.E();
      query.gremlin.script.should.equal("g.E()");
    });

    it("should chain .v() with a numerical id", function() {
      var query = gRex.gremlin().g.v(1);
      query.gremlin.script.should.equal("g.v(1)");
    });

    it("should chain .v() with multiple numerical ids", function() {
      var query = gRex.gremlin().g.v(1, 4);
      query.gremlin.script.should.equal("g.v(1,4)");
    });

    it("should chain .id()", function() {
      var query = gRex.gremlin().g.V().id();
      query.gremlin.script.should.equal('g.V().id()');
    });

    it('should chain .transform() with a closure', function() {
      var query = gRex.gremlin().g.E().has('weight', T.gt, '0.5f').outV().transform('{[it.id,it.age]}');
      query.gremlin.script.should.equal("g.E().has('weight',T.gt,0.5f).outV().transform(){[it.id,it.age]}");
    });

    /**
     * Select the named steps to emit after select with post-processing closures.
     * @see http://gremlindocs.com/#transform/select
     */
    it('should handle no argument', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select();
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select()");
    });

    it('should handle an array of strings', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select(["y"]);
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select([\"y\"])");
    });

    it('should handle an array of strings & 1 post-processing closure', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select(["y"],"{it.name}");
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select([\"y\"]){it.name}");
    });

    it('should handle no argument & 2 post-processing closures', function() {
      var query = gRex.gremlin().g.v(1).as('x').out('knows').as('y').select("{it.id}{it.name}");
      query.gremlin.script.should.equal("g.v(1).as('x').out('knows').as('y').select(){it.id}{it.name}");
    });

    it("should handle ordering class argument", function() {
      var query = gRex.gremlin().g.V().both().groupCount().cap().orderMap(T.decr);
      query.gremlin.script.should.equal("g.V().both().groupCount().cap().orderMap(T.decr)");
    });
  });

  describe('Filter-based steps', function() {
    it('should chain .index() as []', function() {
      var query = gRex.gremlin().g.V().index(0).property('name');
      query.gremlin.script.should.equal("g.V()[0].property('name')");
    });

    it('should chain .range() as [..]', function() {
      var query = gRex.gremlin().g.V().range('0..<2').property('name');
      query.gremlin.script.should.equal("g.V()[0..<2].property('name')");
    });

    it('should chain .and() with 2 conditions', function() {
      var gremlin = gRex.gremlin();
      var query = gremlin.g.V().and(gremlin._().both("knows"), gremlin._().both("created"));
      query.gremlin.script.should.equal("g.V().and(_().both('knows'),_().both('created'))");
    });

    it('should chain .or() with 2 conditions', function() {
      var gremlin = gRex.gremlin();
      var query = gremlin.g.v(1).outE().or(gremlin._().has('id', T.eq, 9), gremlin._().has('weight', T.lt, '0.6f'));
      query.gremlin.script.should.equal("g.v(1).outE().or(_().has('id',T.eq,9),_().has('weight',T.lt,0.6f))");
    });

    it('should chain .retain([])', function() {
      var gremlin = gRex.gremlin();

      var query = gremlin.g.V().retain([gremlin.g.v(1), gremlin.g.v(2), gremlin.g.v(3)]);

      query.gremlin.script.should.equal("g.V().retain([g.v(1),g.v(2),g.v(3),])");
    });

    it('should chain .except()', function() {
      var query = gRex.gremlin().g.V().has('age',T.lt,30).as('x').out('created').in('created').except('x');
      query.gremlin.script.should.equal("g.V().has('age',T.lt,30).as('x').out('created').in('created').except('x')");
    });
  });

  describe('SideEffect-based steps', function() {
    it("should chain .gather()", function() {
      var query = gRex.gremlin().g.v(1).out().gather("{it.size()}");
      query.gremlin.script.should.equal("g.v(1).out().gather(){it.size()}");
    });
  });

  describe('Branch-based steps', function() {
    it("should chain .ifThenElse()", function() {
      var query = gRex.gremlin().g.v(1).out().ifThenElse("{it.name=='josh'}{it.age}{it.name}");
      query.gremlin.script.should.equal("g.v(1).out().ifThenElse(){it.name=='josh'}{it.age}{it.name}");
    });

    it("should chain .copySplit()", function() {
      var gremlin = gRex.gremlin();
      var query = gremlin.g.v(1).out('knows').copySplit(gremlin._().out('created').property('name'), gremlin._().property('age')).fairMerge();
      query.gremlin.script.should.equal("g.v(1).out('knows').copySplit(_().out('created').property('name'),_().property('age')).fairMerge()");
    });
  });
});

describe('Graph methods', function() {
  describe('indexing', function() {
    it("should support g.createIndex()", function() {
      var query = gRex.gremlin().g.createIndex("my-index", 'Vertex.class');
      query.gremlin.script.should.equal("g.createIndex('my-index',Vertex.class)");
    });

    it("should support g.idx().put()", function() {
      var gremlin = gRex.gremlin();
      var query = gRex.gremlin().g.idx("my-index").put("name", "marko", gremlin.g.v(1));
      query.gremlin.script.should.equal("g.idx('my-index').put('name','marko',g.v(1))");
    });

    it("should support g.idx(name, {})", function() {
      var query = gRex.gremlin().g.idx("my-index", {'name':'marko'});
      query.gremlin.script.should.equal("g.idx('my-index')[[name:'marko']]");
    });

    it("should support g.dropIndex()", function() {
      var query = gRex.gremlin().g.dropIndex("my-index");
      query.gremlin.script.should.equal("g.dropIndex('my-index')");
    });
  });

  describe('Elements', function() {
    it("should chain .keys()", function() {
      var query = gRex.gremlin().g.v(1).keys();
      query.gremlin.script.should.equal("g.v(1).keys()");
    });

    it("should chain .values()", function() {
      var query = gRex.gremlin().g.v(1).values();
      query.gremlin.script.should.equal("g.v(1).values()");
    });
  });
});

describe('Misc', function() {
  describe('float', function() {
    it("should handle float values", function() {
      var query = gRex.gremlin().g.v(1).outE().has("weight", T.gte, "0.5f");
      query.gremlin.script.should.equal("g.v(1).outE().has('weight',T.gte,0.5f)");
    });
  });
});
<|endoftext|>