Uprava duplikace elementu
This commit is contained in:
@@ -1,19 +1,9 @@
|
||||
$ (document).on ('click', '.js-add-program', function () {
|
||||
var templateSelector = $ (this).data ('template') + ":last";
|
||||
var $templateContainer = $ ($ (this).data ('template-container'));
|
||||
var $template = $templateContainer.find (templateSelector);
|
||||
var $template= $($(this).data('template'));
|
||||
|
||||
var $copy = $template.clone ().removeClass ('template');
|
||||
$template.clone().appendTo($template.parent());
|
||||
|
||||
var itemsCount = $ ('.template-container__item').length;
|
||||
$copy.find ('input').each (function () {
|
||||
var name = $ (this).attr ('name');
|
||||
|
||||
if (typeof name !== 'undefined')
|
||||
$ (this).attr ('name', name.replace (/\[[0-9]+\]/g, '[' + itemsCount + ']'));
|
||||
});
|
||||
|
||||
$copy.removeAttr ('hidden').appendTo ($templateContainer);
|
||||
renameInputs();
|
||||
|
||||
$ ('.select-time').datetimepicker ({
|
||||
format: 'LT',
|
||||
@@ -28,7 +18,6 @@ function renameInputs() {
|
||||
|
||||
items.each (function () {
|
||||
var $rows = $ (this).find ('input');
|
||||
|
||||
$rows.each (function () {
|
||||
var name = $ (this).attr ('name');
|
||||
$ (this).attr ('name', name.replace (/\[[0-9]+\]/g, '[' + i + ']'));
|
||||
@@ -51,14 +40,15 @@ function sortEvents($container, $templates) {
|
||||
|
||||
var elements = $templates.get ();
|
||||
|
||||
elements.sort (function (a, b) {
|
||||
$container.children().remove();
|
||||
|
||||
console.log (a);
|
||||
elements.sort (function (a, b) {
|
||||
// console.log (a);
|
||||
|
||||
var timeA = $ (a).find ('.select-time').val ();
|
||||
var timeB = $ (b).find ('.select-time').val ();
|
||||
|
||||
return timeA > timeB;
|
||||
return timeA > timeB ? 1 : -1;
|
||||
});
|
||||
|
||||
$container.append (elements);
|
||||
@@ -73,6 +63,7 @@ function checkEvents($container, $templates) {
|
||||
var time = $ (this).find ('.select-time').val ();
|
||||
|
||||
if (time < lastTime) {
|
||||
// console.log ($(this).find('.select-time').attr('name')+": "+time + " < " + lastTime);
|
||||
orderCorrect = false;
|
||||
}
|
||||
lastTime = time;
|
||||
@@ -89,7 +80,7 @@ $ (document).ready (function () {
|
||||
|
||||
setInterval (function () {
|
||||
var $templateContainer = $ ('.template-container');
|
||||
var $templates = $ ('.template');
|
||||
var $templates = $ ('.program-template');
|
||||
|
||||
checkEvents ($templateContainer, $templates);
|
||||
}, 1000);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@import "timeline";
|
||||
@import "gallery";
|
||||
|
||||
.template:first-child {
|
||||
.program-template:first-child, .template:first-child {
|
||||
.js-remove-program {
|
||||
display: none;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user