<commit_before><link rel="import" href="../../../bower_components/polymer/polymer.html">

<link rel="import" href="../../things-meta-view/things-diy-based-form.html">
<link rel="import" href="things-term-common-grid.html">

<!--
OI Screen - Order List
-->

<dom-module id="things-term-create-lot">
	<template>
		<style>
			:host {
				display: block;
				@apply(--layout-vertical);
				@apply(--layout-flex);
			}
      things-layout-hermes {
        @apply(--layout-flex);
      }			
		</style>

		<things-ajax
			auto
			id="get-order"
			resource-action="find"
			resource-url="work_orders/:id"
			resource-id="[[orderId]]"
			last-response="{{order}}">
		</things-ajax>

		<things-ajax
			id="create-lot"
			resource-action="create"
			resource-url="lot_trxs/CREATE/transaction">
		</things-ajax>

    <things-layout-hermes top-left-content-title="Lot Information" bottom-left-content-title="Comments" right-content-title="Latest Created Lot List">
      <things-diy-based-form
      	left-top
      	id="form"
      	class="flex"
      	resource="[[order]]"
      	resource-id="[[orderId]]"
      	diy-form-name="OI-CreateLot"
      	buttons="[[buttons]]">
      </things-diy-based-form>

	    <things-input-field
	    	left-bottom
	    	id="comments-form"
	    	label="Comments"
	    	value="{{comments}}">
    	</things-input-field>

      <things-term-common-grid
      	right
      	id="common-grid"
      	class="flex"
      	query-fields="[[queryFields]]"
      	sort-fields="[[sortFields]]">
      </things-term-common-grid>
    </things-layout-hermes>
	</template>

	<script>
		Polymer({
			
			is: 'things-term-create-lot',

			properties: {
				/**
				 * 메뉴 정보
				 */
				menuInfo: {
					type: Object
				},

				/**
				 * 라우팅 정보
				 */
				dataRoute: {
					type: String,
					observer: 'dataRouteChanged'
				},

				/**
				 * 오더
				 */
				order: {
					type: Object,
					notify: true
				},
				
				/**
				 * 오더 아이디
				 */
				orderId: {
					type: String
				},

				/**
				 * 생성된 Lot
				 */
				lot: {
					type: Object
				},

				/**
				 * create lot 시에 입력 받은 comment
				 */
				comments: {
					type: String
				},

				/**
				 * common-grid에 넘겨줄 query fields property
				 */
				queryFields: {
					type: Array
				},

				/**
				 * common-grid에 넘겨줄 sort fields property
				 */
				sortFields: {
					type: Array
				},

				/**
				* Buttons 리스트 설정
				*/
				buttons: {
					type: Array,
					value: [ {
						id: 'create-btn',
						text: 'create'
					}, {
						id: 'reset-btn',
						text: 'reset'
					} ]
				}
			},

			listeners: {
				'create-btn-tap' : 'createLot',
				'reset-btn-tap' : 'resetForm',
				'create-lot.things-ajax-response' : '_transactionResponsed',
			},

			behaviors: [
				Things.GlobalBehavior
			],

			observers: [
				'orderChanged(globals.order)',
			],

			/**
			 * order가 변화하면 order와 orderId를 초기화 하고
			 * common-grid의 ajax를 호출 한다.
			 */
			orderChanged: function(order) {
				this.order = order;
				this.orderId = order.id;

				if(this.orderId) {
					this.getLatestLots();
				}
			},

			/**
			 * dataRoute가 변경되었을 경우 
			 *
			 * @param {String} dataRoute
			 */
			dataRouteChanged: function(dataRoute) {
				if(dataRoute == this.menuInfo.routing) {
					if(this.globals) {
						var dataGlobal = this.globals;
						this.orderId = (dataGlobal.order.id) ? dataGlobal.order.id : '';
					}					
				}
			},			

			/**
			 * Create Lot 
			 */
			createLot: function() {
				if(!this.orderId) return;

				var createAjax = this.$['create-lot'];
				createAjax.body = {
					work_order_id : this.orderId,<commit_msg>things-term-create-lot enter event 추가<commit_after><link rel="import" href="../../../bower_components/polymer/polymer.html">

<link rel="import" href="../../things-meta-view/things-diy-based-form.html">
<link rel="import" href="things-term-common-grid.html">

<!--
OI Screen - Order List
-->

<dom-module id="things-term-create-lot">
	<template>
		<style>
			:host {
				display: block;
				@apply(--layout-vertical);
				@apply(--layout-flex);
			}
      things-layout-hermes {
        @apply(--layout-flex);
      }			
		</style>

		<things-ajax
			auto
			id="get-order"
			resource-action="find"
			resource-url="work_orders/:id"
			resource-id="[[orderId]]"
			last-response="{{order}}">
		</things-ajax>

		<things-ajax
			id="create-lot"
			resource-action="create"
			resource-url="lot_trxs/CREATE/transaction">
		</things-ajax>

    <things-layout-hermes top-left-content-title="Lot Information" bottom-left-content-title="Comments" right-content-title="Latest Created Lot List">
      <things-diy-based-form
      	left-top
      	id="form"
      	class="flex"
      	resource="[[order]]"
      	resource-id="[[orderId]]"
      	diy-form-name="OI-CreateLot"
      	buttons="[[buttons]]">
      </things-diy-based-form>

	    <things-input-field
	    	on-keypress="handleKeyPress"
	    	left-bottom
	    	id="comments-form"
	    	label="Comments"
	    	value="{{comments}}">
    	</things-input-field>

      <things-term-common-grid
      	right
      	id="common-grid"
      	class="flex"
      	query-fields="[[queryFields]]"
      	sort-fields="[[sortFields]]">
      </things-term-common-grid>
    </things-layout-hermes>
	</template>

	<script>
		Polymer({
			
			is: 'things-term-create-lot',

			properties: {
				/**
				 * 메뉴 정보
				 */
				menuInfo: {
					type: Object
				},

				/**
				 * 라우팅 정보
				 */
				dataRoute: {
					type: String,
					observer: 'dataRouteChanged'
				},

				/**
				 * 오더
				 */
				order: {
					type: Object,
					notify: true
				},
				
				/**
				 * 오더 아이디
				 */
				orderId: {
					type: String
				},

				/**
				 * 생성된 Lot
				 */
				lot: {
					type: Object
				},

				/**
				 * create lot 시에 입력 받은 comment
				 */
				comments: {
					type: String
				},

				/**
				 * common-grid에 넘겨줄 query fields property
				 */
				queryFields: {
					type: Array
				},

				/**
				 * common-grid에 넘겨줄 sort fields property
				 */
				sortFields: {
					type: Array
				},

				/**
				* Buttons 리스트 설정
				*/
				buttons: {
					type: Array,
					value: [ {
						id: 'create-btn',
						text: 'create'
					}, {
						id: 'reset-btn',
						text: 'reset'
					} ]
				}
			},

			listeners: {
				'create-btn-tap' : 'createLot',
				'reset-btn-tap' : 'resetForm',
				'create-lot.things-ajax-response' : '_transactionResponsed',
			},

			behaviors: [
				Things.GlobalBehavior
			],

			observers: [
				'orderChanged(globals.order)',
			],

			/**
			 * order가 변화하면 order와 orderId를 초기화 하고
			 * common-grid의 ajax를 호출 한다.
			 */
			orderChanged: function(order) {
				this.order = order;
				this.orderId = order.id;

				if(this.orderId) {
					this.getLatestLots();
				}
			},

			/**
			 * dataRoute가 변경되었을 경우 
			 *
			 * @param {String} dataRoute
			 */
			dataRouteChanged: function(dataRoute) {
				if(dataRoute == this.menuInfo.routing) {
					if(this.globals) {
						var dataGlobal = this.globals;
						this.orderId = (dataGlobal.order.id) ? dataGlobal.order.id : '';
					}					
				}
			},			

			/**
			 * key event - form submits when enter key is monitored
			 */
			handleKeyPress: function(event) {
				var code = event.keyCode;
				if(code == 13) {
					this.createLot();
				}
			},

			/**
			 * Create Lot 
			 */
			createLot: function() {
				if(!this.orderId) return;

				var createAjax = this.$['create-lot'];
				createAjax.body = {
					work_order_id : this.orderId,
{'fraction_non_alphanumeric': 0.16488079292794, 'fraction_numerical': 0.0002678810608090008, 'mean_word_length': 1.9607454401268833, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '1370322', 'n_tokens_mistral': 3596, 'n_tokens_neox': 2736, 'n_words': 422}