commit cf129c8ece0e1788c64ea398c1d33b2cc370b535
parent 5ddb2483136de85148273a62248ea84045258be7
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Mon, 20 Mar 2017 00:20:14 +0300
[print] show number of pages
Diffstat:
3 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/lib/leaflet.control.printPages/control.css b/src/lib/leaflet.control.printPages/control.css
@@ -6,6 +6,11 @@
width: 3.2em;
}
+.control-print-pages .pages-num {
+ vertical-align: middle;
+ margin-left: 1.5em;
+}
+
.control-print-pages .page-size {
width: 2.1em;
}
@@ -21,10 +26,12 @@
.button-add-page-horiz {
background-image: url("images/add-page-horiz.png");
margin-left: 2mm;
+ vertical-align: middle;
}
.button-add-page-vert {
background-image: url("images/add-page-vert.png");
+ vertical-align: middle;
}
.button-remove-pages {
diff --git a/src/lib/leaflet.control.printPages/control.js b/src/lib/leaflet.control.printPages/control.js
@@ -77,6 +77,8 @@ L.Control.PrintPages = L.Control.extend({
this.scale.subscribe(this.onPageSizeChanged, this);
this.resolution.subscribe(this.onPageSizeChanged, this);
this.pageSizeDescription = ko.pureComputed(this._displayPageSize, this);
+ this.pagesNum = ko.observable(0);
+ this.pagesNumLabel = ko.pureComputed(this._pagesNumLabel, this);
//hash state notifications
this.scale.subscribe(this.notifyChange, this);
@@ -120,6 +122,7 @@ L.Control.PrintPages = L.Control.extend({
page._rotated = isLandsacape;
page.addTo(this._map);
this.pages.push(page);
+ this.pagesNum(this.pages.length);
let cm = new Contextmenu(this.makePageContexmenuItems.bind(this, page));
page.on('contextmenu', cm.show, cm);
page.on('click', this.rotatePage.bind(this, page));
@@ -141,6 +144,7 @@ L.Control.PrintPages = L.Control.extend({
removePage: function(page) {
let i = this.pages.indexOf(page);
this.pages.splice(i, 1);
+ this.pagesNum(this.pages.length);
this._map.removeLayer(page);
for (; i < this.pages.length; i++) {
this.pages[i].setLabel((i + 1).toString());
@@ -152,6 +156,7 @@ L.Control.PrintPages = L.Control.extend({
removePages: function() {
this.pages.forEach((page) => page.removeFrom(this._map));
this.pages = [];
+ this.pagesNum(this.pages.length);
this.notifyChange();
this.updateFormZooms();
},
@@ -352,6 +357,21 @@ L.Control.PrintPages = L.Control.extend({
return !!this.pages.length
},
+ _pagesNumLabel: function() {
+ const n = this.pagesNum();
+ let label = '';
+ if (n) {
+ label += n;
+ } else {
+ label = 'No';
+ }
+ label += ' page';
+ if (n === 0 || n > 1) {
+ label += 's';
+ }
+ return label;
+ },
+
serializeState: function() {
const pages = this.pages;
let state = null;
diff --git a/src/lib/leaflet.control.printPages/form.html b/src/lib/leaflet.control.printPages/form.html
@@ -8,6 +8,7 @@
data-bind="click: addPortraitPage"></a>
<a title="Add page in landscape orientation" class="button-add-page-horiz image-button"
data-bind="click: addLandscapePage"></a>
+ <span class="pages-num" data-bind="text: pagesNumLabel"></span>
<a title="Remove all pages" class="button-remove-pages image-button"
data-bind="click: removePages"></a>
</td></tr>