1
- function nodesEvent ( nodes , event , func ) {
1
+ function nodesBindEvent ( nodes , event , func ) {
2
2
for ( let element of nodes ) {
3
3
element . addEventListener ( event , func ) ;
4
4
}
@@ -21,7 +21,7 @@ function componentSelect(name,selected,options) {
21
21
}
22
22
function addVal ( ) {
23
23
var val = '' ;
24
- $ ( '#' + name + '-select' ) . children ( ) . each ( function ( i , n ) {
24
+ document . getElementById ( name + '-select' ) . childNodes . forEach ( function ( n ) {
25
25
val += parseInt ( n . getAttribute ( 'data-id' ) ) + "," ;
26
26
} ) ;
27
27
val = val . replace ( / , $ / g, '' ) ;
@@ -52,8 +52,8 @@ function componentSelect(name,selected,options) {
52
52
'</div>' +
53
53
'</div>' ;
54
54
document . getElementById ( name ) . innerHTML = html ;
55
- nodesEvent ( document . getElementById ( name + '-select' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagCancel ) ;
56
- nodesEvent ( document . getElementById ( name + '-content' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagSelect ) ;
55
+ nodesBindEvent ( document . getElementById ( name + '-select' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagCancel ) ;
56
+ nodesBindEvent ( document . getElementById ( name + '-content' ) . getElementsByClassName ( "v-tag" ) , 'click' , tagSelect ) ;
57
57
document . getElementById ( name + '-search' ) . addEventListener ( 'input' , function ( ) {
58
58
var search = this . value ;
59
59
if ( search == '' ) {
@@ -68,12 +68,11 @@ function componentSelect(name,selected,options) {
68
68
} ) ;
69
69
}
70
70
71
-
72
71
function componentJsonTable ( name , columns , data ) {
73
72
function selectTd ( td , type , value , column ) {
74
73
switch ( type ) {
75
74
case 'text' :
76
- td . innerText = value ;
75
+ td . innerHTML = '<p style="text-overflow: ellipsis;overflow: hidden;display: block;white-space: nowrap;">' + value + '</p>' ;
77
76
break ;
78
77
case 'input' :
79
78
let input = document . createElement ( 'input' ) ;
@@ -92,6 +91,9 @@ function componentJsonTable(name,columns,data) {
92
91
} ) ;
93
92
td . appendChild ( input ) ;
94
93
break ;
94
+ default :
95
+ td . innerHTML = '<p style="text-overflow: ellipsis;overflow: hidden;display: block;white-space: nowrap;">' + value + '</p>' ;
96
+ break ;
95
97
}
96
98
}
97
99
function deleteButton ( td ) {
@@ -121,6 +123,9 @@ function componentJsonTable(name,columns,data) {
121
123
var head = '<tr style="display:table;width:100%;table-layout:fixed;">' ;
122
124
var foot = head ;
123
125
for ( let column in columns ) {
126
+ if ( columns [ column ] . type == 'hidden' ) {
127
+ continue ;
128
+ }
124
129
if ( columns [ column ] . style ) {
125
130
head += '<th style="' + columns [ column ] . style + '">' + columns [ column ] . name + '</th>' ;
126
131
foot += '<th style="' + columns [ column ] . style + '">' +
@@ -145,6 +150,12 @@ function componentJsonTable(name,columns,data) {
145
150
let flag = false ;
146
151
let record = { } ;
147
152
for ( let column in columns ) {
153
+ if ( columns [ column ] . type == 'hidden' ) {
154
+ if ( value [ column ] ) {
155
+ record [ column ] = value [ column ] ;
156
+ }
157
+ continue ;
158
+ }
148
159
let td = document . createElement ( 'td' ) ;
149
160
if ( value [ column ] ) {
150
161
record [ column ] = value [ column ] ;
@@ -211,3 +222,154 @@ function componentJsonTable(name,columns,data) {
211
222
} ) ;
212
223
dom . getElementsByClassName ( 'JsonTableInsert' ) [ 0 ] . appendChild ( i ) ;
213
224
}
225
+
226
+ let componentCommonBlock = {
227
+ _loadingSvg :"<svg version=\"1.1\" style='width: 100%;height:100px' xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n" +
228
+ " width=\"40px\" height=\"40px\" viewBox=\"0 0 40 40\" enable-background=\"new 0 0 40 40\" xml:space=\"preserve\">\n" +
229
+ " <path opacity=\"0.2\" fill=\"#000\" d=\"M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,14.946,14.946\n" +
230
+ " s14.946-6.691,14.946-14.946C35.146,11.861,28.455,5.169,20.201,5.169z M20.201,31.749c-6.425,0-11.634-5.208-11.634-11.634\n" +
231
+ " c0-6.425,5.209-11.634,11.634-11.634c6.425,0,11.633,5.209,11.633,11.634C31.834,26.541,26.626,31.749,20.201,31.749z\"/>\n" +
232
+ " <path fill=\"#000\" d=\"M26.013,10.047l1.654-2.866c-2.198-1.272-4.743-2.012-7.466-2.012h0v3.312h0\n" +
233
+ " C22.32,8.481,24.301,9.057,26.013,10.047z\">\n" +
234
+ " <animateTransform attributeType=\"xml\"\n" +
235
+ " attributeName=\"transform\"\n" +
236
+ " type=\"rotate\"\n" +
237
+ " from=\"0 20 20\"\n" +
238
+ " to=\"360 20 20\"\n" +
239
+ " dur=\"0.5s\"\n" +
240
+ " repeatCount=\"indefinite\"/>\n" +
241
+ " </path>\n" +
242
+ " </svg>" ,
243
+ _nodesBindEvent :function ( nodes , event , func ) {
244
+ for ( let element of nodes ) {
245
+ element . addEventListener ( event , func ) ;
246
+ }
247
+ }
248
+ } ;
249
+
250
+ let componentEditForm = {
251
+ url : '' ,
252
+ apply :function ( name , url ) {
253
+ this . url = url ;
254
+ componentCommonBlock . _nodesBindEvent ( document . getElementsByClassName ( name ) , 'click' , this . make ) ;
255
+ } ,
256
+ make :function ( ) {
257
+ componentEditForm . _DOM = this ;
258
+ componentEditForm . _modalBodyNode = null ;
259
+ componentEditForm . _boxNode = null ;
260
+ componentEditForm . _boxBodyNode = null ;
261
+ componentEditForm . _tableNode = null ;
262
+ componentEditForm . _loadingNode = null ;
263
+ componentEditForm . _createModal ( ) ;
264
+ let url = componentEditForm . url + '/' + this . getAttribute ( 'data-id' ) + '/edit' ;
265
+ componentEditForm . _createBox ( url ) ;
266
+ } ,
267
+ _DOM :null ,
268
+ _modalBodyNode :null ,
269
+ _boxNode :null ,
270
+ _boxBodyNode : null ,
271
+ _tableNode : null ,
272
+ _loadingNode :null ,
273
+ _loading :function ( remove = false ) {
274
+ if ( remove ) {
275
+ this . _modalBodyNode . removeChild ( this . _loadingNode ) ;
276
+ this . _loadingNode = null ;
277
+ return ;
278
+ }
279
+ if ( this . _loadingNode instanceof HTMLElement ) {
280
+ return ;
281
+ }
282
+ let svg = componentCommonBlock . _loadingSvg ;
283
+ let loading = document . createElement ( 'div' ) ;
284
+ loading . style = 'width: 100%;height: 100px;' ;
285
+ loading . innerHTML = svg ;
286
+ this . _loadingNode = loading ;
287
+ let firstChild = this . _modalBodyNode . childNodes [ 0 ] ;
288
+ if ( firstChild instanceof HTMLElement ) {
289
+ this . _modalBodyNode . insertBefore ( loading , firstChild ) ;
290
+ return ;
291
+ }
292
+ this . _modalBodyNode . append ( loading ) ;
293
+ } ,
294
+ _request : function ( url ) {
295
+ //loading
296
+ var thisObj = this ;
297
+ this . _loading ( ) ;
298
+ var xhr = new XMLHttpRequest ( ) ;
299
+ xhr . open ( "GET" , url , true ) ;
300
+ xhr . timeout = 3000 ;
301
+ xhr . responseType = "text" ;
302
+ var token = document . querySelector ( 'meta[name="csrf-token"]' ) . getAttribute ( 'content' ) ;
303
+ xhr . setRequestHeader ( "Content-type" , "application/text;charset=UTF-8" ) ;
304
+ xhr . setRequestHeader ( "X-CSRF-TOKEN" , token ) ;
305
+ xhr . send ( null ) ;
306
+ xhr . onreadystatechange = function ( ) {
307
+ if ( xhr . readyState == xhr . DONE && xhr . status == 200 ) {
308
+ thisObj . _loading ( true ) ;
309
+ var response = xhr . response ;
310
+ //thisObj._modalBodyNode.append(response);
311
+ $ ( '.modal-content' ) . append ( response )
312
+ }
313
+ } ;
314
+ xhr . onerror = function ( e ) {
315
+ console . log ( e )
316
+ } ;
317
+ } ,
318
+ _createBox : function ( url ) {
319
+ let box = document . createElement ( "div" ) ;
320
+ box . className = "box grid-box" ;
321
+ let box_body = document . createElement ( "div" ) ;
322
+ box_body . className = "box-body table-responsive no-padding" ;
323
+
324
+ box . append ( box_body ) ;
325
+ this . _boxNode = box ;
326
+ this . _boxBodyNode = box_body ;
327
+ this . _request ( url ) ;
328
+ return ;
329
+ } ,
330
+ _createModal : function ( ) {
331
+ //modal
332
+ let modal = document . createElement ( "div" ) ;
333
+ modal . setAttribute ( 'class' , 'modal grid-modal in' ) ;
334
+ modal . setAttribute ( 'tabindex' , '-1' ) ;
335
+ modal . setAttribute ( 'role' , 'dialog' ) ;
336
+ modal . style = 'display: block;' ;
337
+
338
+ //modal_dialog
339
+ let mod_dialog = document . createElement ( "div" ) ;
340
+ mod_dialog . setAttribute ( 'class' , 'modal-dialog modal-lg' ) ;
341
+ mod_dialog . setAttribute ( 'role' , 'document' ) ;
342
+
343
+ //modal_content
344
+ let modal_content = document . createElement ( "div" ) ;
345
+ modal_content . className = "modal-content" ;
346
+
347
+ //header
348
+ let modal_header = document . createElement ( "div" ) ;
349
+ modal_header . className = 'modal-header' ;
350
+ modal_header . style = 'background-color:#ffffff;padding: 3px;display: flex;justify-content:flex-end;' ;
351
+ //X
352
+ let X = document . createElement ( 'i' ) ;
353
+ X . setAttribute ( 'class' , 'fa fa-close' ) ;
354
+ X . setAttribute ( 'style' , 'cursor: pointer' ) ;
355
+
356
+ X . addEventListener ( 'click' , function ( ) {
357
+ document . body . removeChild ( modal ) ;
358
+ } ) ;
359
+
360
+ let modal_body = document . createElement ( 'div' ) ;
361
+ modal_body . className = "modal-body" ;
362
+ modal_body . style = 'background-color:#f4f4f4;padding:0;' ;
363
+ this . _modalBodyNode = modal_body ;
364
+ this . _loading ( ) ;
365
+ //create modal
366
+ modal_header . append ( X ) ;
367
+ modal_content . append ( modal_header ) ;
368
+ modal_content . append ( modal_body ) ;
369
+ mod_dialog . append ( modal_content ) ;
370
+ modal . appendChild ( mod_dialog ) ;
371
+ document . body . append ( modal ) ;
372
+ }
373
+ } ;
374
+
375
+
0 commit comments