Browse Source

publish muk_web_utils - 12.0

pull/68/head
MuK IT GmbH 6 years ago
parent
commit
42e3f5cffe
  1. 2
      muk_web_utils/__manifest__.py
  2. 33
      muk_web_utils/static/src/js/core/utils.js

2
muk_web_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Web Utils", "name": "MuK Web Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": "12.0.2.8.16",
"version": "12.0.2.8.17",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",

33
muk_web_utils/static/src/js/core/utils.js

@ -41,9 +41,42 @@ var parseText2Html= function(text) {
.replace(/[\n\r]/g,'<br/>'); .replace(/[\n\r]/g,'<br/>');
} }
var closedRange = function(start, end) {
return _.range(start, end + 1);
}
var partitionPageList = function(pages, page, size) {
if (!size || size < 5) {
throw "The size must be at least 5 to partition the list.";
}
var sideSize = size < 9 ? 1 : 2;
var leftSize = (size - sideSize * 2 - 3) >> 1;
var rightSize = (size - sideSize * 2 - 2) >> 1;
if (pages <= size) {
return closedRange(1, pages);
}
if (page <= size - sideSize - 1 - rightSize) {
return closedRange(1, size - sideSize - 1)
.concat([false])
.concat(closedRange(pages - sideSize + 1, pages));
}
if (page >= pages - sideSize - 1 - rightSize) {
return closedRange(1, sideSize)
.concat([false])
.concat(closedRange(pages - sideSize - 1 - rightSize - leftSize, pages));
}
return closedRange(1, sideSize)
.concat([false])
.concat(closedRange(page - leftSize, page + rightSize))
.concat([false])
.concat(closedRange(pages - sideSize + 1, pages));
}
return { return {
isUrl: isUrl, isUrl: isUrl,
closedRange: closedRange,
parseText2Html: parseText2Html, parseText2Html: parseText2Html,
partitionPageList: partitionPageList,
}; };
}); });
Loading…
Cancel
Save