Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/235646

Change subject: [wip] Toggle the save button when there are changes to the 
content
......................................................................

[wip] Toggle the save button when there are changes to the content

Change-Id: I7cfa891ef75f1cf1c5f2dfc4000802c1f97816b8
---
M modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
M modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
M modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
M modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
M modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
M modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
6 files changed, 55 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/46/235646/1

diff --git 
a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js 
b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
index b68da8f..67ba1de 100644
--- a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
+++ b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.AbstractEditorWidget.js
@@ -118,10 +118,18 @@
        /**
         * Change the content of the editor.
         *
+        * @abstract
         * @method
         * @param {string} content New content
         */
-       mw.flow.ui.AbstractEditorWidget.prototype.setContent = function ( 
content ) {
+       mw.flow.ui.AbstractEditorWidget.prototype.setContent = null;
+
+       /**
+        * Set the initial content for comparison
+        *
+        * @param {string} content New content
+        */
+       mw.flow.ui.AbstractEditorWidget.prototype.setInitialContent = function 
( content ) {
                // Cache content for comparison
                this.initialContent = content;
        };
diff --git 
a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js 
b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
index 06df41e..5d1bb8a 100644
--- a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
+++ b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.VisualEditorWidget.js
@@ -173,9 +173,15 @@
        /**
         * @inheritdoc
         */
-       mw.flow.ui.VisualEditorWidget.prototype.setContent = function ( content 
) {
+       mw.flow.ui.VisualEditorWidget.prototype.setContent = function ( 
content, isOriginalContent ) {
                this.target.clearSurfaces();
                this.createSurface( content );
+               if ( isOriginalContent ) {
+                       // Set breakpoint to compare to
+                       // 
+                       // 
+                       // 
+               }
        };
 
        /**
diff --git 
a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js 
b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
index a30a442..22d0291 100644
--- a/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
+++ b/modules/flow/ui/widgets/editor/editors/mw.flow.ui.WikitextEditorWidget.js
@@ -134,10 +134,10 @@
        /**
         * @inheritdoc
         */
-       mw.flow.ui.WikitextEditorWidget.prototype.setContent = function ( 
content ) {
-               // Parent method
-               
mw.flow.ui.WikitextEditorWidget.parent.prototype.setContent.call( this, content 
);
-
+       mw.flow.ui.WikitextEditorWidget.prototype.setContent = function ( 
content, isOriginalContent ) {
+               if ( isOriginalContent ) {
+                       this.setInitialContent( content );
+               }
                this.input.setValue( content );
        };
 
diff --git a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js 
b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
index e9844c8..0374d18 100644
--- a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
+++ b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
@@ -383,7 +383,7 @@
         * @param {string} contentFormat Format of new content
         * @return {jQuery.Promise} Promise resolved when new content has been 
set
         */
-       mw.flow.ui.EditorSwitcherWidget.prototype.setContent = function ( 
content, contentFormat ) {
+       mw.flow.ui.EditorSwitcherWidget.prototype.setContent = function ( 
content, contentFormat, isOriginalContent ) {
                if ( this.settingPromise ) {
                        // TODO handle this more gracefully
                        return $.Deferred().reject();
@@ -409,7 +409,7 @@
                                return widget.convertContent( content, 
contentFormat, widget.contentFormat );
                        } )
                        .then( function ( newContent ) {
-                               widget.getActiveEditor().setContent( newContent 
);
+                               widget.getActiveEditor().setContent( 
newContent, isOriginalContent );
                                settingDeferred.resolve();
                                widget.settingPromise = null;
                        } )
@@ -431,6 +431,10 @@
                this.autoFocus = autoFocus === undefined ? !this.autoFocus : 
!!autoFocus;
        };
 
+       mw.flow.ui.EditorSwitcherWidget.prototype.getActiveEditorName = 
function () {
+               return this.activeEditorName;
+       };
+
        /**
         * Respond to change events from an editor
         *
diff --git a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js 
b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
index 00e6965..15e8a55 100644
--- a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
+++ b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
@@ -33,6 +33,7 @@
 
                this.initialEditor = config.editor;
                this.confirmCancel = !!config.confirmCancel || 
config.cancelOnEscape === undefined;
+               this.changedOnce = false;
 
                this.editorControlsWidget = new 
mw.flow.ui.EditorControlsWidget( {
                        termsMsgKey: config.termsMsgKey || 
'flow-terms-of-use-edit',
@@ -52,7 +53,7 @@
                // Events
                this.editorSwitcherWidget.connect( this, {
                        'switch': 'onEditorSwitcherSwitch',
-                       change: [ 'emit', 'change' ]
+                       change: 'onEditorSwitcherChange'
                } );
                this.editorControlsWidget.connect( this, {
                        cancel: 'onEditorControlsWidgetCancel',
@@ -115,6 +116,28 @@
        // merge EditorSwitcherWidget into EditorWidget?
 
        /**
+        * Respond to change in the editor
+        * @fires change
+        */
+       mw.flow.ui.EditorWidget.prototype.onEditorSwitcherChange = function () {
+               var hasBeenChanged = this.editorSwitcherWidget.hasBeenChanged();
+
+               if (
+                       // If there have been changes
+                       hasBeenChanged &&
+                       // And the editor is the original one we loaded (which 
is where we
+                       // saved the initial content for comparison)
+                       this.initialEditor === 
this.editorSwitcherWidget.getActiveEditorName()
+               ) {
+                       // Set the changedOnce flag to true
+                       this.changedOnce = true;
+               }
+
+               // Check if there's changed content or if the changedOnce flag 
is on
+               this.editorControlsWidget.toggleSaveable( this.changedOnce || 
hasBeenChanged );
+               this.emit( 'change' );
+       };
+       /**
         * Respond to cancel event. Verify with the user that they want to 
cancel if
         * there is changed data in the editor.
         * @fires cancel
@@ -136,6 +159,8 @@
                } else {
                        this.emit( 'cancel' );
                }
+               // Reset the changedOnce flag
+               this.changedOnce = false;
        };
 
        /**
@@ -210,8 +235,8 @@
         * @return {jQuery.Promise} Promise resolved when new content has been 
set
         * @see mw.flow.ui.EditorSwitcherWidget#setContent
         */
-       mw.flow.ui.EditorWidget.prototype.setContent = function ( content, 
contentFormat ) {
-               return this.editorSwitcherWidget.setContent( content, 
contentFormat );
+       mw.flow.ui.EditorWidget.prototype.setContent = function ( content, 
contentFormat, isOriginalContent ) {
+               return this.editorSwitcherWidget.setContent( content, 
contentFormat, isOriginalContent );
        };
 
        /**
diff --git a/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js 
b/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
index 480a63f..3fd95e9 100644
--- a/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
+++ b/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
@@ -114,7 +114,7 @@
 
                                        if ( content !== undefined && format 
!== undefined ) {
                                                // Give it to the editor
-                                               widget.editor.setContent( 
content, format );
+                                               widget.editor.setContent( 
content, format, true );
 
                                                // Update revisionId in the API
                                                widget.api.setCurrentRevision( 
widget.model.getRevisionId() );

-- 
To view, visit https://gerrit.wikimedia.org/r/235646
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7cfa891ef75f1cf1c5f2dfc4000802c1f97816b8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to