From 5e919c6e10ced4d95ab041a1ccdf21ea933778e5 Mon Sep 17 00:00:00 2001 From: Leo Koppelkamm Date: Thu, 14 Jul 2011 20:48:01 +0000 Subject: [PATCH] AjaxCategories: More interface polish --- languages/messages/MessagesEn.php | 2 + maintenance/language/messages.inc | 2 + resources/Resources.php | 2 + .../mediawiki.page.ajaxCategories.css | 4 +- .../mediawiki.page.ajaxCategories.js | 69 ++++++++++++------- 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index fce45c74f2..e64fd6b777 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -4592,11 +4592,13 @@ This site is experiencing technical difficulties.', 'ajax-remove-category' => 'Remove category', 'ajax-edit-category' => 'Edit category', 'ajax-add-category-submit' => 'Add', +'ajax-confirm-ok' => 'OK', 'ajax-confirm-title' => 'Confirm action', 'ajax-confirm-prompt' => 'You can provide an edit summary below. Click "Save" to save your edit.', 'ajax-confirm-save' => 'Save', 'ajax-confirm-save-all' => 'Save all changes', +'ajax-cancel' => 'Cancel edits', 'ajax-add-category-summary' => 'Add category "$1"', 'ajax-edit-category-summary' => 'Change category "$1" to "$2"', 'ajax-remove-category-summary' => 'Remove category "$1"', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 30b00695e3..a66d1a57e7 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -3464,10 +3464,12 @@ $wgMessageStructure = array( 'ajax-remove-category', 'ajax-edit-category', 'ajax-add-category-submit', + 'ajax-confirm-ok', 'ajax-confirm-title', 'ajax-confirm-prompt', 'ajax-confirm-save', 'ajax-confirm-save-all', + 'ajax-cancel', 'ajax-add-category-summary', 'ajax-edit-category-summary', 'ajax-remove-category-summary', diff --git a/resources/Resources.php b/resources/Resources.php index 459ce2adf1..98b508e3aa 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -499,10 +499,12 @@ return array( 'ajax-remove-category', 'ajax-edit-category', 'ajax-add-category-submit', + 'ajax-confirm-ok', 'ajax-confirm-prompt', 'ajax-confirm-title', 'ajax-confirm-save', 'ajax-confirm-save-all', + 'ajax-cancel', 'ajax-add-category-summary', 'ajax-remove-category-summary', 'ajax-edit-category-summary', diff --git a/resources/mediawiki.page/mediawiki.page.ajaxCategories.css b/resources/mediawiki.page/mediawiki.page.ajaxCategories.css index 1a9f6ce882..dd991aaf11 100644 --- a/resources/mediawiki.page/mediawiki.page.ajaxCategories.css +++ b/resources/mediawiki.page/mediawiki.page.ajaxCategories.css @@ -11,7 +11,9 @@ padding: 2px 8px; display:inline; } - +.mw-removed-category { + text-decoration: line-through; +} #catlinks:hover .icon { opacity: 1; } diff --git a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js index 1a451a235d..ff3b727584 100644 --- a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js +++ b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js @@ -7,6 +7,8 @@ // * Add Hooks for soft redirect // * Handle normal redirects +// * Fixme on narrow windows +// * Enter to submit ( function( $, mw ) { @@ -26,6 +28,8 @@ var ajaxCategories = function ( options ) { var categoryNamespaceId = namespaceIds['category']; var categoryNamespace = mw.config.get( 'wgFormattedNamespaces' )[categoryNamespaceId]; var _saveAllButton; + var _cancelAllButton; + var _multiEdit = ( wgUserGroups.indexOf("user") != -1 ); /** * Helper function for $.fn.suggestion @@ -169,13 +173,15 @@ var ajaxCategories = function ( options ) { */ _confirmEdit = function ( fn, actionSummary, doneFn, all ) { // Check whether to use multiEdit mode - if ( wgUserGroups.indexOf("user") != -1 && !all ) { + if ( _multiEdit && !all ) { // Stash away _stash.summaries.push( actionSummary ); _stash.fns.push( fn ); + //TODO add Cancel button _saveAllButton.show(); - + //_cancelAllButton.show(); + // This only does visual changes doneFn( true ); return; @@ -253,21 +259,27 @@ var ajaxCategories = function ( options ) { } return newtext; }; - var doneFn = function() { - //Remove saveAllButton - _saveAllButton.hide(); - - // Clean stash - _stash.fns = []; - _stash.summaries = []; + var doneFn = _resetToActual; - // TODO - // Any link with $link.css('text-decoration', 'line-through'); - // needs to be removed - }; _confirmEdit( combinedFn, summary, doneFn, true ); }; + _resetToActual = function() { + //Remove saveAllButton + _saveAllButton.hide(); + _cancelAllButton.hide(); + + // Clean stash + _stash.fns = []; + _stash.summaries = []; + + // TODO + $container.find('.mw-removed-category').parent().remove(); + // Any link with $link.css('text-decoration', 'line-through'); + // needs to be removed + + }; + _doEdit = function ( page, fn, summary, doneFn ) { // Get an edit token for the page. var getTokenVars = { @@ -373,7 +385,10 @@ var ajaxCategories = function ( options ) { var $link = $this.parent().find( 'a:not(.icon)' ); var category = $link.text(); - var $input = _makeSuggestionBox( category, _handleCategoryEdit, mw.msg( 'ajax-confirm-save' ) ); + var $input = _makeSuggestionBox( category, + _handleCategoryEdit, + _multiEdit ? mw.msg( 'ajax-confirm-ok' ) : mw.msg( 'ajax-confirm-save' ) + ); $link.after( $input ).hide(); _catElements[category].editButton.hide(); _catElements[category].deleteButton.unbind('click').click( function() { @@ -420,8 +435,8 @@ var ajaxCategories = function ( options ) { summary, function( unsaved ) { if ( unsaved ) { - //TODO flesh out: Make it a class, make revertable - $link.css('text-decoration', 'line-through'); + //TODO Make revertable + $link.addClass('.mw-removed-category'); } else { $this.parent().remove(); } @@ -435,7 +450,7 @@ var ajaxCategories = function ( options ) { category = $.ucFirst( category ); if ( _containsCat(category) ) { - _showError( mw.msg( 'ajax-category-already-present' ) ); + _showError( mw.msg( 'ajax-category-already-present', category ) ); return; } var appendText = "\n[[" + categoryNamespace + ":" + category + "]]\n"; @@ -454,6 +469,7 @@ var ajaxCategories = function ( options ) { }; _handleCategoryEdit = function ( e ) { + //FIXME: in MultiEdit Mode handle successive edits to same category e.preventDefault(); // Grab category text @@ -464,10 +480,9 @@ var ajaxCategories = function ( options ) { var $link = $this.parent().parent().find( 'a:not(.icon)' ); var category = $link.text(); - // User didn't change anything. Just close the box + // User didn't change anything. if ( category == categoryNew ) { - $this.parent().remove(); - $link.show(); + _catElements[category].deleteButton.click(); return; } categoryRegex = _buildRegex( category ); @@ -505,8 +520,9 @@ var ajaxCategories = function ( options ) { summary, function() { // Remove input box & button - $this.parent().remove(); - + _catElements[category].deleteButton.click(); + _catElements[categoryNew] = _catElements[category]; + delete _catElements[category]; // Update link text and href $link.show().text( categoryNew ).attr( 'href', _catLink( categoryNew ) ); } @@ -624,8 +640,15 @@ var ajaxCategories = function ( options ) { '', mw.msg( 'ajax-confirm-save-all' ) ); + _cancelAllButton = _createButton( 'icon-tick', + mw.msg( 'ajax-confirm-save-all' ), + '', + mw.msg( 'ajax-confirm-save-all' ) + ); _saveAllButton.click( _handleStashedCategories ).hide(); - $containerNormal.append( _saveAllButton ); + _cancelAllButton.hide(); + + $containerNormal.append( _saveAllButton ).append( _cancelAllButton ); }; _stash = { -- 2.20.1