|
1
|
|
|
import printInput from './printInput' |
|
2
|
|
|
import abeEngine from './abeEngine' |
|
3
|
|
|
|
|
4
|
|
|
export default function printBlock (ctx) { |
|
5
|
|
|
var res = '' |
|
6
|
|
|
|
|
7
|
|
|
if(typeof ctx[0].block !== 'undefined' && ctx[0].block !== null && ctx[0].block !== '') { |
|
8
|
|
|
res += `<div class="form-group"> |
|
9
|
|
|
<label class="title">${ctx[0].block}</label> |
|
10
|
|
|
<div class='single-block well well-sm'>` |
|
11
|
|
|
Array.prototype.forEach.call(ctx, (item) => { |
|
12
|
|
|
res += printInput(item) |
|
13
|
|
|
}) |
|
14
|
|
|
res += '</div></div>' |
|
15
|
|
|
}else if(ctx[0].key.indexOf('[') > -1) { |
|
16
|
|
|
var ctxBlock = ctx[0].key.split('[')[0] |
|
17
|
|
|
res += `<div class="form-group"> |
|
18
|
|
|
<div class="list-group" data-block="${ctxBlock}" > |
|
19
|
|
|
<label> |
|
20
|
|
|
${ctxBlock} |
|
21
|
|
|
<button type="button" class="btn btn-success add-block" title="Add new block" > |
|
22
|
|
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> |
|
23
|
|
|
</button> |
|
24
|
|
|
</label>` |
|
25
|
|
|
|
|
26
|
|
|
var arrItem = [] |
|
27
|
|
|
Array.prototype.forEach.call(ctx, (item) => { |
|
28
|
|
|
var index = item.key.match(/[^\[\]]+?(?=\])/) |
|
29
|
|
|
if(typeof arrItem[index] === 'undefined' || arrItem[index] === null) { |
|
30
|
|
|
arrItem[index] = [] |
|
31
|
|
|
} |
|
32
|
|
|
arrItem[index].push(item) |
|
33
|
|
|
}) |
|
34
|
|
|
|
|
35
|
|
|
Array.prototype.forEach.call(Object.keys(arrItem), (i) => { |
|
36
|
|
|
var key = arrItem[i][0].key.split('[')[0] |
|
37
|
|
|
var display = '' |
|
38
|
|
|
if(typeof abeEngine.instance.content[key] === 'undefined' || abeEngine.instance.content[key] === null |
|
39
|
|
|
|| abeEngine.instance.content[key].length === 0) { |
|
40
|
|
|
display = 'style="display: none"' |
|
41
|
|
|
} |
|
42
|
|
|
res += `<div class="list-block" data-block="${key}${i}" ${display}> |
|
43
|
|
|
<button type="button" class="btn btn-info collapsed" data-toggle="collapse" data-target="#${key}${i}" > |
|
44
|
|
|
Section <span class='label-count'>${i}</span> : |
|
45
|
|
|
<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span> |
|
46
|
|
|
</button> |
|
47
|
|
|
<button type="button" class="btn btn-danger remove-block" title="Delete block" > |
|
48
|
|
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> |
|
49
|
|
|
</button> |
|
50
|
|
|
<div id="${key}${i}" class="collapse" > |
|
51
|
|
|
` |
|
52
|
|
|
Array.prototype.forEach.call(arrItem[i], (item) => { |
|
53
|
|
|
res += printInput(item) |
|
54
|
|
|
}) |
|
55
|
|
|
res += '</div></div>' |
|
56
|
|
|
}) |
|
57
|
|
|
|
|
58
|
|
|
res += ` |
|
59
|
|
|
</div> |
|
60
|
|
|
</div>` |
|
61
|
|
|
}else { |
|
62
|
|
|
res += printInput(ctx[0]) |
|
63
|
|
|
} |
|
64
|
|
|
return res |
|
65
|
|
|
} |
|
66
|
|
|
|