| | |
| | | success: function (layero, dIndex) { |
| | | form.val('detail', mData || {enabled: 1, layoutType: 2}); |
| | | form.render('select'); |
| | | var detailForm = $(layero).find('#detail'); |
| | | if (!mData) { |
| | | detailForm.attr('data-auto-row-fill', 'true'); |
| | | detailForm.on('input propertychange', '[name="searchRowsCsv"]', function () { |
| | | autoFillDepthRows(detailForm); |
| | | }); |
| | | autoFillDepthRows(detailForm); |
| | | } |
| | | form.on('submit(editSubmit)', function (data) { |
| | | if (!mData) { |
| | | var submitForm = $(data.form); |
| | | data.field.shallowRowsCsv = submitForm.find('[name="shallowRowsCsv"]').val(); |
| | | data.field.deepRowsCsv = submitForm.find('[name="deepRowsCsv"]').val(); |
| | | } |
| | | $.ajax({ |
| | | url: baseUrl + '/basCrnDepthRule/' + (mData ? 'update' : 'add') + '/auth', |
| | | headers: {'token': localStorage.getItem('token')}, |
| | |
| | | }); |
| | | } |
| | | |
| | | form.on('select(crnDepthLayoutType)', function (data) { |
| | | autoFillDepthRows($(data.elem).closest('form')); |
| | | }); |
| | | |
| | | function autoFillDepthRows(formEl) { |
| | | if (!formEl || formEl.length === 0 || formEl.attr('data-auto-row-fill') !== 'true') { |
| | | return; |
| | | } |
| | | var layoutType = $.trim(formEl.find('[name="layoutType"]').val()); |
| | | var searchRowsCsv = $.trim(formEl.find('[name="searchRowsCsv"]').val()); |
| | | if (layoutType === '1') { |
| | | formEl.find('[name="shallowRowsCsv"]').val(searchRowsCsv); |
| | | formEl.find('[name="deepRowsCsv"]').val(''); |
| | | return; |
| | | } |
| | | if (layoutType === '2') { |
| | | var searchRows = parseRows(searchRowsCsv); |
| | | var shallowRows = []; |
| | | var deepRows = []; |
| | | if (searchRows.length > 0) { |
| | | deepRows.push(searchRows[0]); |
| | | } |
| | | if (searchRows.length > 1) { |
| | | deepRows.push(searchRows[searchRows.length - 1]); |
| | | shallowRows.push(searchRows[1]); |
| | | } |
| | | if (searchRows.length > 2) { |
| | | shallowRows.push(searchRows[2]); |
| | | } |
| | | formEl.find('[name="shallowRowsCsv"]').val(shallowRows.join(',')); |
| | | formEl.find('[name="deepRowsCsv"]').val(deepRows.join(',')); |
| | | } |
| | | } |
| | | |
| | | function parseRows(rowsCsv) { |
| | | var rows = []; |
| | | if (!rowsCsv) { |
| | | return rows; |
| | | } |
| | | var normalized = rowsCsv.replace(/,/g, ',') |
| | | .replace(/;/g, ';') |
| | | .replace(/、/g, ',') |
| | | .replace(/\s+/g, ''); |
| | | if (!normalized) { |
| | | return rows; |
| | | } |
| | | $.each(normalized.split(/[,;]/), function (_, segment) { |
| | | if (!segment) { |
| | | return true; |
| | | } |
| | | if (segment.indexOf('-') > -1) { |
| | | addRangeRows(rows, segment); |
| | | return true; |
| | | } |
| | | addRow(rows, segment); |
| | | return true; |
| | | }); |
| | | return rows; |
| | | } |
| | | |
| | | function addRangeRows(rows, segment) { |
| | | var rangeParts = segment.split('-', 2); |
| | | var startRow = parsePositiveInt(rangeParts[0]); |
| | | var endRow = parsePositiveInt(rangeParts[1]); |
| | | if (startRow == null || endRow == null) { |
| | | return; |
| | | } |
| | | var step = startRow <= endRow ? 1 : -1; |
| | | for (var row = startRow; step > 0 ? row <= endRow : row >= endRow; row += step) { |
| | | addUniqueRow(rows, row); |
| | | } |
| | | } |
| | | |
| | | function addRow(rows, rowText) { |
| | | var row = parsePositiveInt(rowText); |
| | | if (row != null) { |
| | | addUniqueRow(rows, row); |
| | | } |
| | | } |
| | | |
| | | function parsePositiveInt(value) { |
| | | var rowText = $.trim(String(value)); |
| | | if (!/^\d+$/.test(rowText)) { |
| | | return null; |
| | | } |
| | | var row = parseInt(rowText, 10); |
| | | return isNaN(row) || row <= 0 ? null : row; |
| | | } |
| | | |
| | | function addUniqueRow(rows, row) { |
| | | if ($.inArray(row, rows) === -1) { |
| | | rows.push(row); |
| | | } |
| | | } |
| | | |
| | | function openTemplateDialog(generate) { |
| | | admin.open({ |
| | | type: 1, |