<commit_before>/**
 * Module : Kero Grid Adapter
 * Author : Kvkens(<EMAIL>)
 * Date	  : 2016-08-09 16:17:17
 */

import {BaseAdapter} from '../core/baseAdapter';
import {ValueMixin} from '../core/valueMixin';
import {EnableMixin} from '../core/enableMixin';
import {RequiredMixin} from '../core/requiredMixin';
import {ValidateMixin} from '../core/validateMixin';
import {getJSObject,getFunction} from 'tinper-sparrow/js/util';
import {NumberFormater} from 'tinper-sparrow/js/util/formater';
import {NumberMasker,PercentMasker,CurrencyMasker} from 'tinper-sparrow/js/util/masker';
import {dateRender,dateTimeRender} from 'tinper-sparrow/js/util/dataRender';
import {DataTable} from 'kero/js/dataTable/indexDataTable';
import {stopEvent} from 'tinper-sparrow/js/event';
import {YearAdapter} from './keroa-year';
import {MonthAdapter} from './keroa-month';
import {YearMonthAdapter} from './keroa-yearmonth';
import {TimeAdapter} from './keroa-time';
import {StringAdapter} from './keroa-string';
import {IntegerAdapter} from './keroa-integer';
import {CheckboxAdapter} from './keroa-checkbox';
import {ComboboxAdapter} from './keroa-combo';
import {RadioAdapter} from './keroa-radio';
import {FloatAdapter} from './keroa-float';
import {CurrencyAdapter} from './keroa-currency';
import {DateTimeAdapter} from './keroa-datetimepicker';
import {UrlAdapter} from './keroa-url';
import {PassWordAdapter} from './keroa-password';
import {PercentAdapter} from './keroa-percent';
import {Validate} from 'tinper-neoui/js/neoui-validate';
import {showMessage} from 'tinper-neoui/js/neoui-message';
import {compMgr} from 'tinper-sparrow/js/compMgr';
import {trans} from 'tinper-sparrow/js/util/i18n';
import {core} from 'tinper-sparrow/js/core';
import {addClass} from 'tinper-sparrow/js/dom';

var GridAdapter = BaseAdapter.extend({
	initialize: function(options) {
		// 初始options中包含grid的属性设置，还需要增加dataSource、columns、transMap以及事件处理
		var opt = options['options'] || {},
				viewModel = options['model'];
		var element = typeof options['el'] === 'string' ? document.querySelector(options['el']) : options['el'];
		var app = options['app'];
		this.id = opt['id'];
		options = opt;

		var oThis = this;
		var compDiv = null;
		var comp = null;
		this.dataTable = getJSObject(viewModel, options["data"]);
		this.element = element;
		this.$element = $(element);
		this.editComponentDiv = {};
		this.editComponent = {};
		this.id = options['id'];
		this.gridOptions = options;



		// 在html中将函数类参数进行处理
		this.gridOptions.onBeforeRowSelected = getFunction(viewModel,this.gridOptions.onBeforeRowSelected);
		this.gridOptions.onRowSelected = getFunction(viewModel,this.gridOptions.onRowSelected);
		this.gridOptions.onBeforeRowUnSelected = getFunction(viewModel,this.gridOptions.onBeforeRowUnSelected);
		this.gridOptions.onRowUnSelected = getFunction(viewModel,this.gridOptions.onRowUnSelected);
		this.gridOptions.onBeforeAllRowSelected = getFunction(viewModel,this.gridOptions.onBeforeAllRowSelected);
		this.gridOptions.onAllRowSelected = getFunction(viewModel,this.gridOptions.onAllRowSelected);
		this.gridOptions.onBeforeAllRowUnSelected = getFunction(viewModel,this.gridOptions.onBeforeAllRowUnSelected);
		this.gridOptions.onAllRowUnSelected = getFunction(viewModel,this.gridOptions.onAllRowUnSelected);
		this.gridOptions.onBeforeRowFocus = getFunction(viewModel,this.gridOptions.onBeforeRowFocus);
		this.gridOptions.onRowFocus = getFunction(viewModel,this.gridOptions.onRowFocus);
		this.gridOptions.onBeforeRowUnFocus = getFunction(viewModel,this.gridOptions.onBeforeRowUnFocus);
		this.gridOptions.onRowUnFocus = getFunction(viewModel,this.gridOptions.onRowUnFocus);
		this.gridOptions.onDblClickFun = getFunction(viewModel,this.gridOptions.onDblClickFun);
		this.gridOptions.onValueChange = getFunction(viewModel,this.gridOptions.onValueChange);
		this.gridOptions.onBeforeClickFun = getFunction(viewModel,this.gridOptions.onBeforeClickFun);
		this.gridOptions.onBeforeEditFun = getFunction(viewModel,this.gridOptions.onBeforeEditFun);
		this.gridOptions.onRowHover = getFunction(viewModel,this.gridOptions.onRowHover);
		this.gridOptions.afterCreate = getFunction(viewModel,this.gridOptions.afterCreate);

		/*扩展onBeforeEditFun，如果点击的是单选或者复选的话则不执行原有的编辑处理，直接通过此js进行处理*/
		var customOnBeforeEditFun = this.gridOptions.onBeforeEditFun;
		var newOnBeforeEditFun = function(obj){
			var colIndex = obj.colIndex;
			var $tr = obj.$tr;

			if($($tr.find('td')[colIndex]).find('[type=radio]').length > 0 || $($tr.find('td')[colIndex]).find('[type=checkbox]').length > 0){
				return false;
			}else{
				if(typeof customOnBeforeEditFun == 'function'){
					return customOnBeforeEditFun(obj);
				}else{
					return true;
				}
			}
		}
		this.gridOptions.onBeforeEditFun = newOnBeforeEditFun;
		/*
		 * 处理column参数  item
		 * div子项div存储column信息
		 */
		var columns = [];
		$("div",this.$element).each(function() {
			var ops = $(this).attr('options')
			if(typeof(ops) == "undefined")
				var column = eval("(" + ops+")");
			else
				var column = JSON.parse(ops);
			// 处理精度，以dataTable的精度为准

			/*处理editType*/
			var eType = getFunction(viewModel, column.editType);
			var rType = getFunction(viewModel, column.renderType);
			var afterEType = getFunction(viewModel, column.afterEType);
			var afterRType = getFunction(viewModel, column.afterRType);
			var sumRenderType = getFunction(viewModel, column.sumRenderType);
			column.sumRenderType = sumRenderType;
			var eOptions = {};
			if(column.editOptions){
				if(typeof(column.editOptions) == "undefined")
					var eOptions = eval("(" + column.editOptions +")");
				else
					var eOptions = column.editOptions;
			}
			eOptions.data = options['data']
			eOptions.field = column['field']
			// 默认按照string处理
			if(eType == '')
					eType = 'string';
			if(eType == 'number') // 兼容之前版本
				eType = 'integer';
			if(eType == 'string' || eType == 'integer' || eType == 'checkbox' || eType == 'combo' || eType == 'radio' || eType == 'float' || eType == 'currency' || eType == 'datetime'|| eType == 'year'|| eType == 'month'|| eType == 'yearmonth'|| eType == 'date' || eType == 'time' || eType == 'url' || eType == 'password' || eType == 'percent' || eType == 'phoneNumber' || eType == 'landLine'){
				oThis.createDefaultEdit(eType,eOptions,options,viewModel,column);
				column.editType = function(obj){
					if(oThis.editComponentDiv[column.field] && oThis.editComponentDiv[column.field][0].childNodes.length > 0){
					}else{
						//IE8有问题，所以需要重新创建div,将上面的代码直接拷贝
						oThis.createDefaultEdit(eType,eOptions,options,viewModel,column);
					}
					var comp = oThis.editComponent[column.field];
					var rowId = obj.rowObj['$_#_@_id'];
					var row = oThis.dataTable.getRowByRowId(rowId);
					var index = oThis.dataTable.getRowIndex(row);
					if(comp){
						comp.options.rowIndex = index;
					}
					if (!comp){
						$(obj.element).parent().focus();
						return
					}
					obj.element.innerHTML = '';
					var row = oThis.getDataTableRow(obj.rowObj)
					$(obj.element).append(oThis.editComponentDiv[column.field]);
					

					if(comp.required) {
						$(obj.element).parent().parent().find('.u-grid-edit-mustFlag').show()
					}

					// checkbox 类型  此段逻辑不知道是什么，暂时注释掉
					// if($Div.find('.checkbox').length > 0) {
					// 	$Div.closest('.u-grid-edit-div').css({'position': 'absolute', 'left': '83px'});
					// 	$Div.closest('.u-grid-edit-whole-div').find('.u-grid-edit-label').css({'margin-left': '112px', 'text-align': 'left'})
					// }
					$(obj.element).parent().focus();
					comp.modelValueChange(obj.value);


					// 根据惊道需求增加editype之后的处理,此处只针对grid.js中的默认eType进行处理，非默认通过eType进行处理
					if(typeof afterEType == 'function'){
						afterEType.call(this,obj);
					}
				}
			}else if (typeof eType == 'function'){
				column.editType = eType;
			}



<commit_msg>fix: 创建编辑控件的时候增加editComp存储对应控件<commit_after>/**
 * Module : Kero Grid Adapter
 * Author : Kvkens(yueming<EMAIL>)
 * Date	  : 2016-08-09 16:17:17
 */

import {BaseAdapter} from '../core/baseAdapter';
import {ValueMixin} from '../core/valueMixin';
import {EnableMixin} from '../core/enableMixin';
import {RequiredMixin} from '../core/requiredMixin';
import {ValidateMixin} from '../core/validateMixin';
import {getJSObject,getFunction} from 'tinper-sparrow/js/util';
import {NumberFormater} from 'tinper-sparrow/js/util/formater';
import {NumberMasker,PercentMasker,CurrencyMasker} from 'tinper-sparrow/js/util/masker';
import {dateRender,dateTimeRender} from 'tinper-sparrow/js/util/dataRender';
import {DataTable} from 'kero/js/dataTable/indexDataTable';
import {stopEvent} from 'tinper-sparrow/js/event';
import {YearAdapter} from './keroa-year';
import {MonthAdapter} from './keroa-month';
import {YearMonthAdapter} from './keroa-yearmonth';
import {TimeAdapter} from './keroa-time';
import {StringAdapter} from './keroa-string';
import {IntegerAdapter} from './keroa-integer';
import {CheckboxAdapter} from './keroa-checkbox';
import {ComboboxAdapter} from './keroa-combo';
import {RadioAdapter} from './keroa-radio';
import {FloatAdapter} from './keroa-float';
import {CurrencyAdapter} from './keroa-currency';
import {DateTimeAdapter} from './keroa-datetimepicker';
import {UrlAdapter} from './keroa-url';
import {PassWordAdapter} from './keroa-password';
import {PercentAdapter} from './keroa-percent';
import {Validate} from 'tinper-neoui/js/neoui-validate';
import {showMessage} from 'tinper-neoui/js/neoui-message';
import {compMgr} from 'tinper-sparrow/js/compMgr';
import {trans} from 'tinper-sparrow/js/util/i18n';
import {core} from 'tinper-sparrow/js/core';
import {addClass} from 'tinper-sparrow/js/dom';

var GridAdapter = BaseAdapter.extend({
	initialize: function(options) {
		// 初始options中包含grid的属性设置，还需要增加dataSource、columns、transMap以及事件处理
		var opt = options['options'] || {},
				viewModel = options['model'];
		var element = typeof options['el'] === 'string' ? document.querySelector(options['el']) : options['el'];
		var app = options['app'];
		this.id = opt['id'];
		options = opt;

		var oThis = this;
		var compDiv = null;
		var comp = null;
		this.dataTable = getJSObject(viewModel, options["data"]);
		this.element = element;
		this.$element = $(element);
		this.editComponentDiv = {};
		this.editComponent = {};
		this.id = options['id'];
		this.gridOptions = options;



		// 在html中将函数类参数进行处理
		this.gridOptions.onBeforeRowSelected = getFunction(viewModel,this.gridOptions.onBeforeRowSelected);
		this.gridOptions.onRowSelected = getFunction(viewModel,this.gridOptions.onRowSelected);
		this.gridOptions.onBeforeRowUnSelected = getFunction(viewModel,this.gridOptions.onBeforeRowUnSelected);
		this.gridOptions.onRowUnSelected = getFunction(viewModel,this.gridOptions.onRowUnSelected);
		this.gridOptions.onBeforeAllRowSelected = getFunction(viewModel,this.gridOptions.onBeforeAllRowSelected);
		this.gridOptions.onAllRowSelected = getFunction(viewModel,this.gridOptions.onAllRowSelected);
		this.gridOptions.onBeforeAllRowUnSelected = getFunction(viewModel,this.gridOptions.onBeforeAllRowUnSelected);
		this.gridOptions.onAllRowUnSelected = getFunction(viewModel,this.gridOptions.onAllRowUnSelected);
		this.gridOptions.onBeforeRowFocus = getFunction(viewModel,this.gridOptions.onBeforeRowFocus);
		this.gridOptions.onRowFocus = getFunction(viewModel,this.gridOptions.onRowFocus);
		this.gridOptions.onBeforeRowUnFocus = getFunction(viewModel,this.gridOptions.onBeforeRowUnFocus);
		this.gridOptions.onRowUnFocus = getFunction(viewModel,this.gridOptions.onRowUnFocus);
		this.gridOptions.onDblClickFun = getFunction(viewModel,this.gridOptions.onDblClickFun);
		this.gridOptions.onValueChange = getFunction(viewModel,this.gridOptions.onValueChange);
		this.gridOptions.onBeforeClickFun = getFunction(viewModel,this.gridOptions.onBeforeClickFun);
		this.gridOptions.onBeforeEditFun = getFunction(viewModel,this.gridOptions.onBeforeEditFun);
		this.gridOptions.onRowHover = getFunction(viewModel,this.gridOptions.onRowHover);
		this.gridOptions.afterCreate = getFunction(viewModel,this.gridOptions.afterCreate);

		/*扩展onBeforeEditFun，如果点击的是单选或者复选的话则不执行原有的编辑处理，直接通过此js进行处理*/
		var customOnBeforeEditFun = this.gridOptions.onBeforeEditFun;
		var newOnBeforeEditFun = function(obj){
			var colIndex = obj.colIndex;
			var $tr = obj.$tr;

			if($($tr.find('td')[colIndex]).find('[type=radio]').length > 0 || $($tr.find('td')[colIndex]).find('[type=checkbox]').length > 0){
				return false;
			}else{
				if(typeof customOnBeforeEditFun == 'function'){
					return customOnBeforeEditFun(obj);
				}else{
					return true;
				}
			}
		}
		this.gridOptions.onBeforeEditFun = newOnBeforeEditFun;
		/*
		 * 处理column参数  item
		 * div子项div存储column信息
		 */
		var columns = [];
		$("div",this.$element).each(function() {
			var ops = $(this).attr('options')
			if(typeof(ops) == "undefined")
				var column = eval("(" + ops+")");
			else
				var column = JSON.parse(ops);
			// 处理精度，以dataTable的精度为准

			/*处理editType*/
			var eType = getFunction(viewModel, column.editType);
			var rType = getFunction(viewModel, column.renderType);
			var afterEType = getFunction(viewModel, column.afterEType);
			var afterRType = getFunction(viewModel, column.afterRType);
			var sumRenderType = getFunction(viewModel, column.sumRenderType);
			column.sumRenderType = sumRenderType;
			var eOptions = {};
			if(column.editOptions){
				if(typeof(column.editOptions) == "undefined")
					var eOptions = eval("(" + column.editOptions +")");
				else
					var eOptions = column.editOptions;
			}
			eOptions.data = options['data']
			eOptions.field = column['field']
			// 默认按照string处理
			if(eType == '')
					eType = 'string';
			if(eType == 'number') // 兼容之前版本
				eType = 'integer';
			if(eType == 'string' || eType == 'integer' || eType == 'checkbox' || eType == 'combo' || eType == 'radio' || eType == 'float' || eType == 'currency' || eType == 'datetime'|| eType == 'year'|| eType == 'month'|| eType == 'yearmonth'|| eType == 'date' || eType == 'time' || eType == 'url' || eType == 'password' || eType == 'percent' || eType == 'phoneNumber' || eType == 'landLine'){
				oThis.createDefaultEdit(eType,eOptions,options,viewModel,column);
				column.editType = function(obj){
					if(oThis.editComponentDiv[column.field] && oThis.editComponentDiv[column.field][0].childNodes.length > 0){
					}else{
						//IE8有问题，所以需要重新创建div,将上面的代码直接拷贝
						oThis.createDefaultEdit(eType,eOptions,options,viewModel,column);
					}
					var comp = oThis.editComponent[column.field];
					var rowId = obj.rowObj['$_#_@_id'];
					var row = oThis.dataTable.getRowByRowId(rowId);
					var index = oThis.dataTable.getRowIndex(row);
					if(comp){
						comp.options.rowIndex = index;
					}
					if (!comp){
						$(obj.element).parent().focus();
						return
					}
					obj.element.innerHTML = '';
					var row = oThis.getDataTableRow(obj.rowObj)
					$(obj.element).append(oThis.editComponentDiv[column.field]);
					

					if(comp.required) {
						$(obj.element).parent().parent().find('.u-grid-edit-mustFlag').show()
					}

					// checkbox 类型  此段逻辑不知道是什么，暂时注释掉
					// if($Div.find('.checkbox').length > 0) {
					// 	$Div.closest('.u-grid-edit-div').css({'position': 'absolute', 'left': '83px'});
					// 	$Div.closest('.u-grid-edit-whole-div').find('.u-grid-edit-label').css({'margin-left': '112px', 'text-align': 'left'})
					// }
					$(obj.element).parent().focus();
					comp.modelValueChange(obj.value);
					obj.gridObj.editComp = comp;

					// 根据惊道需求增加editype之后的处理,此处只针对grid.js中的默认eType进行处理，非默认通过eType进行处理
					if(typeof afterEType == 'function'){
						afterEType.call(this,obj);
					}
				}
			}else if (typeof eType == 'function'){
				column.editType = eType;
			}




{'fraction_non_alphanumeric': 0.1561842859873829, 'fraction_numerical': 0.0034410246606767347, 'mean_word_length': 4.7298284045272, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5494203', 'n_tokens_mistral': 6065, 'n_tokens_neox': 5485, 'n_words': 841}