summaryrefslogtreecommitdiffstats
path: root/client/components/forms
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-08-31 15:09:53 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-08-31 15:52:16 +0200
commitd644cba38ff06369cc43c1ebd08d344fd1d248ea (patch)
treebad4bcef1f549132792301cf134b3c8234ad1d13 /client/components/forms
parentcc88e78483d2f39048d3558193f0c82b711c12c8 (diff)
downloadwekan-d644cba38ff06369cc43c1ebd08d344fd1d248ea.tar.gz
wekan-d644cba38ff06369cc43c1ebd08d344fd1d248ea.tar.bz2
wekan-d644cba38ff06369cc43c1ebd08d344fd1d248ea.zip
Replace the component bounded `cachedValue` by a global `UnsavedEdits`
This new draft saving system is currently only implemented for the card description and comment. We need better a component inheritance/composition model to support this for all editable fields. Fixes #186
Diffstat (limited to 'client/components/forms')
-rw-r--r--client/components/forms/cachedValue.js22
-rw-r--r--client/components/forms/inlinedform.js90
2 files changed, 0 insertions, 112 deletions
diff --git a/client/components/forms/cachedValue.js b/client/components/forms/cachedValue.js
deleted file mode 100644
index a2898d85..00000000
--- a/client/components/forms/cachedValue.js
+++ /dev/null
@@ -1,22 +0,0 @@
-var emptyValue = '';
-
-Mixins.CachedValue = BlazeComponent.extendComponent({
- onCreated: function() {
- this._cachedValue = emptyValue;
- },
-
- setCache: function(value) {
- this._cachedValue = value;
- },
-
- getCache: function(defaultValue) {
- if (this._cachedValue === emptyValue)
- return defaultValue || '';
- else
- return this._cachedValue;
- },
-
- resetCache: function() {
- this.setCache('');
- }
-});
diff --git a/client/components/forms/inlinedform.js b/client/components/forms/inlinedform.js
deleted file mode 100644
index 09c75ce1..00000000
--- a/client/components/forms/inlinedform.js
+++ /dev/null
@@ -1,90 +0,0 @@
-// A inlined form is used to provide a quick edition of single field for a given
-// document. Clicking on a edit button should display the form to edit the field
-// value. The form can then be submited, or just closed.
-//
-// When the form is closed we save non-submitted values in memory to avoid any
-// data loss.
-//
-// Usage:
-//
-// +inlineForm
-// // the content when the form is open
-// else
-// // the content when the form is close (optional)
-
-// We can only have one inlined form element opened at a time
-// XXX Could we avoid using a global here ? This is used in Mousetrap
-// keyboard.js
-var currentlyOpenedForm = new ReactiveVar(null);
-
-BlazeComponent.extendComponent({
- template: function() {
- return 'inlinedForm';
- },
-
- mixins: function() {
- return [Mixins.CachedValue];
- },
-
- onCreated: function() {
- this.isOpen = new ReactiveVar(false);
- },
-
- onDestroyed: function() {
- currentlyOpenedForm.set(null);
- },
-
- open: function() {
- // Close currently opened form, if any
- EscapeActions.executeUpTo('inlinedForm');
- this.isOpen.set(true);
- currentlyOpenedForm.set(this);
- },
-
- close: function() {
- this.saveValue();
- this.isOpen.set(false);
- currentlyOpenedForm.set(null);
- },
-
- getValue: function() {
- var input = this.find('textarea,input[type=text]');
- return this.isOpen.get() && input && input.value;
- },
-
- saveValue: function() {
- this.callFirstWith(this, 'setCache', this.getValue());
- },
-
- events: function() {
- return [{
- 'click .js-close-inlined-form': this.close,
- 'click .js-open-inlined-form': this.open,
-
- // Pressing Ctrl+Enter should submit the form
- 'keydown form textarea': function(evt) {
- if (evt.keyCode === 13 && (evt.metaKey || evt.ctrlKey)) {
- this.find('button[type=submit]').click();
- }
- },
-
- // Close the inlined form when after its submission
- submit: function() {
- if (this.currentData().autoclose !== false) {
- Tracker.afterFlush(() => {
- this.close();
- this.callFirstWith(this, 'resetCache');
- });
- }
- }
- }];
- }
-}).register('inlinedForm');
-
-// Press escape to close the currently opened inlinedForm
-EscapeActions.register('inlinedForm',
- function() { currentlyOpenedForm.get().close(); },
- function() { return currentlyOpenedForm.get() !== null; }, {
- noClickEscapeOn: '.js-inlined-form'
- }
-);