From 645612fd16b75c9d973044217c6022d57c1f44ed Mon Sep 17 00:00:00 2001 From: Alexander Yuzhin Date: Fri, 15 Feb 2019 14:12:49 +0300 Subject: [PATCH] [DE Mobile] Added page margins setting. --- .../mobile/app/controller/Settings.js | 96 ++++++++++++++++++- .../mobile/app/template/Settings.template | 65 +++++++++++++ .../mobile/app/view/Settings.js | 7 +- apps/documenteditor/mobile/locale/en.json | 5 + 4 files changed, 169 insertions(+), 4 deletions(-) diff --git a/apps/documenteditor/mobile/app/controller/Settings.js b/apps/documenteditor/mobile/app/controller/Settings.js index 75fe52c80..7b58fd0c7 100644 --- a/apps/documenteditor/mobile/app/controller/Settings.js +++ b/apps/documenteditor/mobile/app/controller/Settings.js @@ -81,6 +81,14 @@ define([ ], _licInfo; + var mm2Cm = function(mm) { + return parseFloat((mm/10.).toFixed(2)); + }; + + var cm2Mm = function(cm) { + return cm * 10.; + }; + return { models: [], collections: [], @@ -89,14 +97,23 @@ define([ ], initialize: function () { + var me = this; + Common.SharedSettings.set('readerMode', false); Common.NotificationCenter.on('settingscontainer:show', _.bind(this.initEvents, this)); - this.addListeners({ + me.maxMarginsW = me.maxMarginsH = 0; + me.localSectionProps = new Asc.CDocumentSectionProps(); + + me.addListeners({ 'Settings': { - 'page:show' : this.onPageShow + 'page:show' : me.onPageShow } }); + + uiApp.onPageAfterBack('settings-document-view', function (page) { + me.applyPageMarginsIfNeed() + }); }, setApi: function (api) { @@ -208,7 +225,8 @@ define([ initPageDocumentSettings: function () { var me = this, $pageOrientation = $('.page[data-page=settings-document-view] input:radio[name=doc-orientation]'), - $pageSize = $('#settings-document-format'); + $pageSize = $('#settings-document-format'), + txtCm = Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.cm); // Init orientation $pageOrientation.val([_isPortrait]); @@ -217,6 +235,23 @@ define([ // Init format $pageSize.find('.item-title').text(_pageSizes[_pageSizesIndex]['caption']); $pageSize.find('.item-subtitle').text(_pageSizes[_pageSizesIndex]['subtitle']); + + // Init page margins + me.localSectionProps = me.api.asc_GetSectionProps(); + + if (me.localSectionProps) { + me.maxMarginsH = me.localSectionProps.get_H() - 26; + me.maxMarginsW = me.localSectionProps.get_W() - 127; + + $('#document-margin-top .item-after label').text(mm2Cm(me.localSectionProps.get_TopMargin()) + ' ' + txtCm); + $('#document-margin-bottom .item-after label').text(mm2Cm(me.localSectionProps.get_BottomMargin()) + ' ' + txtCm); + $('#document-margin-left .item-after label').text(mm2Cm(me.localSectionProps.get_LeftMargin()) + ' ' + txtCm); + $('#document-margin-right .item-after label').text(mm2Cm(me.localSectionProps.get_RightMargin()) + ' ' + txtCm); + } + + _.each(["top", "left", "bottom", "right"], function(align) { + $(Common.Utils.String.format('#document-margin-{0} .button', align)).single('click', _.bind(me.onPageMarginsChange, me, align)); + }) }, initPageInfo: function () { @@ -271,6 +306,29 @@ define([ } }, + // Utils + + applyPageMarginsIfNeed: function() { + var me = this, + originalMarginsProps = me.api.asc_GetSectionProps(), + originalMarginsChecksum = _.reduce([ + originalMarginsProps.get_TopMargin(), + originalMarginsProps.get_LeftMargin(), + originalMarginsProps.get_RightMargin(), + originalMarginsProps.get_BottomMargin() + ], function(memo, num){ return memo + num; }, 0), + localMarginsChecksum = _.reduce([ + me.localSectionProps.get_TopMargin(), + me.localSectionProps.get_LeftMargin(), + me.localSectionProps.get_RightMargin(), + me.localSectionProps.get_BottomMargin() + ], function(memo, num){ return memo + num; }, 0); + + if (Math.abs(originalMarginsChecksum - localMarginsChecksum) > 0.01) { + me.api.asc_SetSectionProps(me.localSectionProps); + } + }, + // Handlers onSearch: function (e) { @@ -373,6 +431,38 @@ define([ }, 300); }, + onPageMarginsChange: function (align, e) { + var me = this, + $button = $(e.currentTarget), + step = 1, // mm + txtCm = Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.cm), + marginValue = null; + + switch (align) { + case 'left': marginValue = me.localSectionProps.get_LeftMargin(); break; + case 'top': marginValue = me.localSectionProps.get_TopMargin(); break; + case 'right': marginValue = me.localSectionProps.get_RightMargin(); break; + case 'bottom': marginValue = me.localSectionProps.get_BottomMargin(); break; + } + + if ($button.hasClass('decrement')) { + marginValue = Math.max(0, marginValue - step); + } else { + marginValue = Math.min((align == 'left' || align == 'right') ? me.maxMarginsW : me.maxMarginsH, marginValue + step); + } + + switch (align) { + case 'left': me.localSectionProps.put_LeftMargin(marginValue); break; + case 'top': me.localSectionProps.put_TopMargin(marginValue); break; + case 'right': me.localSectionProps.put_RightMargin(marginValue); break; + case 'bottom': me.localSectionProps.put_BottomMargin(marginValue); break; + } + + $(Common.Utils.String.format('#document-margin-{0} .item-after label', align)).text(mm2Cm(marginValue) + ' ' + txtCm); + + me.applyPageMarginsIfNeed() + }, + // API handlers onApiGetDocInfoStart: function () { diff --git a/apps/documenteditor/mobile/app/template/Settings.template b/apps/documenteditor/mobile/app/template/Settings.template index cb9a715dc..2ea5ff4ba 100644 --- a/apps/documenteditor/mobile/app/template/Settings.template +++ b/apps/documenteditor/mobile/app/template/Settings.template @@ -209,6 +209,71 @@ +
<%= scope.textMargins %>
+
+ +
diff --git a/apps/documenteditor/mobile/app/view/Settings.js b/apps/documenteditor/mobile/app/view/Settings.js index f120a87b4..d7d0450a2 100644 --- a/apps/documenteditor/mobile/app/view/Settings.js +++ b/apps/documenteditor/mobile/app/view/Settings.js @@ -261,7 +261,12 @@ define([ textOrientation: 'Orientation', textPoweredBy: 'Powered by', textSpellcheck: 'Spell Checking', - textPrint: 'Print' + textPrint: 'Print', + textMargins: 'Margins', + textTop: 'Top', + textLeft: 'Left', + textBottom: 'Bottom', + textRight: 'Right' } })(), DE.Views.Settings || {})) diff --git a/apps/documenteditor/mobile/locale/en.json b/apps/documenteditor/mobile/locale/en.json index c7f5bafa2..4b5016d73 100644 --- a/apps/documenteditor/mobile/locale/en.json +++ b/apps/documenteditor/mobile/locale/en.json @@ -387,5 +387,10 @@ "DE.Views.Settings.unknownText": "Unknown", "DE.Views.Settings.textSpellcheck": "Spell Checking", "DE.Views.Settings.textPrint": "Print", + "DE.Views.Settings.textMargins": "Margins", + "DE.Views.Settings.textTop": "Top", + "DE.Views.Settings.textLeft": "Left", + "DE.Views.Settings.textBottom": "Bottom", + "DE.Views.Settings.textRight": "Right", "DE.Views.Toolbar.textBack": "Back" } \ No newline at end of file