@@ -37,7 +37,9 @@ $(function() {
37
37
38
38
$ ( '[data-toggle="tooltip"]' ) . tooltip ( ) ;
39
39
const stringPattern = / ^ ( \w + \s ) * \w + $ / ;
40
- const numberPattern = / ^ [ 0 - 9 ] { 1 , } $ / ;
40
+ const numberPattern = / ^ \d * \. ? \d * $ / ;
41
+
42
+ let hasError = false ;
41
43
42
44
$ ( 'form#detail' ) . submit ( e => {
43
45
e . preventDefault ( ) ;
@@ -54,10 +56,10 @@ $(function() {
54
56
if ( stringPattern . test ( val . trim ( ) ) ) {
55
57
$ ( parent ) . removeClass ( 'has-error' ) ;
56
58
nextElement . innerText = '' ;
57
- console . log ( 'error' ) ;
58
59
} else {
59
60
nextElement . innerText = $ ( item ) . attr ( 'alt' ) ;
60
61
$ ( parent ) . addClass ( 'has-error' ) ;
62
+ hasError = true ;
61
63
}
62
64
} ) ;
63
65
@@ -66,7 +68,7 @@ $(function() {
66
68
inputNumber . forEach ( item => {
67
69
const nextElement = item . nextElementSibling ;
68
70
const parent = item . parentElement ;
69
- const itemId = `${ $ ( inputText ) . attr ( 'id' ) } ` ;
71
+ const itemId = `${ $ ( inputNumber ) . attr ( 'id' ) } ` ;
70
72
71
73
const val = document . getElementById ( itemId ) . value ;
72
74
@@ -76,12 +78,95 @@ $(function() {
76
78
} else {
77
79
nextElement . innerText = $ ( item ) . attr ( 'alt' ) ;
78
80
$ ( parent ) . addClass ( 'has-error' ) ;
81
+ hasError = true ;
79
82
}
80
83
} ) ;
84
+
85
+ if ( ! hasError ) {
86
+ addProjectDetail ( ) ;
87
+ }
81
88
} ) ;
82
89
90
+ let currentRowIndex = - 1 ;
91
+
92
+ const tableProjectDetail = this . querySelector ( '#table-project-detail' ) ;
93
+
94
+ tableProjectDetail . addEventListener ( 'click' , e => {
95
+ parentTag = $ ( e . target ) . parent ( ) ;
96
+
97
+ console . log ( parentTag ) ;
98
+
99
+ if (
100
+ parentTag . prop ( 'tagName' ) == 'TR' &&
101
+ ! parentTag . hasClass ( 'tr-heading' )
102
+ ) {
103
+ const lastRow = `#table-project-detail tr[alt=${ currentRowIndex } ]` ;
104
+ console . log ( lastRow ) ;
105
+
106
+ $ ( lastRow ) . removeClass ( 'selected-row' ) ;
107
+
108
+ $ ( tableProjectDetail ) ;
109
+
110
+ currentRowIndex = $ ( e . target )
111
+ . parent ( )
112
+ . attr ( 'alt' ) ;
113
+ $ ( e . target )
114
+ . parent ( )
115
+ . addClass ( 'selected-row' ) ;
116
+ }
117
+ } ) ;
118
+
119
+ $ ( '#table-project-detail' ) . click ( e => { } ) ;
120
+
83
121
$ ( '.select2' ) . select2 ( {
84
122
theme : 'classic' ,
85
123
width : 'resolve' ,
86
124
} ) ;
125
+
126
+ /* Add property detail to project */
87
127
} ) ;
128
+
129
+ function addProjectDetail ( ) {
130
+ const type = document . querySelector ( '#propertyType' ) ;
131
+ const code = document . querySelector ( '#code' ) ;
132
+ const description = document . querySelector ( '#description' ) ;
133
+ const no = document . querySelector ( '#no' ) ;
134
+ const st = document . querySelector ( '#st' ) ;
135
+ const propAttribute = $ ( '#attribute' ) . select2 ( 'data' ) [ 0 ] . text ;
136
+ const cost = document . querySelector ( '#cost' ) ;
137
+ const price = document . querySelector ( '#price' ) ;
138
+ const free = document . querySelector ( '#free' ) ;
139
+ const publish = document . querySelector ( '#publish' ) ;
140
+
141
+ const stType = document . querySelector (
142
+ `#propertyType option[value="${ type . value } "]`
143
+ ) . innerText ;
144
+ const stPublish = document . querySelector (
145
+ `#publish option[value="${ type . value } "]`
146
+ ) . innerText ;
147
+
148
+ const rowCount = $ ( '#table-project-detail td' ) . closest ( 'tr' ) . length + 1 ;
149
+
150
+ const row = `<tr class="detail-row" alt=${ rowCount - 1 } ><td>${ rowCount } </td>
151
+ <td><div alt='${ type . value } '></div>${ stType } </td>
152
+ <td>${ code . value } </td>
153
+ <td>${ description . value } </td>
154
+ <td>${ no . value } </td>
155
+ <td>${ st . value } </td>
156
+ <td>${ propAttribute } </td>
157
+ <td>${ cost . value } </td>
158
+ <td>${ price . value } </td>
159
+ <td>${ free . value } </td>
160
+ <td><div alt='${ publish . value } '></div>${ stPublish } </td>
161
+ ` ;
162
+
163
+ $ ( '#project-detail-body' ) . append ( row ) ;
164
+
165
+ const tCost = Number ( $ ( '#tCost' ) . text ( ) ) + Number ( cost . value ) ;
166
+
167
+ const tPrice = Number ( $ ( '#tPrice' ) . text ( ) ) + Number ( price . value ) ;
168
+
169
+ $ ( '#tCount' ) . text ( rowCount ) ;
170
+ $ ( '#tCost' ) . text ( tCost ) ;
171
+ $ ( '#tPrice' ) . text ( tPrice ) ;
172
+ }
0 commit comments