ИНТЕРНЕТ-ПОРТАЛ ДЛЯ ПУБЛИЧНОГО ОБСУЖДЕНИЯ ПРОЕКТОВ И ДЕЙСТВУЮЩИХ НОРМАТИВНЫХ ПРАВОВЫХ АКТОВ ОРГАНОВ ВЛАСТИ САМАРСКОЙ ОБЛАСТИ
Самарская область
‘;
var viewData = [];
var loading = false;
var loaded = false;
$modal.kendoWindow({
title: ‘Порталы других субъектов’,
actions: [‘Close’],
draggable: false,
resizable: false,
visible: false,
modal: true
});
var modal = $modal.data(‘kendoWindow’);
$(window).resize(modal.center.bind(modal));
$btn.click(function (e) {
e.preventDefault();
if (loading) return false;
if (loaded) {
render();
return modal
.center()
.open();
}
var federalRoot = cleanUrl(‘https://regulation.gov.ru’);
var federalApi = ‘/api/regportals’;
modal.bind(‘activate’, function onActivate() {
modal.unbind(‘activate’, onActivate);
var url = federalRoot + federalApi;
download(url, onSuccess, onError, function dataValidation (data) {
return !!data && data.length > 0;
});
}).center().open();
});
function download (url, onSuccess, onError, dataValidation) {
$modal.addClass(‘loading’);
loading = true;
$.ajax({
url: url,
method: ‘GET’,
dataType: ‘json’,
async: true
})
.always(function () {
//$modal.removeClass(‘loading’);
loading = false;
})
.done(function (data) {
if (dataValidation && !dataValidation(data))
return onError();
onSuccess(data);
})
.fail(onError);
}
function onSuccess (data) {
loaded = true;
var parsed = parseViewData(data, function skipItem (rawDataItem) {
return rawDataItem.RegionId === thisRegionId;
});
if (parsed && parsed.length)
viewData = parsed;
render();
}
function onError() {
render();
}
function render () {
if (!viewData.length) {
$modal.html(noDataHtml);
async(function () { $modal.removeClass(‘loading’); });
modal.center();
return;
}
var viewHtml = renderView();
$modal.html(viewHtml);
async(function () { $modal.removeClass(‘loading’); });
modal.center();
}
function parseViewData (rawData, skipRawItem) {
if (!rawData) return [];
var temp = rawData.reduce(function (res, cur) {
if (skipRawItem && skipRawItem(cur)) return res;
var title = cleanTitle(cur.Title);
var url = cleanUrl(cur.Link);
var logoUrl = url + ‘/api/mainlogomini’;
var letter = title[0].toLowerCase();
if (!res[letter])
res[letter] = [];
res[letter].push({
logoUrl: logoUrl,
title: title,
url: url
});
return res;
}, {});
var tempKeys = Object.keys(temp);
if (!temp || !tempKeys.length) return [];
viewData = [];
tempKeys.forEach(function (key) {
viewData.push({
letter: key,
items: temp[key]
});
});
return viewData.sort(function (a, b) {
return a.letter.localeCompare(b.letter);
});
}
function cleanTitle(title) {
if (typeof title !== ‘string’) return ‘-‘;
title = title.trim();
if (!title.length) return ‘-‘;
return title;
}
function cleanUrl (url) {
if (typeof url !== ‘string’) return ‘#’;
return url.trim().replace(//$/, »);
}
function renderView () {
var renderedItems = [];
viewData.forEach(function (item) {
renderedItems.push( renderSection(item) );
});
var itemsAmount = renderedItems.length;
var columnAmount = resolveColumnAmount(itemsAmount);
var itemsPerColumn = Math.round(itemsAmount / columnAmount);
var columns = [];
var dividers = [];
for (var i = 0; i 0) dividers.push( renderDivider(columnAmount, i) );
}
return » + columns.join(») + » + dividers.join(»);
}
function resolveColumnAmount (itemsAmount) {
var width = window.innerWidth;
var lg = 1280;
var md = 480;
var count = 1;
if (width > lg) count = 3;
else if (width > md) count = 2;
if (!itemsAmount || count > itemsAmount)
count = itemsAmount || 1;
return count;
}
function renderColumn (columnAmount, columnHtmlContent) {
var _class = ‘col-xs-‘ + (12 / columnAmount);
return » + columnHtmlContent + »;
}
function renderDivider (columnAmount, columnIndex) {
var _left = (1 / columnAmount * 100 * columnIndex).toFixed(2) + ‘%’;
return »;
}
function async(func) {
setTimeout(func, 0);
}
});
Сообщает Самарская Губернская Дума