import * as userSettings from './settings/userSettings';
import globalize from './globalize';
export function getSavedQueryKey(modifier) {
return window.location.href.split('#')[0] + (modifier || '');
}
export function loadSavedQueryValues(key, query) {
let values = userSettings.get(key);
if (values) {
values = JSON.parse(values);
return Object.assign(query, values);
}
return query;
}
export function saveQueryValues(key, query) {
const values = {};
if (query.SortBy) {
values.SortBy = query.SortBy;
}
if (query.SortOrder) {
values.SortOrder = query.SortOrder;
}
userSettings.set(key, JSON.stringify(values));
}
export function saveViewSetting (key, value) {
userSettings.set(key + '-_view', value);
}
export function getSavedView (key) {
return userSettings.get(key + '-_view');
}
export function showLayoutMenu (button, currentLayout, views) {
let dispatchEvent = true;
if (!views) {
dispatchEvent = false;
views = button.getAttribute('data-layouts');
views = views ? views.split(',') : ['List', 'Poster', 'PosterCard', 'Thumb', 'ThumbCard'];
}
const menuItems = views.map(function (v) {
return {
name: globalize.translate(v),
id: v,
selected: currentLayout == v
};
});
import('../components/actionSheet/actionSheet').then(({default: actionsheet}) => {
actionsheet.show({
items: menuItems,
positionTo: button,
callback: function (id) {
button.dispatchEvent(new CustomEvent('layoutchange', {
detail: {
viewStyle: id
},
bubbles: true,
cancelable: false
}));
if (!dispatchEvent && window.$) {
$(button).trigger('layoutchange', [id]);
}
}
});
});
}
export function getQueryPagingHtml (options) {
const startIndex = options.startIndex;
const limit = options.limit;
const totalRecordCount = options.totalRecordCount;
let html = '';
const recordsEnd = Math.min(startIndex + limit, totalRecordCount);
const showControls = limit < totalRecordCount;
html += '
';
if (showControls) {
html += '';
html += globalize.translate('ListPaging', totalRecordCount ? startIndex + 1 : 0, recordsEnd, totalRecordCount);
html += '';
}
if (showControls || options.viewButton || options.filterButton || options.sortButton || options.addLayoutButton) {
html += '
';
if (showControls) {
html += '';
html += '';
}
if (options.addLayoutButton) {
html += '';
}
if (options.sortButton) {
html += '';
}
if (options.filterButton) {
html += '';
}
html += '