-
-
Notifications
You must be signed in to change notification settings - Fork 603
XWIKI-20953: Edit autosave frequency visibility #4682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f408e25
ed654d7
329042f
014133d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -411,7 +411,7 @@ core.edit.wikiToolbar.htmltext=<!-- Your HTML code here --> | |||||
| core.edit.wikiToolbar.velocity=Velocity code | ||||||
| core.edit.wikiToolbar.velocitytext=#* Your velocity code here *# | ||||||
| core.edit.autosave=Autosave | ||||||
| core.edit.autosave.every=every | ||||||
| core.edit.autosave.interval.label=Autosave interval (in mins) | ||||||
|
|
||||||
| notice=Notice | ||||||
| changephoto=Changing photo for {0} | ||||||
|
|
@@ -5695,6 +5695,11 @@ platform.index.spaceIndexDocumentListCreate=Create a new page | |||||
| csrf.confirmation=<p>This request contains an invalid authentication information.</p><p>This might happen in the following situations:</p><ul><li>You left the editor open in another window/tab and logged off and on again</li><li>Your authentication token expired after a long period of inactivity</li><li>Somebody tried to perform a CSRF attack</li></ul><p>If you are sure that none of these situations apply in your case, you might have found a bug. We are sorry about that, please report it on <a href="http://jira.xwiki.org/">XWiki JIRA</a></p><p>Do you want to resend the request? If unsure, say <strong>No</strong>.</p> | ||||||
| core.register.successful={0} ({1}): Registration successful. | ||||||
|
|
||||||
| ####################################### | ||||||
| ## until 17.9.0RC1 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ####################################### | ||||||
| core.edit.autosave.every=every | ||||||
|
|
||||||
| ## Used to indicate where deprecated keys end | ||||||
| #@deprecatedend | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,18 @@ | ||
| #template('colorThemeInit.vm') | ||
| #autosaveControl { | ||
| display: inline; | ||
| white-space: nowrap; | ||
| } | ||
| #autosaveControl input.autosave-frequency { | ||
| text-align: center; | ||
| width: 2em; | ||
| } | ||
|
|
||
| /** Override Toucan styles */ | ||
| #body #autosaveControl label { | ||
| display: inline; | ||
| margin: 0; | ||
| #autosaveControl .interval { | ||
| display: none; | ||
| margin-left: 2em; | ||
|
|
||
| & .autosave-interval { | ||
| width: 3em; | ||
| margin-left: 1em; | ||
| } | ||
| } | ||
| #body #autosaveControl label.frequency, #body #autosaveControl label.frequency span { | ||
| text-transform: none; | ||
| font-weight: 400; | ||
| } | ||
| #autosaveControl label.autosave { | ||
| font-weight: 400; | ||
|
|
||
| #autosaveControl .autosave:has(input:checked) + .interval { | ||
| display: inline-block; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ editors.AutoSave = Class.create({ | |
| /** Is the autosave enabled ? */ | ||
| enabled: false, | ||
| /** If enabled, how frequent are the savings */ | ||
| frequency: 5, // minutes | ||
| interval: 5, // minutes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking API change as this is a public API, e.g., documented at https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/FrontendResources/Autosave/. I would suggest not modifying the API and just modifying the displayed text. |
||
| /** Is the UI for configuring the autosave enabled or not? */ | ||
| showConfigurationUI: true, | ||
| /** | ||
|
|
@@ -45,7 +45,7 @@ editors.AutoSave = Class.create({ | |
| /** Initialization */ | ||
| initialize : function(options) { | ||
| this.options = Object.extend(Object.clone(this.options), options || { }); | ||
| this.form = $(this.options.form) || ($("xwikieditcontent") && $("xwikieditcontent").up('form')); | ||
| this.form = $(this.options.form) || $("xwikieditcontent")?.up('form'); | ||
| if (!this.form || this.form.down('#autosaveControl')) { | ||
| return; | ||
| } | ||
|
|
@@ -83,44 +83,40 @@ editors.AutoSave = Class.create({ | |
| }, | ||
|
|
||
| /** | ||
| * The UI of the autosave feature is created and introduced at the beginning of the edit form. It comprises a checkbox | ||
| * for enabling / disabling the autosave and an input that allows to set the autosave frequency. | ||
| * The UI of the autosave feature is created and introduced towards the end of the edit form. | ||
| * It contains a checkbox for toggling the autosave and an input that allows to set the autosave interval in minutes. | ||
| */ | ||
| createUIElements : function() { | ||
| // Checkbox to enable/disable the autosave | ||
| // Toggle for the autosave feature. | ||
| this.autosaveCheckbox = new Element('input', { | ||
| type: "checkbox", | ||
| checked: this.options.enabled, | ||
| name: "doAutosave", | ||
| id: "doAutosave" | ||
| }); | ||
| // Input for setting the autosave frequency | ||
| this.autosaveInput = new Element('input', { | ||
| // Input for setting the autosave interval | ||
| this.autosaveIntervalInput = new Element('input', { | ||
| type: "text", | ||
| value: this.options.frequency, | ||
| value: this.options.interval, | ||
| size: "2", | ||
| "class": "autosave-frequency" | ||
| "class": "autosave-interval" | ||
| }); | ||
| // Labels | ||
| var autosaveLabel = new Element('label', {'class': 'autosave', 'for' : "doAutosave"}); | ||
| let autosaveLabel = new Element('label', {'class': 'autosave'}); | ||
| autosaveLabel.appendChild(this.autosaveCheckbox); | ||
| autosaveLabel.appendChild(document.createTextNode(" $services.localization.render('core.edit.autosave')")); | ||
| var frequencyLabel = new Element('label', {'class': 'frequency'}); | ||
| frequencyLabel.appendChild(document.createTextNode("$services.localization.render('core.edit.autosave.every') ")); | ||
| frequencyLabel.appendChild(this.autosaveInput); | ||
| this.timeUnit = new Element('span'); | ||
| this.setTimeUnit(); | ||
| frequencyLabel.appendChild(document.createTextNode(" ")); | ||
| frequencyLabel.appendChild(this.timeUnit); | ||
| autosaveLabel.appendChild(document.createTextNode("$escapetool.javascript($services.localization.render('core.edit.autosave'))")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be much simpler to use the |
||
| let intervalLabel = new Element('label', {'class': 'interval'}); | ||
| intervalLabel.appendChild(document.createTextNode("$escapetool.javascript($services.localization.render('core.edit.autosave.interval.label'))")); | ||
| intervalLabel.appendChild(this.autosaveIntervalInput); | ||
| // A paragraph containing the whole thing | ||
| var container = new Element('div', {"id": "autosaveControl"}); | ||
| let container = new Element('div', {"id": "autosaveControl"}); | ||
| this.classNameAutosaveDisabled = 'autosaveDisabled'; | ||
| if (!this.options.enabled) { | ||
| container.addClassName(this.classNameAutosaveDisabled); | ||
| } | ||
| container.appendChild(autosaveLabel); | ||
| container.appendChild(document.createTextNode(" ")); | ||
| container.appendChild(frequencyLabel); | ||
| container.appendChild(intervalLabel); | ||
| container.appendChild(document.createTextNode(" ")); | ||
| // Insert in the editing UI | ||
| this.form.down('.buttons').insert(container); | ||
|
|
@@ -138,7 +134,7 @@ editors.AutoSave = Class.create({ | |
| } | ||
| }; | ||
| ["keydown", "keyup", "keypress"].each(function(eventName) { | ||
| this.autosaveInput.observe(eventName, preventSubmit); | ||
| this.autosaveIntervalInput.observe(eventName, preventSubmit); | ||
| this.autosaveCheckbox.observe(eventName, preventSubmit); | ||
| }.bind(this)); | ||
|
|
||
|
|
@@ -147,38 +143,24 @@ editors.AutoSave = Class.create({ | |
| this.toggleTimer(this.autosaveCheckbox.checked); | ||
| }.bindAsEventListener(this)); | ||
|
|
||
| // Set autosave frequency | ||
| Event.observe(this.autosaveInput, "blur", function() { | ||
| // Set autosave interval | ||
| Event.observe(this.autosaveIntervalInput, "blur", function() { | ||
| // is the given value valid? | ||
| var newFrequency = new Number(this.autosaveInput.value); | ||
| if (newFrequency > 0) { | ||
| let newInterval = Number(this.autosaveIntervalInput.value); | ||
| if (newInterval > 0) { | ||
| // yes: memorize it | ||
| this.options.frequency = newFrequency; | ||
| this.setTimeUnit(); | ||
| this.options.interval = newInterval; | ||
| // reset autosave loop | ||
| this.startTimer(); | ||
| } else { | ||
| // no: restore the previous value in the input | ||
| this.autosaveInput.value = this.options.frequency; | ||
| this.autosaveIntervalInput.value = this.options.interval; | ||
| } | ||
| }.bindAsEventListener(this)); | ||
|
|
||
| this._toggleTimerWhenSaveButtonIsEnabledOrDisabled(); | ||
| }, | ||
|
|
||
| /** | ||
| * Changes the label text displaying the time measure unit for autosave freaquency, | ||
| * according to the value introduced by the user in the input (singular or plural). | ||
| * TODO This is bad, very difficult to internationalize. | ||
| */ | ||
| setTimeUnit : function() { | ||
| if (this.options.frequency == 1) { | ||
| this.timeUnit.update("minute"); | ||
| } else { | ||
| this.timeUnit.update("minutes"); | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Stop the timer when the save button is disabled (e.g. because there is another save in progress or because the save | ||
| * button was hidden) and restart the timer, if needed, when the save button is enabled. | ||
|
|
@@ -207,30 +189,30 @@ editors.AutoSave = Class.create({ | |
| } | ||
| if (this.options.enabled) { | ||
| this.startTimer(); | ||
| if (this.autosaveInput) { | ||
| this.autosaveInput.up(1).removeClassName(this.classNameAutosaveDisabled); | ||
| if (this.autosaveIntervalInput) { | ||
| this.autosaveIntervalInput.up(1).removeClassName(this.classNameAutosaveDisabled); | ||
| } | ||
| } else { | ||
| this.stopTimer(); | ||
| if (this.autosaveInput) { | ||
| this.autosaveInput.up(1).addClassName(this.classNameAutosaveDisabled); | ||
| if (this.autosaveIntervalInput) { | ||
| this.autosaveIntervalInput.up(1).addClassName(this.classNameAutosaveDisabled); | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Start autosave timer when the autosave is enabled. | ||
| * Every (this.options.frequency * 60) seconds, the callback function doAutosave is called. | ||
| * Every (this.options.interval * 60) seconds, the callback function doAutosave is called. | ||
| */ | ||
| startTimer : function() { | ||
| // Make sure we stop the existing timer. | ||
| this.stopTimer(); | ||
| this.timer = new PeriodicalExecuter(this.doAutosave.bind(this), | ||
| this.options.frequency * 60 /* seconds in a minute */); | ||
| this.options.interval * 60 /* seconds in a minute */); | ||
| }, | ||
|
|
||
| /** | ||
| * Stop the autosave loop when the autosave is disabled or when the autosave frequency is changed | ||
| * Stop the autosave loop when the autosave is disabled or when the autosave interval is changed | ||
| * and the loop needs to be restarted. | ||
| */ | ||
| stopTimer : function() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term "mins" is colloquial English, I think we should use a proper formal term like "minutes".