Merge "Allow the gallery dialog to insert duplicate images initially"

This commit is contained in:
jenkins-bot 2016-11-24 04:13:03 +00:00 committed by Gerrit Code Review
commit 1909c445bb
2 changed files with 25 additions and 14 deletions

View file

@ -52,7 +52,8 @@ ve.ui.MWGalleryDialog.prototype.initialize = function () {
// States // States
this.highlightedItem = null; this.highlightedItem = null;
this.searchPanelVisible = false; this.searchPanelVisible = false;
this.imageCaptions = {}; this.selectedFilenames = {};
this.initialImageData = [];
// Default settings // Default settings
this.defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions; this.defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions;
@ -304,7 +305,10 @@ ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) {
if ( title ) { if ( title ) {
titleText = title.getPrefixedText(); titleText = title.getPrefixedText();
imageTitles.push( titleText ); imageTitles.push( titleText );
dialog.imageCaptions[ titleText ] = matches[ 3 ]; dialog.initialImageData.push( {
title: titleText,
caption: matches[ 3 ]
} );
} }
} }
} }
@ -437,14 +441,21 @@ ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( deferred, re
} }
} }
for ( title in this.imageCaptions ) { if ( this.initialImageData.length > 0 ) {
if ( Object.prototype.hasOwnProperty.call( thumbUrls, title ) ) { this.initialImageData.forEach( function ( image ) {
items.push( new ve.ui.MWGalleryItemWidget( { image.thumbUrl = thumbUrls[ image.title ];
title: title, items.push( new ve.ui.MWGalleryItemWidget( image ) );
caption: this.imageCaptions[ title ], } );
thumbUrl: thumbUrls[ title ] this.initialImageData = [];
} ) ); } else {
delete this.imageCaptions[ title ]; for ( title in this.selectedFilenames ) {
if ( Object.prototype.hasOwnProperty.call( thumbUrls, title ) ) {
items.push( new ve.ui.MWGalleryItemWidget( {
title: title,
thumbUrl: thumbUrls[ title ]
} ) );
delete this.selectedFilenames[ title ];
}
} }
} }
this.galleryGroup.addItems( items ); this.galleryGroup.addItems( items );
@ -463,8 +474,8 @@ ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( deferred, re
ve.ui.MWGalleryDialog.prototype.addNewImage = function ( title ) { ve.ui.MWGalleryDialog.prototype.addNewImage = function ( title ) {
var dialog = this; var dialog = this;
// Reset this.imageCaptions, for onRequestImagesSuccess // Make list of unique pending images, for onRequestImagesSuccess
this.imageCaptions[ title ] = ''; this.selectedFilenames[ title ] = true;
// Request image // Request image
this.requestImages( { this.requestImages( {
@ -486,7 +497,7 @@ ve.ui.MWGalleryDialog.prototype.addNewImage = function ( title ) {
ve.ui.MWGalleryDialog.prototype.onSearchResultsChoose = function ( item ) { ve.ui.MWGalleryDialog.prototype.onSearchResultsChoose = function ( item ) {
var title = mw.Title.newFromText( item.getData().title ).getPrefixedText(); var title = mw.Title.newFromText( item.getData().title ).getPrefixedText();
if ( !Object.prototype.hasOwnProperty( this.imageCaptions, title ) ) { if ( !Object.prototype.hasOwnProperty( this.selectedFilenames, title ) ) {
this.addNewImage( title ); this.addNewImage( title );
} }
}; };

View file

@ -19,7 +19,7 @@
ve.ui.MWGalleryItemWidget = function VeUiMWGalleryItemWidget( imageInfo, config ) { ve.ui.MWGalleryItemWidget = function VeUiMWGalleryItemWidget( imageInfo, config ) {
this.imageTitle = imageInfo.title; this.imageTitle = imageInfo.title;
this.thumbUrl = imageInfo.thumbUrl; this.thumbUrl = imageInfo.thumbUrl;
this.caption = imageInfo.caption; this.caption = imageInfo.caption || '';
this.highlighted = false; this.highlighted = false;
// Configuration initialization // Configuration initialization