r88461 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88460‎ | r88461 | r88462 >
Date:16:25, 20 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
implemented add new group functionality
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_Group.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/jquery.watchlistcondition.js
@@ -153,7 +153,7 @@
154154
155155 self.doDelete( function( success ) {
156156 if ( success ) {
157 - self.slideUp( 'fast' );
 157+ self.slideUp( 'fast', function() { self.remove(); } );
158158 }
159159 else {
160160 alert( 'Could not delete the watchlist group.' );
Index: trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php
@@ -70,8 +70,45 @@
7171 $groupsHtml[] = $this->getGroupHtml( $group );
7272 }
7373
74 - $wgOut->addHTML( implode( '', $groupsHtml ) );
 74+ $wgOut->addHTML(
 75+ '<div id="swl-groups">' .
 76+ implode( '', $groupsHtml ) .
 77+ '</div>'
 78+ );
7579
 80+ $wgOut->addHTML( Html::rawElement(
 81+ 'fieldset',
 82+ array(
 83+
 84+ ),
 85+ Html::element(
 86+ 'legend',
 87+ array(),
 88+ wfMsg( 'swl-group-add-new-group' )
 89+ ) .
 90+ Html::element(
 91+ 'span',
 92+ array(),
 93+ wfMsg( 'swl-group-name' )
 94+ ) . '&nbsp;' .
 95+ Html::element(
 96+ 'input',
 97+ array(
 98+ 'type' => 'text',
 99+ 'value' => '',
 100+ 'id' => 'swl-add-group-name'
 101+ )
 102+ ) . '&nbsp;' .
 103+ Html::element(
 104+ 'input',
 105+ array(
 106+ 'type' => 'button',
 107+ 'value' => wfMsg( 'swl-group-add-group' ),
 108+ 'id' => 'swl-add-group-button'
 109+ )
 110+ )
 111+ ) );
 112+
76113 $wgOut->addHTML( Html::element(
77114 'input',
78115 array(
Index: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlistconditions.js
@@ -17,9 +17,7 @@
1818 return element.attr( attribute ).split( separator );
1919 }
2020
21 - $( '.swl_group' ).each(function( index, domElement ) {
22 - var element = $( domElement );
23 -
 21+ function initGroupElement( element ) {
2422 element.watchlistcondition(
2523 {
2624 name: element.attr( 'groupname' ),
@@ -30,11 +28,75 @@
3129 concepts: getSplitAttrValue( element, 'concepts', '|' )
3230 },
3331 {}
34 - );
 32+ );
 33+ }
 34+
 35+ $( '.swl_group' ).each(function( index, domElement ) {
 36+ initGroupElement( $( domElement ) );
3537 });
3638
3739 $( '#swl-save-all' ).click( function() {
3840 $( '.swl-save' ).click();
3941 } );
4042
 43+ function addGroupToDB( groupName, callback ) {
 44+ $.getJSON(
 45+ wgScriptPath + '/api.php',
 46+ {
 47+ 'action': 'addswlgroup',
 48+ 'format': 'json',
 49+ 'name': groupName,
 50+ 'properties': ''
 51+ },
 52+ function( data ) {
 53+ callback( data.success, data.group );
 54+ }
 55+ );
 56+ }
 57+
 58+ function addGroupToGUI( groupName, groupId ) {
 59+ var newGroup = $( '<fieldset />' ).attr( {
 60+ 'id': 'swl_group_' + groupId,
 61+ 'groupid': groupId,
 62+ 'class': 'swl_group',
 63+ 'groupname': groupName,
 64+ 'categories': '',
 65+ 'namespaces': '',
 66+ 'properties': '',
 67+ 'concepts': ''
 68+ } )
 69+ .html( $( '<legend />' ).text( groupName ) );
 70+
 71+ $( '#swl-groups' ).append( newGroup );
 72+
 73+ initGroupElement( newGroup );
 74+ }
 75+
 76+ $( '#swl-add-group-button' ).click( function() {
 77+ var input = $( '#swl-add-group-name' );
 78+ var button = this;
 79+
 80+ button.disabled = true;
 81+ input.disabled = true;
 82+
 83+ addGroupToDB( input.val(), function( success, group ) {
 84+ if ( success ) {
 85+ addGroupToGUI( group.name, group.id );
 86+ input.val( '' );
 87+ }
 88+ else {
 89+ alert( 'Could not add the group.' );
 90+ }
 91+
 92+ button.disabled = false;
 93+ input.disabled = false;
 94+ } );
 95+ } );
 96+
 97+ $( '#swl-add-group-name' ).keypress( function( event ) {
 98+ if ( event.which == '13' ) {
 99+ $( '#swl-add-group-button' ).click();
 100+ }
 101+ } );
 102+
41103 } ); })(jQuery);
\ No newline at end of file
Index: trunk/extensions/SemanticWatchlist/includes/SWL_Group.php
@@ -75,7 +75,7 @@
7676 protected function insertIntoDB() {
7777 $dbr = wfGetDB( DB_MASTER );
7878
79 - $dbr->insert(
 79+ $result = $dbr->insert(
8080 'swl_groups',
8181 array(
8282 'group_name' => $this->name,
@@ -85,6 +85,10 @@
8686 'group_concepts' => $this->concepts,
8787 )
8888 );
 89+
 90+ $this->id = $dbr->insertId();
 91+
 92+ return $result;
8993 }
9094
9195 /**
Index: trunk/extensions/SemanticWatchlist/api/ApiAddWatchlistGroup.php
@@ -36,7 +36,23 @@
3737 $params['concepts']
3838 );
3939
40 - $group->writeToDB();
 40+ $this->getResult()->addValue(
 41+ null,
 42+ 'success',
 43+ $group->writeToDB()
 44+ );
 45+
 46+ $this->getResult()->addValue(
 47+ 'group',
 48+ 'id',
 49+ $group->getId()
 50+ );
 51+
 52+ $this->getResult()->addValue(
 53+ 'group',
 54+ 'name',
 55+ $group->getName()
 56+ );
4157 }
4258
4359 public function getAllowedParams() {
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
@@ -39,6 +39,8 @@
4040 'swl-group-concept' => 'concept',
4141 'swl-group-confirmdelete' => 'Are you sure you want to delete the "$1" watchlist group?',
4242 'swl-group-save-all' => 'Save all',
 43+ 'swl-group-add-new-group' => 'Add a new group',
 44+ 'swl-group-add-group' => 'Add group',
4345
4446 // Special:SemanticWatchlist
4547 'swl-watchlist-position' => "Showing '''$1''' of the last changes starting with '''#$2'''.",

Status & tagging log