<commit_before>/* 
This file is part of Kronekeeper, a web based application for 
recording and managing wiring frame records.

Copyright (C) 2016 NP Broadcast Limited

Kronekeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Kronekeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Kronekeeper.  If not, see <http://www.gnu.org/licenses/>.

*/


require([
	'backbone',
        'jquery',
	'jqueryui'
], function (

) {
        'use strict';


	var Block_Caption_Model = Backbone.Model.extend({

		urlRoot: '/api/block',
		defaults: {
			name: null
		}
	});


	var Block_Caption_View = Backbone.View.extend({

		el: '#block_table_caption',

		events: {
			'input' : 'highlight_change',
			'change' : 'save_caption',
			'keypress' : 'reset_on_escape_key'
		},

		initialize: function() {
			this.listenTo(
				this.model,
				'sync',
				this.model_synced
			);
		},

		highlight_change: function(e) {
			if(e.target.value != this.model.get("name")) {
				e.target.classList.add('change_pending');
			}
			else {
				e.target.classList.remove('change_pending');
			}
		},

		reset_on_escape_key: function(e) {
			if(e.keyCode == 27) {
				e.target.value = this.model.get("name");
				e.target.classList.remove('change_pending');
			}
		},

		save_caption: function(e) {
			var data = {
				name: e.target.value
			};

			this.model.save(data, {
				patch: true,
				success: function(model, response, options) {
					console.log("circuit data saved");
				},
				error: function(model, xhr, options) {
					console.log("ERROR saving circuit data");
				}
			});
		},

		model_synced: function(model, response, options) {
			/* Clear field highlighting and flash green to indicate successful save
			 * Server returns the changed fields to confirm which have been updated
			 */
			if('name' in response) {
				this.$el.children("input.name").removeClass('change_pending');
				this.$el.children("input.name").effect("highlight", {color: "#deffde"}, 1000);
			};
		}

	});



	var Jumper_Model = Backbone.Model.extend({

		defaults: {
			designation: null
		},

		initialize: function(attributes, options) {
			this.circuit = options.circuit;
		},

		urlRoot: '/api/jumper'
	});

	var Jumper_View = Backbone.View.extend({

		tagName: 'td',
		className: 'jumper',
		template: _.template( $('#active_jumper_cell_template').html() ),

		events: {
			'input' : 'highlight_change',
			'change' : 'jumper_change',
			'keypress' : 'reset_on_escape_key'
		},

		initialize: function(attributes) {
			this.listenTo(
				this.model.circuit.collection,
				"jumper_deleted",
				this.jumper_deleted
			);
			this.listenTo(
				this.model,
				'sync',
				this.model_synced
			);
		},
	
		render: function() {
			var json = this.model.toJSON();
			this.$el.html(this.template(json));
			return this;
		},

		highlight_change: function(e) {
			if(e.target.value != this.model.get("designation")) {
				e.target.parentNode.classList.add('change_pending');
			}
			else {
				e.target.parentNode.classList.remove('change_pending');
			}
		},

		reset_on_escape_key: function(e) {
			if(e.keyCode == 27) {
				e.target.value = this.model.get("designation");
				e.target.parentNode.classList.remove('change_pending');
			}
		},

		jumper_change: function(e) {
			if(e.target.value == this.model.get("designation")) {
				/* No change - nothing to do */
				console.log("jumper unchanged");
			}
			else if (e.target.value == '') {
				this.jumper_remove();
			}
			else {
				console.log("jumper changed");
			}
		},

		jumper_remove: function() {
			console.log("jumper removed");
			this.model.destroy();
			this.model.circuit.collection.trigger("jumper_deleted", this.model.get("id"));
		},

		jumper_deleted: function(deleted_jumper_id) {

			/* Responds to another jumper being deleted
			 * If we are the other end of the deleted jumper, we'll have the
			 * same id, but the text input field won't have been cleared.
			 */
			if(deleted_jumper_id == this.model.get("id") && this.$("input").val() != "") {
				this.$("input").val('');
				this.$el.effect("highlight", {}, 1500);
			}
		},

		model_synced: function(model, response, options) {
			/* Clear field highlighting and flash green to indicate successful save
			 * Server returns the changed fields to confirm which have been updated
			 */
			this.$el.removeClass('change_pending');
			this.$el.effect("highlight", {color: "#deffde"}, 900);
		}<commit_msg>Reset jumper model after removal<commit_after>/* 
This file is part of Kronekeeper, a web based application for 
recording and managing wiring frame records.

Copyright (C) 2016 NP Broadcast Limited

Kronekeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Kronekeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Kronekeeper.  If not, see <http://www.gnu.org/licenses/>.

*/


require([
	'backbone',
        'jquery',
	'jqueryui'
], function (

) {
        'use strict';


	var Block_Caption_Model = Backbone.Model.extend({

		urlRoot: '/api/block',
		defaults: {
			name: null
		}
	});


	var Block_Caption_View = Backbone.View.extend({

		el: '#block_table_caption',

		events: {
			'input' : 'highlight_change',
			'change' : 'save_caption',
			'keypress' : 'reset_on_escape_key'
		},

		initialize: function() {
			this.listenTo(
				this.model,
				'sync',
				this.model_synced
			);
		},

		highlight_change: function(e) {
			if(e.target.value != this.model.get("name")) {
				e.target.classList.add('change_pending');
			}
			else {
				e.target.classList.remove('change_pending');
			}
		},

		reset_on_escape_key: function(e) {
			if(e.keyCode == 27) {
				e.target.value = this.model.get("name");
				e.target.classList.remove('change_pending');
			}
		},

		save_caption: function(e) {
			var data = {
				name: e.target.value
			};

			this.model.save(data, {
				patch: true,
				success: function(model, response, options) {
					console.log("circuit data saved");
				},
				error: function(model, xhr, options) {
					console.log("ERROR saving circuit data");
				}
			});
		},

		model_synced: function(model, response, options) {
			/* Clear field highlighting and flash green to indicate successful save
			 * Server returns the changed fields to confirm which have been updated
			 */
			if('name' in response) {
				this.$el.children("input.name").removeClass('change_pending');
				this.$el.children("input.name").effect("highlight", {color: "#deffde"}, 1000);
			};
		}

	});



	var Jumper_Model = Backbone.Model.extend({

		defaults: {
			designation: null
		},

		initialize: function(attributes, options) {
			this.circuit = options.circuit;
		},

		urlRoot: '/api/jumper'
	});

	var Jumper_View = Backbone.View.extend({

		tagName: 'td',
		className: 'jumper',
		template: _.template( $('#active_jumper_cell_template').html() ),

		events: {
			'input' : 'highlight_change',
			'change' : 'jumper_change',
			'keypress' : 'reset_on_escape_key'
		},

		initialize: function(attributes) {
			this.listenTo(
				this.model.circuit.collection,
				"jumper_deleted",
				this.jumper_deleted
			);
			this.listenTo(
				this.model,
				'sync',
				this.model_synced
			);
		},
	
		render: function() {
			var json = this.model.toJSON();
			this.$el.html(this.template(json));
			return this;
		},

		highlight_change: function(e) {
			if(e.target.value != this.model.get("designation")) {
				e.target.parentNode.classList.add('change_pending');
			}
			else {
				e.target.parentNode.classList.remove('change_pending');
			}
		},

		reset_on_escape_key: function(e) {
			if(e.keyCode == 27) {
				e.target.value = this.model.get("designation");
				e.target.parentNode.classList.remove('change_pending');
			}
		},

		jumper_change: function(e) {
			if(e.target.value == this.model.get("designation")) {
				/* No change - nothing to do */
				console.log("jumper unchanged");
			}
			else if (e.target.value == '') {
				this.jumper_remove();
			}
			else {
				console.log("jumper changed");
			}
		},

		jumper_remove: function() {
			console.log("jumper removed");
			this.model.destroy();
			this.model.circuit.collection.trigger("jumper_deleted", this.model.get("id"));
			this.model.set(this.model.defaults);
		},

		jumper_deleted: function(deleted_jumper_id) {

			/* Responds to another jumper being deleted
			 * If we are the other end of the deleted jumper, we'll have the
			 * same id, but the text input field won't have been cleared.
			 */
			if(deleted_jumper_id == this.model.get("id") && this.$("input").val() != "") {
				this.$("input").val('');
				this.$el.effect("highlight", {}, 1500);
				this.model.set(this.model.defaults);
			}
		},

		model_synced: function(model, response, options) {
			/* Clear field highlighting and flash green to indicate successful save
			 * Server returns the changed fields to confirm which have been updated
			 */
			this.$el.removeClass('change_pending');
			this.$el.effect("highlight", {color: "#deffde"}, 900);
		}
{'fraction_non_alphanumeric': 0.14047231270358307, 'fraction_numerical': 0.004071661237785016, 'mean_word_length': 3.378342245989305, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '188204', 'n_tokens_mistral': 3769, 'n_tokens_neox': 3104, 'n_words': 770}