Brian Wolff has uploaded a new change for review. https://gerrit.wikimedia.org/r/300739
Change subject: [WIP] add GUI for per item edit ...................................................................... [WIP] add GUI for per item edit Bug: T141073 Change-Id: Ieebd1d517b82b296309b548e0ce32cd62b64fe62 --- M modules/ext.CollaborationKit.list.edit.js 1 file changed, 74 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit refs/changes/39/300739/1 diff --git a/modules/ext.CollaborationKit.list.edit.js b/modules/ext.CollaborationKit.list.edit.js index 194eec4..a56e41f 100644 --- a/modules/ext.CollaborationKit.list.edit.js +++ b/modules/ext.CollaborationKit.list.edit.js @@ -1,16 +1,44 @@ ( function ( $, mw, OO ) { - var deleteItem, getCurrentJson, saveJson, addItem, reorderList, getListOfTitles; + var deleteItem, getCurrentJson, saveJson, addItem, reorderList, getListOfTitles, modifyItem, modifyExistingItem; addItem = function () { + modifyItem( {} ); + } + + /** + * @param item Object The name of the title to modify, or false to add new. + */ + modifyItem = function ( itemToEdit ) { var dialog, windowManager = new OO.ui.WindowManager(); $( 'body' ).append( windowManager.$element ); - dialog = new NewItemDialog( { - size: 'medium' - } ); + itemToEdit['size'] = 'medium'; + dialog = new NewItemDialog( itemToEdit ); windowManager.addWindows( [ dialog ] ); windowManager.openWindow( dialog ); }; + + modifyExistingItem = function ( itemName ) { + getCurrentJson( mw.config.get( 'wgArticleId' ), function ( res ) { + var done = false; + $.each( res.content.items, function ( index ) { + if ( this.title === itemName ) { + done = true; + modifyItem( { + itemTitle: this.title, + itemImage: this.image, + itemDescription: this.notes + } ); + return false; + } + } ); + if ( !done ) { + // FIXME error handling + alert( "Edit conflict!" ); + location.reload(); + } + } ); + } deleteItem = function ( $item ) { var cur, @@ -232,6 +260,11 @@ // There's probably an easier way to do this. function NewItemDialog( config ) { + if ( config.itemTitle ) { + this.itemTitle = config.itemTitle; + this.itemDescription = config.itemDescription; + this.itemImage = config.itemImage; + } NewItemDialog.parent.call( this, config ); } OO.inheritClass( NewItemDialog, OO.ui.ProcessDialog ); @@ -242,7 +275,11 @@ { modes: 'edit', label: 'Cancel', flags: 'safe' } ]; - NewItemDialog.prototype.initialize = function () { + + /** + * @param itemInfo Object info from json + */ + NewItemDialog.prototype.initialize = function ( itemInfo ) { var titleWidget, fileToUse, description; NewItemDialog.parent.prototype.initialize.apply( this, arguments ); @@ -264,6 +301,16 @@ multiline: true, label: 'Description (optional)' // fixme i18n } ); + + if ( this.itemTitle ) { + this.titleWidget.setValue( this.itemTitle ); + if ( this.itemDescription ) { + this.description.setValue( this.itemDescription ); + } + if ( this.itemImage ) { + this.fileToUse.setValue( this.itemImage ); + } + } this.panel1.$element.append( this.titleWidget.$element ); this.panel1.$element.append( $( '<br>' ) ); this.panel1.$element.append( this.fileToUse.$element ); @@ -292,16 +339,20 @@ NewItemDialog.prototype.saveItem = function () { var title = this.titleWidget.getValue().trim(), file = this.fileToUse.getValue().trim(), - notes = this.description.getValue(), + notes = this.description.getValue().trim(), dialog = this; getCurrentJson( mw.config.get( 'wgArticleId' ), function ( res ) { + var itemToAdd = { + title: title, + notes: notes + }; res.content.items[ res.content.items.length ] = { title: title, notes: notes }; if ( file !== '' ) { - res.content.items[ res.content.items.length ].image = file; + itemToAdd.image = file; } res.summary = mw.msg( 'collabkit-list-add-summary', title ); saveJson( res, function () { @@ -329,8 +380,10 @@ $list.find( '.mw-collabkit-list-item' ).each( function () { var deleteButton, moveButton, + editButton, $delWrapper, $moveWrapper, + $editWrapper, $item = $( this ); deleteButton = new OO.ui.ButtonWidget( { @@ -344,6 +397,13 @@ framed: false, icon: 'move', iconTitle: 'Re-order this item' // fixme i18n + } ); + + editButton = new OO.ui.ButtonWidget( { + label: 'edit', + framed: false + } ).on( 'click', function () { + modifyExistingItem( $item.data( 'collabkit-item-title' ) ); } ); // FIXME, the <a> might make an extra target when tabbing @@ -366,9 +426,15 @@ .addClass( 'mw-collabkit-list-button' ) .append( moveButton.$element ); + $editWrapper = $( '<div></div>' ) + .addClass( 'mw-collabkit-list-editbutton' ) + .addClass( 'mw-collabkit-list-button' ) + .append( editButton.$element ); + $item.find( '.mw-collabkit-list-title' ) .append( $delWrapper ) - .append( $moveWrapper ); + .append( $moveWrapper ) + .append( $editWrapper ); } ); $list.sortable( { -- To view, visit https://gerrit.wikimedia.org/r/300739 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ieebd1d517b82b296309b548e0ce32cd62b64fe62 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CollaborationKit Gerrit-Branch: master Gerrit-Owner: Brian Wolff <bawolff...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits