21 |
21 |
*/
|
22 |
22 |
return true;
|
23 |
23 |
}
|
24 |
|
|
25 |
24 |
if ($(row).find('[name$=add_element], [data-dynamic-display-value]').length > 0) {
|
26 |
25 |
/* this has complex widgets, don't use
|
27 |
26 |
* javascript in that case */
|
... | ... | |
34 |
33 |
/* fix up form element name */
|
35 |
34 |
$(new_row).find('[name^=' + prefix + ']').each(
|
36 |
35 |
function() {
|
37 |
|
var cur_name = $(this).attr('name');
|
|
36 |
var $element = $(this);
|
|
37 |
if ($element.attr('type') == 'text') {
|
|
38 |
$element.attr('value', '');
|
|
39 |
}
|
|
40 |
var cur_name = $element.attr('name');
|
38 |
41 |
var pos = cur_name.indexOf('element', prefix.length) + 7; // 7 == len(element)
|
39 |
42 |
var index = cur_name.substring(pos, cur_name.length);
|
40 |
|
var after_pos = Math.max(index.indexOf('-'), index.indexOf('$'));
|
41 |
|
var after = '';
|
42 |
|
if (after_pos != -1) {
|
43 |
|
after = index.substring(after_pos, index.length);
|
44 |
|
}
|
45 |
|
var new_name = cur_name.substring(0, cur_name.length-index.length) +
|
46 |
|
(parseInt(index)+1) + after;
|
47 |
|
$(this).attr('name', new_name);
|
48 |
|
if ($(this).attr('type') == 'text') {
|
49 |
|
$(this).attr('value', '');
|
|
43 |
var element_regex = RegExp(`\\$element(\\d)`, 'g');
|
|
44 |
index = parseInt(index) + 1;
|
|
45 |
$(new_row).html($(new_row).html().replace(element_regex, `$element${index}`));
|
|
46 |
if ($(new_row).attr('data-widget-name')) {
|
|
47 |
$(new_row).attr('data-widget-name', $(new_row).attr('data-widget-name').replace(element_regex, `$element${index}`));
|
50 |
48 |
}
|
51 |
49 |
}
|
52 |
50 |
);
|
... | ... | |
65 |
63 |
return false;
|
66 |
64 |
}
|
67 |
65 |
);
|
|
66 |
|
|
67 |
$('.widget.sortable input').each(function () {
|
|
68 |
$('<span class="handle">⣿</span>').insertBefore($(this));
|
|
69 |
});
|
|
70 |
$('.widget.sortable .content').sortable({
|
|
71 |
handle: '.handle',
|
|
72 |
start: function(event, ui) {
|
|
73 |
$('.widget.StringWidget input', $(this)).each(function () {
|
|
74 |
$(this).attr('value', $(this).val()); // save potential new values before the move
|
|
75 |
});
|
|
76 |
},
|
|
77 |
update : function(event, ui) {
|
|
78 |
$('.widget.StringWidget', $(this)).each(function (index) {
|
|
79 |
var element_regex = RegExp(`\\$element(\\d)`, 'g');
|
|
80 |
$(this).html($(this).html().replace(element_regex, `$element${index}`));
|
|
81 |
$(this).attr('data-widget-name', $(this).attr('data-widget-name').replace(element_regex, `$element${index}`));
|
|
82 |
});
|
|
83 |
},
|
|
84 |
});
|
68 |
85 |
}
|
69 |
86 |
|
70 |
87 |
$(document).ready(prepare_widget_list_elements);
|
71 |
|
-
|