-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.php
181 lines (160 loc) · 5.02 KB
/
template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<div class="repeater">
<?php echo $field->headline() ?>
<!-- <input class="hidden" type="text" v-model="values" value="<?php echo a::json($field->values()); ?>">
<input class="hidden" type="text" v-model="blueprint" value="<?php echo a::json($field->values()); ?>">
<input class="hidden" type="text" v-model="fields" value="<?php echo a::json($field->values()); ?>">
-->
<div class="repeater-entries">
<div class="structure-entries structure-entry" v-sortable:values="{ animation: 200 }">
<div class="repeater-entry" v-for="(v_index ,value) in values">
<div class="repeater-entry-content text" v-if="editedEntries[v_index]">
<label class="builder-entry-fieldset">{{section}}</label>
<div class="field-content" v-for="(f_index, field) in fields | orderBy 'f_index' 1">
<component
:is="field.type"
:inputlabel="field.label"
:inputvalue.sync="value[f_index]"
:inputoptions="field.options">
</component>
</div>
</div>
<div class="repeater-entry-content text" v-else>
<?php echo $field->entry() ?>
</div>
<div class="repeater-entry-options cf" >
<div class="repeater-btn repeater-edit-button" v-on:click="editEntrie(v_index)" v-if="editedEntries[v_index]"> <?php i('check', 'left') ?></div>
<div class="repeater-btn repeater-edit-button" v-on:click="editEntrie(v_index)" v-else> <?php i('pencil', 'left') ?></div>
<div class="repeater-btn repeater-delete-button" v-on:click="removeEntrie(v_index)" > <?php i('trash-o', 'left') ?></div>
<div class="repeater-btn repeater-order-button" > <?php i('arrows', 'left') ?></div>
</div>
<div class="repeater-entry-separator">
<div class="repeater-btn repeater-add-button fa fa-plus-circle" v-on:click="addEntrie(v_index)"></div>
</div>
</div>
</div>
</div>
</div>
<!-- <pre>{{ editedEntries | json 4}}</pre>
<pre>{{ editedEntries | json 4}}</pre> -->
<!-- <pre>{{ fields | json 4}}</pre>
<pre>{{ values | json 4}}</pre>
<pre>{{ yamlvalues }}</pre>
-->
<?php foreach ($field->fields() as $f => $s ) { $blueprint[$f] = ""; }?>
<!-- component template -->
<template id="input_template_text">
<label>{{inputlabel}}</label><br>
<input class="input" v-model="inputvalue">
<br>
</template>
<template id="input_template_textarea">
<label>{{inputlabel}}</label><br>
<textarea class="input" v-model="inputvalue">{{inputvalue}}</textarea>
</template>
<template id="input_template_radio">
<label>{{inputlabel}}</label><br>
<template v-for="(o_index, option) in inputoptions">
<input type="radio" id="{{o_index}}" value="{{o_index}}" v-model="inputvalue">
<label for="{{o_index}}"> {{option}} </label>
</template>
<br>
</template>
<template id="input_template_select">
<label>{{inputlabel}}</label><br>
<select v-model="inputvalue">
<template v-for="(o_index, option) in inputoptions">
<option v-bind:value="o_index">
{{ option }}
</option>
</template>
</select>
<br>
</template>
<script type="text/javascript">
(function($) {
var vm_<?php echo $field->fieldid(); ?> = new Vue({
el: '.<?php echo $field->fieldid(); ?>',
data: {
message : "Liste des entrées",
values : <?php echo a::json($field->values(), JSON_FORCE_OBJECT); ?>,
blueprint : <?php echo a::json($blueprint); ?>,
fields : <?php echo a::json($field->fields()); ?>,
editedEntries : {},
datatboby : {},
},
created: function () {
},
computed: {
yamlvalues: function () {
return YAML.stringify(this.values);
},
section: function (){
return message
},
records: function (){
return this.values
}
},
// watch:{
// },
methods:{
addEntrie: function (v_index){
newEntrie = <?php echo a::json($blueprint); ?>;
this.values.push(newEntrie);
},
editEntrie: function (v_index){
if (this.editedEntries[v_index]) {
Vue.set(this.editedEntries, v_index, 0);
}else{
Vue.set(this.editedEntries, v_index, 1);
};
console.log(this.editedEntries);
},
removeEntrie: function (index){
this.values.splice(index, 1);
this.editedEntries.splice(index, 1);
},
inputTemplate: function (inputType){
return "cinput" + inputType;
}
},
components:{
text: {
template: '#input_template_text',
props: {
inputvalue: String,
inputlabel: String,
}
},
longtext: {
template: '#input_template_textarea',
props: {
inputvalue: String,
inputlabel: String,
}
},
radio: {
template: '#input_template_radio',
props: {
inputvalue: String,
inputlabel: String,
inputoptions: Object,
}
},
},
directives:{
data: function (value) {
}
},
events: {
sort: function( item, e ) {
editedEntrieItem = this.editedEntries[e.oldIndex];
Vue.set(this.editedEntries, e.oldIndex, this.editedEntries[e.newIndex]);
Vue.set(this.editedEntries, e.newIndex, editedEntrieItem);
// console.log( item );
// console.log( e );
}
}
});
})(jQuery);
</script>